Skip to content

Commit 7308c22

Browse files
committed
Auto merge of rust-lang#100100 - Dylan-DPC:rollup-llcaaq8, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#99371 (Remove synchronization from Windows `hashmap_random_keys`) - rust-lang#99614 (do not claim that transmute is like memcpy) - rust-lang#99738 (rustdoc: avoid inlining modules with duplicate names) - rust-lang#99800 (Fix futex module imports on wasm+atomics) - rust-lang#100079 (Replace `* -> vec` with `-> vec` in docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e141246 + e92b241 commit 7308c22

File tree

8 files changed

+84
-83
lines changed

8 files changed

+84
-83
lines changed

library/core/src/intrinsics.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -1207,29 +1207,34 @@ extern "rust-intrinsic" {
12071207

12081208
/// Reinterprets the bits of a value of one type as another type.
12091209
///
1210-
/// Both types must have the same size. Neither the original, nor the result,
1211-
/// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1210+
/// Both types must have the same size. Compilation will fail if this is not guaranteed.
12121211
///
12131212
/// `transmute` is semantically equivalent to a bitwise move of one type
12141213
/// into another. It copies the bits from the source value into the
1215-
/// destination value, then forgets the original. It's equivalent to C's
1216-
/// `memcpy` under the hood, just like `transmute_copy`.
1214+
/// destination value, then forgets the original. Note that source and destination
1215+
/// are passed by-value, which means if `T` or `U` contain padding, that padding
1216+
/// is *not* guaranteed to be preserved by `transmute`.
1217+
///
1218+
/// Both the argument and the result must be [valid](../../nomicon/what-unsafe-does.html) at
1219+
/// their given type. Violating this condition leads to [undefined behavior][ub]. The compiler
1220+
/// will generate code *assuming that you, the programmer, ensure that there will never be
1221+
/// undefined behavior*. It is therefore your responsibility to guarantee that every value
1222+
/// passed to `transmute` is valid at both types `T` and `U`. Failing to uphold this condition
1223+
/// may lead to unexpected and unstable compilation results. This makes `transmute` **incredibly
1224+
/// unsafe**. `transmute` should be the absolute last resort.
1225+
///
1226+
/// Transmuting pointers to integers in a `const` context is [undefined behavior][ub].
1227+
/// Any attempt to use the resulting value for integer operations will abort const-evaluation.
1228+
/// (And even outside `const`, such transmutation is touching on many unspecified aspects of the
1229+
/// Rust memory model and should be avoided. See below for alternatives.)
12171230
///
12181231
/// Because `transmute` is a by-value operation, alignment of the *transmuted values
12191232
/// themselves* is not a concern. As with any other function, the compiler already ensures
12201233
/// both `T` and `U` are properly aligned. However, when transmuting values that *point
12211234
/// elsewhere* (such as pointers, references, boxes…), the caller has to ensure proper
12221235
/// alignment of the pointed-to values.
12231236
///
1224-
/// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1225-
/// cause [undefined behavior][ub] with this function. `transmute` should be
1226-
/// the absolute last resort.
1227-
///
1228-
/// Transmuting pointers to integers in a `const` context is [undefined behavior][ub].
1229-
/// Any attempt to use the resulting value for integer operations will abort const-evaluation.
1230-
///
1231-
/// The [nomicon](../../nomicon/transmutes.html) has additional
1232-
/// documentation.
1237+
/// The [nomicon](../../nomicon/transmutes.html) has additional documentation.
12331238
///
12341239
/// [ub]: ../../reference/behavior-considered-undefined.html
12351240
///

library/std/src/sys/wasm/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ cfg_if::cfg_if! {
5252
#[path = "../unix/locks"]
5353
pub mod locks {
5454
#![allow(unsafe_op_in_unsafe_fn)]
55-
mod futex;
55+
mod futex_condvar;
56+
mod futex_mutex;
5657
mod futex_rwlock;
57-
pub(crate) use futex::{Mutex, MovableMutex, Condvar, MovableCondvar};
58+
pub(crate) use futex_condvar::{Condvar, MovableCondvar};
59+
pub(crate) use futex_mutex::{Mutex, MovableMutex};
5860
pub(crate) use futex_rwlock::{RwLock, MovableRwLock};
5961
}
6062
#[path = "atomics/futex.rs"]

library/std/src/sys/windows/rand.rs

+8-60
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,9 @@
11
use crate::io;
22
use crate::mem;
3-
use crate::sync;
3+
use crate::ptr;
44
use crate::sys::c;
55

6-
/// The kinds of HashMap RNG that may be available
7-
#[derive(Clone, Copy, Debug, PartialEq)]
8-
enum HashMapRng {
9-
Preferred,
10-
Fallback,
11-
}
12-
136
pub fn hashmap_random_keys() -> (u64, u64) {
14-
match get_hashmap_rng() {
15-
HashMapRng::Preferred => {
16-
preferred_rng().expect("couldn't generate random bytes with preferred RNG")
17-
}
18-
HashMapRng::Fallback => {
19-
fallback_rng().expect("couldn't generate random bytes with fallback RNG")
20-
}
21-
}
22-
}
23-
24-
/// Returns the HashMap RNG that should be used
25-
///
26-
/// Panics if they are both broken
27-
fn get_hashmap_rng() -> HashMapRng {
28-
// Assume that if the preferred RNG is broken the first time we use it, it likely means
29-
// that: the DLL has failed to load, there is no point to calling it over-and-over again,
30-
// and we should cache the result
31-
static VALUE: sync::OnceLock<HashMapRng> = sync::OnceLock::new();
32-
*VALUE.get_or_init(choose_hashmap_rng)
33-
}
34-
35-
/// Test whether we should use the preferred or fallback RNG
36-
///
37-
/// If the preferred RNG is successful, we choose it. Otherwise, if the fallback RNG is successful,
38-
/// we choose that
39-
///
40-
/// Panics if both the preferred and the fallback RNG are both non-functional
41-
fn choose_hashmap_rng() -> HashMapRng {
42-
let preferred_error = match preferred_rng() {
43-
Ok(_) => return HashMapRng::Preferred,
44-
Err(e) => e,
45-
};
46-
47-
match fallback_rng() {
48-
Ok(_) => return HashMapRng::Fallback,
49-
Err(fallback_error) => panic!(
50-
"preferred RNG broken: `{}`, fallback RNG broken: `{}`",
51-
preferred_error, fallback_error
52-
),
53-
}
54-
}
55-
56-
/// Generate random numbers using the preferred RNG function (BCryptGenRandom)
57-
fn preferred_rng() -> Result<(u64, u64), io::Error> {
58-
use crate::ptr;
59-
607
let mut v = (0, 0);
618
let ret = unsafe {
629
c::BCryptGenRandom(
@@ -66,22 +13,23 @@ fn preferred_rng() -> Result<(u64, u64), io::Error> {
6613
c::BCRYPT_USE_SYSTEM_PREFERRED_RNG,
6714
)
6815
};
69-
70-
if ret == 0 { Ok(v) } else { Err(io::Error::last_os_error()) }
16+
if ret != 0 { fallback_rng() } else { v }
7117
}
7218

7319
/// Generate random numbers using the fallback RNG function (RtlGenRandom)
7420
#[cfg(not(target_vendor = "uwp"))]
75-
fn fallback_rng() -> Result<(u64, u64), io::Error> {
21+
#[inline(never)]
22+
fn fallback_rng() -> (u64, u64) {
7623
let mut v = (0, 0);
7724
let ret =
7825
unsafe { c::RtlGenRandom(&mut v as *mut _ as *mut u8, mem::size_of_val(&v) as c::ULONG) };
7926

80-
if ret != 0 { Ok(v) } else { Err(io::Error::last_os_error()) }
27+
if ret != 0 { v } else { panic!("fallback RNG broken: {}", io::Error::last_os_error()) }
8128
}
8229

8330
/// We can't use RtlGenRandom with UWP, so there is no fallback
8431
#[cfg(target_vendor = "uwp")]
85-
fn fallback_rng() -> Result<(u64, u64), io::Error> {
86-
Err(io::const_io_error!(io::ErrorKind::Unsupported, "RtlGenRandom() not supported on UWP"))
32+
#[inline(never)]
33+
fn fallback_rng() -> (u64, u64) {
34+
panic!("fallback RNG broken: RtlGenRandom() not supported on UWP");
8735
}

src/librustdoc/clean/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,24 @@ pub(crate) trait Clean<'tcx, T> {
5151
impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
5252
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
5353
let mut items: Vec<Item> = vec![];
54-
items.extend(
55-
self.foreigns
56-
.iter()
57-
.map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)),
58-
);
59-
items.extend(self.mods.iter().map(|x| x.clean(cx)));
54+
let mut inserted = FxHashSet::default();
55+
items.extend(self.foreigns.iter().map(|(item, renamed)| {
56+
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
57+
if let Some(name) = item.name {
58+
inserted.insert((item.type_(), name));
59+
}
60+
item
61+
}));
62+
items.extend(self.mods.iter().map(|x| {
63+
inserted.insert((ItemType::Module, x.name));
64+
x.clean(cx)
65+
}));
6066

6167
// Split up imports from all other items.
6268
//
6369
// This covers the case where somebody does an import which should pull in an item,
6470
// but there's already an item with the same namespace and same name. Rust gives
6571
// priority to the not-imported one, so we should, too.
66-
let mut inserted = FxHashSet::default();
6772
items.extend(self.items.iter().flat_map(|(item, renamed)| {
6873
// First, lower everything other than imports.
6974
if matches!(item.kind, hir::ItemKind::Use(..)) {

src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ function loadCss(cssFileName) {
816816
<code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
817817
and <code>const</code>.",
818818
"Search functions by type signature (e.g., <code>vec -&gt; usize</code> or \
819-
<code>* -&gt; vec</code>)",
819+
<code>-&gt; vec</code>)",
820820
"Search multiple things at once by splitting your query with comma (e.g., \
821821
<code>str,u8</code> or <code>String,struct:Vec,test</code>)",
822822
"You can look for items with an exact name by putting double quotes around \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub struct Option;
2+
impl Option {
3+
pub fn unwrap(self) {}
4+
}
5+
6+
/// [`Option::unwrap`]
7+
pub mod task {}
8+
9+
extern "C" {
10+
pub fn main() -> std::ffi::c_int;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build:issue-99734-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name = "foo"]
6+
7+
#[macro_use]
8+
extern crate issue_99734_aux;
9+
10+
pub use issue_99734_aux::*;
11+
12+
// @count foo/index.html '//a[@class="fn"][@title="foo::main fn"]' 1
13+
14+
extern "C" {
15+
pub fn main() -> std::ffi::c_int;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// aux-build:issue-99734-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name = "foo"]
6+
7+
#[macro_use]
8+
extern crate issue_99734_aux;
9+
10+
pub use issue_99734_aux::*;
11+
12+
// @count foo/index.html '//a[@class="mod"][@title="foo::task mod"]' 1
13+
14+
pub mod task {}

0 commit comments

Comments
 (0)