Skip to content

Commit 02785da

Browse files
committed
Auto merge of #62704 - Mark-Simulacrum:rollup-oi94s2j, r=Mark-Simulacrum
Rollup of 14 pull requests Successful merges: - #62103 (Add debug assertions to write_bytes and copy*) - #62405 (Remove never_type feature requirement for exhaustive patterns) - #62491 (Fix Pin urls in Option documentation) - #62533 (Add missing links for CannotReallocInPlace type) - #62634 (Less unsafe in the array example of MaybeUninit docs) - #62639 (Make VaListImpl<'f> invariant over the 'f lifetime) - #62646 (Tweak wording in feature gate errors) - #62662 (add spaces in front of trait requirements in libcore/cell.rs) - #62668 (Fix #62660) - #62673 (miri validation: better error messages for dangling references) - #62680 (Actually call `visit_block_entry` in `DataflowResultsConsumer`) - #62685 (Add info about undefined behavior to as_ref suggestions) - #62689 (Fix typo in RawWaker::new documentation) - #62698 (SGX target: don't pretend to be GNU/Linux to LLVM) Failed merges: r? @ghost
2 parents 4b65a86 + da0c8fe commit 02785da

36 files changed

+307
-156
lines changed

Cargo.lock

+19-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
name = "alloc"
2626
version = "0.0.0"
2727
dependencies = [
28-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
28+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
2929
"core 0.0.0",
3030
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
3131
"rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -131,7 +131,7 @@ dependencies = [
131131
"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
132132
"backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
133133
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
134-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
134+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
135135
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
136136
"rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
137137
"rustc-std-workspace-core 1.0.0",
@@ -143,7 +143,7 @@ version = "0.1.27"
143143
source = "registry+https://github.com/rust-lang/crates.io-index"
144144
dependencies = [
145145
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
146-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
146+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
147147
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
148148
"rustc-std-workspace-core 1.0.0",
149149
]
@@ -373,7 +373,7 @@ name = "cfg-if"
373373
version = "0.1.8"
374374
source = "registry+https://github.com/rust-lang/crates.io-index"
375375
dependencies = [
376-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
376+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
377377
"rustc-std-workspace-core 1.0.0",
378378
]
379379

@@ -502,7 +502,7 @@ dependencies = [
502502

503503
[[package]]
504504
name = "compiler_builtins"
505-
version = "0.1.16"
505+
version = "0.1.17"
506506
source = "registry+https://github.com/rust-lang/crates.io-index"
507507
dependencies = [
508508
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -834,7 +834,7 @@ name = "dlmalloc"
834834
version = "0.1.3"
835835
source = "registry+https://github.com/rust-lang/crates.io-index"
836836
dependencies = [
837-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
837+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
838838
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
839839
"rustc-std-workspace-core 1.0.0",
840840
]
@@ -1008,7 +1008,7 @@ name = "fortanix-sgx-abi"
10081008
version = "0.3.2"
10091009
source = "registry+https://github.com/rust-lang/crates.io-index"
10101010
dependencies = [
1011-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
1011+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
10121012
"rustc-std-workspace-core 1.0.0",
10131013
]
10141014

@@ -1199,7 +1199,7 @@ name = "hashbrown"
11991199
version = "0.4.0"
12001200
source = "registry+https://github.com/rust-lang/crates.io-index"
12011201
dependencies = [
1202-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
1202+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
12031203
"rustc-std-workspace-alloc 1.0.0",
12041204
"rustc-std-workspace-core 1.0.0",
12051205
]
@@ -2066,7 +2066,7 @@ dependencies = [
20662066
name = "panic_abort"
20672067
version = "0.0.0"
20682068
dependencies = [
2069-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
2069+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
20702070
"core 0.0.0",
20712071
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
20722072
]
@@ -2077,7 +2077,7 @@ version = "0.0.0"
20772077
dependencies = [
20782078
"alloc 0.0.0",
20792079
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
2080-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
2080+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
20812081
"core 0.0.0",
20822082
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
20832083
"unwind 0.0.0",
@@ -2263,7 +2263,7 @@ name = "profiler_builtins"
22632263
version = "0.0.0"
22642264
dependencies = [
22652265
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
2266-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
2266+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
22672267
"core 0.0.0",
22682268
]
22692269

@@ -2835,7 +2835,7 @@ name = "rustc-demangle"
28352835
version = "0.1.15"
28362836
source = "registry+https://github.com/rust-lang/crates.io-index"
28372837
dependencies = [
2838-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
2838+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
28392839
"rustc-std-workspace-core 1.0.0",
28402840
]
28412841

@@ -2941,7 +2941,7 @@ dependencies = [
29412941
"alloc 0.0.0",
29422942
"build_helper 0.1.0",
29432943
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
2944-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
2944+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
29452945
"core 0.0.0",
29462946
]
29472947

@@ -3160,7 +3160,7 @@ dependencies = [
31603160
"alloc 0.0.0",
31613161
"build_helper 0.1.0",
31623162
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
3163-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
3163+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
31643164
"core 0.0.0",
31653165
]
31663166

@@ -3223,7 +3223,7 @@ dependencies = [
32233223
"alloc 0.0.0",
32243224
"build_helper 0.1.0",
32253225
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
3226-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
3226+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
32273227
"core 0.0.0",
32283228
]
32293229

@@ -3341,7 +3341,7 @@ dependencies = [
33413341
"alloc 0.0.0",
33423342
"build_helper 0.1.0",
33433343
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
3344-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
3344+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
33453345
"core 0.0.0",
33463346
]
33473347

@@ -3648,7 +3648,7 @@ dependencies = [
36483648
"backtrace 0.3.29 (registry+https://github.com/rust-lang/crates.io-index)",
36493649
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
36503650
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
3651-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
3651+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
36523652
"core 0.0.0",
36533653
"dlmalloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
36543654
"fortanix-sgx-abi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4309,7 +4309,7 @@ version = "0.0.0"
43094309
dependencies = [
43104310
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
43114311
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
4312-
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
4312+
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
43134313
"core 0.0.0",
43144314
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
43154315
]
@@ -4527,7 +4527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
45274527
"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc"
45284528
"checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
45294529
"checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
4530-
"checksum compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "e79ed19793c99771b386d76e08c3419409bb3d418b81a8b8afc73524247461cf"
4530+
"checksum compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "ad9b4731b9e701aefe9e6bd1e9173f30526661508f9aaadaa5caec25ddf95585"
45314531
"checksum compiletest_rs 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "f40ecc9332b68270998995c00f8051ee856121764a0d3230e64c9efd059d27b6"
45324532
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
45334533
"checksum core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2640d6d0bf22e82bed1b73c6aef8d5dd31e5abe6666c57e6d45e2649f4f887"

src/libcore/alloc.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,12 @@ impl fmt::Display for AllocErr {
359359
}
360360
}
361361

362-
/// The `CannotReallocInPlace` error is used when `grow_in_place` or
363-
/// `shrink_in_place` were unable to reuse the given memory block for
362+
/// The `CannotReallocInPlace` error is used when [`grow_in_place`] or
363+
/// [`shrink_in_place`] were unable to reuse the given memory block for
364364
/// a requested layout.
365+
///
366+
/// [`grow_in_place`]: ./trait.Alloc.html#method.grow_in_place
367+
/// [`shrink_in_place`]: ./trait.Alloc.html#method.shrink_in_place
365368
#[unstable(feature = "allocator_api", issue = "32838")]
366369
#[derive(Clone, PartialEq, Eq, Debug)]
367370
pub struct CannotReallocInPlace;

src/libcore/cell.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<T:Copy> Clone for Cell<T> {
290290
}
291291

292292
#[stable(feature = "rust1", since = "1.0.0")]
293-
impl<T:Default> Default for Cell<T> {
293+
impl<T: Default> Default for Cell<T> {
294294
/// Creates a `Cell<T>`, with the `Default` value for T.
295295
#[inline]
296296
fn default() -> Cell<T> {
@@ -299,18 +299,18 @@ impl<T:Default> Default for Cell<T> {
299299
}
300300

301301
#[stable(feature = "rust1", since = "1.0.0")]
302-
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
302+
impl<T: PartialEq + Copy> PartialEq for Cell<T> {
303303
#[inline]
304304
fn eq(&self, other: &Cell<T>) -> bool {
305305
self.get() == other.get()
306306
}
307307
}
308308

309309
#[stable(feature = "cell_eq", since = "1.2.0")]
310-
impl<T:Eq + Copy> Eq for Cell<T> {}
310+
impl<T: Eq + Copy> Eq for Cell<T> {}
311311

312312
#[stable(feature = "cell_ord", since = "1.10.0")]
313-
impl<T:PartialOrd + Copy> PartialOrd for Cell<T> {
313+
impl<T: PartialOrd + Copy> PartialOrd for Cell<T> {
314314
#[inline]
315315
fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering> {
316316
self.get().partial_cmp(&other.get())
@@ -338,7 +338,7 @@ impl<T:PartialOrd + Copy> PartialOrd for Cell<T> {
338338
}
339339

340340
#[stable(feature = "cell_ord", since = "1.10.0")]
341-
impl<T:Ord + Copy> Ord for Cell<T> {
341+
impl<T: Ord + Copy> Ord for Cell<T> {
342342
#[inline]
343343
fn cmp(&self, other: &Cell<T>) -> Ordering {
344344
self.get().cmp(&other.get())
@@ -1008,7 +1008,7 @@ impl<T: Clone> Clone for RefCell<T> {
10081008
}
10091009

10101010
#[stable(feature = "rust1", since = "1.0.0")]
1011-
impl<T:Default> Default for RefCell<T> {
1011+
impl<T: Default> Default for RefCell<T> {
10121012
/// Creates a `RefCell<T>`, with the `Default` value for T.
10131013
#[inline]
10141014
fn default() -> RefCell<T> {

src/libcore/ffi.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ impl fmt::Debug for c_void {
6060
#[lang = "va_list"]
6161
pub struct VaListImpl<'f> {
6262
ptr: *mut c_void,
63-
_marker: PhantomData<&'f c_void>,
63+
64+
// Invariant over `'f`, so each `VaListImpl<'f>` object is tied to
65+
// the region of the function it's defined in
66+
_marker: PhantomData<&'f mut &'f c_void>,
6467
}
6568

6669
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
@@ -96,7 +99,7 @@ pub struct VaListImpl<'f> {
9699
vr_top: *mut c_void,
97100
gr_offs: i32,
98101
vr_offs: i32,
99-
_marker: PhantomData<&'f c_void>,
102+
_marker: PhantomData<&'f mut &'f c_void>,
100103
}
101104

102105
/// PowerPC ABI implementation of a `va_list`.
@@ -114,7 +117,7 @@ pub struct VaListImpl<'f> {
114117
reserved: u16,
115118
overflow_arg_area: *mut c_void,
116119
reg_save_area: *mut c_void,
117-
_marker: PhantomData<&'f c_void>,
120+
_marker: PhantomData<&'f mut &'f c_void>,
118121
}
119122

120123
/// x86_64 ABI implementation of a `va_list`.
@@ -131,7 +134,7 @@ pub struct VaListImpl<'f> {
131134
fp_offset: i32,
132135
overflow_arg_area: *mut c_void,
133136
reg_save_area: *mut c_void,
134-
_marker: PhantomData<&'f c_void>,
137+
_marker: PhantomData<&'f mut &'f c_void>,
135138
}
136139

137140
/// asm.js ABI implementation of a `va_list`.
@@ -148,7 +151,7 @@ pub struct VaListImpl<'f> {
148151
#[lang = "va_list"]
149152
pub struct VaListImpl<'f> {
150153
inner: [crate::mem::MaybeUninit<i32>; 4],
151-
_marker: PhantomData<&'f c_void>,
154+
_marker: PhantomData<&'f mut &'f c_void>,
152155
}
153156

154157
#[cfg(all(target_arch = "asmjs", not(windows)))]

src/libcore/intrinsics.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
issue = "0")]
3737
#![allow(missing_docs)]
3838

39+
use crate::mem;
40+
3941
#[stable(feature = "drop_in_place", since = "1.8.0")]
4042
#[rustc_deprecated(reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
4143
since = "1.18.0")]
@@ -1323,6 +1325,26 @@ extern "rust-intrinsic" {
13231325
// (`transmute` also falls into this category, but it cannot be wrapped due to the
13241326
// check that `T` and `U` have the same size.)
13251327

1328+
/// Checks whether `ptr` is properly aligned with respect to
1329+
/// `align_of::<T>()`.
1330+
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1331+
!ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1332+
}
1333+
1334+
/// Checks whether the regions of memory starting at `src` and `dst` of size
1335+
/// `count * size_of::<T>()` overlap.
1336+
fn overlaps<T>(src: *const T, dst: *const T, count: usize) -> bool {
1337+
let src_usize = src as usize;
1338+
let dst_usize = dst as usize;
1339+
let size = mem::size_of::<T>().checked_mul(count).unwrap();
1340+
let diff = if src_usize > dst_usize {
1341+
src_usize - dst_usize
1342+
} else {
1343+
dst_usize - src_usize
1344+
};
1345+
size > diff
1346+
}
1347+
13261348
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
13271349
/// and destination must *not* overlap.
13281350
///
@@ -1412,7 +1434,11 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
14121434
extern "rust-intrinsic" {
14131435
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
14141436
}
1415-
copy_nonoverlapping(src, dst, count);
1437+
1438+
debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
1439+
debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
1440+
debug_assert!(!overlaps(src, dst, count), "attempt to copy to overlapping memory");
1441+
copy_nonoverlapping(src, dst, count)
14161442
}
14171443

14181444
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
@@ -1472,6 +1498,9 @@ pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
14721498
extern "rust-intrinsic" {
14731499
fn copy<T>(src: *const T, dst: *mut T, count: usize);
14741500
}
1501+
1502+
debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
1503+
debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
14751504
copy(src, dst, count)
14761505
}
14771506

@@ -1553,5 +1582,7 @@ pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
15531582
extern "rust-intrinsic" {
15541583
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
15551584
}
1585+
1586+
debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
15561587
write_bytes(dst, val, count)
15571588
}

src/libcore/mem/maybe_uninit.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ use crate::mem::ManuallyDrop;
112112
///
113113
/// ```
114114
/// use std::mem::{self, MaybeUninit};
115-
/// use std::ptr;
116115
///
117116
/// let data = {
118117
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
@@ -122,10 +121,13 @@ use crate::mem::ManuallyDrop;
122121
/// MaybeUninit::uninit().assume_init()
123122
/// };
124123
///
125-
/// // Dropping a `MaybeUninit` does nothing, so if there is a panic during this loop,
126-
/// // we have a memory leak, but there is no memory safety issue.
124+
/// // Dropping a `MaybeUninit` does nothing. Thus using raw pointer
125+
/// // assignment instead of `ptr::write` does not cause the old
126+
/// // uninitialized value to be dropped. Also if there is a panic during
127+
/// // this loop, we have a memory leak, but there is no memory safety
128+
/// // issue.
127129
/// for elem in &mut data[..] {
128-
/// unsafe { ptr::write(elem.as_mut_ptr(), vec![42]); }
130+
/// *elem = MaybeUninit::new(vec![42]);
129131
/// }
130132
///
131133
/// // Everything is initialized. Transmute the array to the
@@ -151,7 +153,7 @@ use crate::mem::ManuallyDrop;
151153
/// let mut data_len: usize = 0;
152154
///
153155
/// for elem in &mut data[0..500] {
154-
/// unsafe { ptr::write(elem.as_mut_ptr(), String::from("hello")); }
156+
/// *elem = MaybeUninit::new(String::from("hello"));
155157
/// data_len += 1;
156158
/// }
157159
///

0 commit comments

Comments
 (0)