Skip to content

Commit

Permalink
Auto merge of #62704 - Mark-Simulacrum:rollup-oi94s2j, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 16, 2019
2 parents 4b65a86 + da0c8fe commit 02785da
Show file tree
Hide file tree
Showing 36 changed files with 307 additions and 156 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
name = "alloc"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -131,7 +131,7 @@ dependencies = [
"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
Expand All @@ -143,7 +143,7 @@ version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]
Expand Down Expand Up @@ -373,7 +373,7 @@ name = "cfg-if"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]

Expand Down Expand Up @@ -502,7 +502,7 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.16"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -834,7 +834,7 @@ name = "dlmalloc"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]
Expand Down Expand Up @@ -1008,7 +1008,7 @@ name = "fortanix-sgx-abi"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]

Expand Down Expand Up @@ -1199,7 +1199,7 @@ name = "hashbrown"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-alloc 1.0.0",
"rustc-std-workspace-core 1.0.0",
]
Expand Down Expand Up @@ -2066,7 +2066,7 @@ dependencies = [
name = "panic_abort"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
Expand All @@ -2077,7 +2077,7 @@ version = "0.0.0"
dependencies = [
"alloc 0.0.0",
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"unwind 0.0.0",
Expand Down Expand Up @@ -2263,7 +2263,7 @@ name = "profiler_builtins"
version = "0.0.0"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -2835,7 +2835,7 @@ name = "rustc-demangle"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]

Expand Down Expand Up @@ -2941,7 +2941,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -3160,7 +3160,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -3223,7 +3223,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -3341,7 +3341,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -3648,7 +3648,7 @@ dependencies = [
"backtrace 0.3.29 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"dlmalloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fortanix-sgx-abi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -4309,7 +4309,7 @@ version = "0.0.0"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
Expand Down Expand Up @@ -4527,7 +4527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc"
"checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
"checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
"checksum compiler_builtins 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "e79ed19793c99771b386d76e08c3419409bb3d418b81a8b8afc73524247461cf"
"checksum compiler_builtins 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "ad9b4731b9e701aefe9e6bd1e9173f30526661508f9aaadaa5caec25ddf95585"
"checksum compiletest_rs 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "f40ecc9332b68270998995c00f8051ee856121764a0d3230e64c9efd059d27b6"
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
"checksum core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2640d6d0bf22e82bed1b73c6aef8d5dd31e5abe6666c57e6d45e2649f4f887"
Expand Down
7 changes: 5 additions & 2 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,12 @@ impl fmt::Display for AllocErr {
}
}

/// The `CannotReallocInPlace` error is used when `grow_in_place` or
/// `shrink_in_place` were unable to reuse the given memory block for
/// The `CannotReallocInPlace` error is used when [`grow_in_place`] or
/// [`shrink_in_place`] were unable to reuse the given memory block for
/// a requested layout.
///
/// [`grow_in_place`]: ./trait.Alloc.html#method.grow_in_place
/// [`shrink_in_place`]: ./trait.Alloc.html#method.shrink_in_place
#[unstable(feature = "allocator_api", issue = "32838")]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct CannotReallocInPlace;
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<T:Copy> Clone for Cell<T> {
}

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

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

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

#[stable(feature = "cell_ord", since = "1.10.0")]
impl<T:PartialOrd + Copy> PartialOrd for Cell<T> {
impl<T: PartialOrd + Copy> PartialOrd for Cell<T> {
#[inline]
fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering> {
self.get().partial_cmp(&other.get())
Expand Down Expand Up @@ -338,7 +338,7 @@ impl<T:PartialOrd + Copy> PartialOrd for Cell<T> {
}

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

#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Default> Default for RefCell<T> {
impl<T: Default> Default for RefCell<T> {
/// Creates a `RefCell<T>`, with the `Default` value for T.
#[inline]
fn default() -> RefCell<T> {
Expand Down
13 changes: 8 additions & 5 deletions src/libcore/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl fmt::Debug for c_void {
#[lang = "va_list"]
pub struct VaListImpl<'f> {
ptr: *mut c_void,
_marker: PhantomData<&'f c_void>,

// Invariant over `'f`, so each `VaListImpl<'f>` object is tied to
// the region of the function it's defined in
_marker: PhantomData<&'f mut &'f c_void>,
}

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

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

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

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

#[cfg(all(target_arch = "asmjs", not(windows)))]
Expand Down
33 changes: 32 additions & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
issue = "0")]
#![allow(missing_docs)]

use crate::mem;

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

/// Checks whether `ptr` is properly aligned with respect to
/// `align_of::<T>()`.
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
!ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
}

/// Checks whether the regions of memory starting at `src` and `dst` of size
/// `count * size_of::<T>()` overlap.
fn overlaps<T>(src: *const T, dst: *const T, count: usize) -> bool {
let src_usize = src as usize;
let dst_usize = dst as usize;
let size = mem::size_of::<T>().checked_mul(count).unwrap();
let diff = if src_usize > dst_usize {
src_usize - dst_usize
} else {
dst_usize - src_usize
};
size > diff
}

/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
/// and destination must *not* overlap.
///
Expand Down Expand Up @@ -1412,7 +1434,11 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
extern "rust-intrinsic" {
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
}
copy_nonoverlapping(src, dst, count);

debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
debug_assert!(!overlaps(src, dst, count), "attempt to copy to overlapping memory");
copy_nonoverlapping(src, dst, count)
}

/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
Expand Down Expand Up @@ -1472,6 +1498,9 @@ pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
extern "rust-intrinsic" {
fn copy<T>(src: *const T, dst: *mut T, count: usize);
}

debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
copy(src, dst, count)
}

Expand Down Expand Up @@ -1553,5 +1582,7 @@ pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
extern "rust-intrinsic" {
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
}

debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
write_bytes(dst, val, count)
}
12 changes: 7 additions & 5 deletions src/libcore/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ use crate::mem::ManuallyDrop;
///
/// ```
/// use std::mem::{self, MaybeUninit};
/// use std::ptr;
///
/// let data = {
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
Expand All @@ -122,10 +121,13 @@ use crate::mem::ManuallyDrop;
/// MaybeUninit::uninit().assume_init()
/// };
///
/// // Dropping a `MaybeUninit` does nothing, so if there is a panic during this loop,
/// // we have a memory leak, but there is no memory safety issue.
/// // Dropping a `MaybeUninit` does nothing. Thus using raw pointer
/// // assignment instead of `ptr::write` does not cause the old
/// // uninitialized value to be dropped. Also if there is a panic during
/// // this loop, we have a memory leak, but there is no memory safety
/// // issue.
/// for elem in &mut data[..] {
/// unsafe { ptr::write(elem.as_mut_ptr(), vec![42]); }
/// *elem = MaybeUninit::new(vec![42]);
/// }
///
/// // Everything is initialized. Transmute the array to the
Expand All @@ -151,7 +153,7 @@ use crate::mem::ManuallyDrop;
/// let mut data_len: usize = 0;
///
/// for elem in &mut data[0..500] {
/// unsafe { ptr::write(elem.as_mut_ptr(), String::from("hello")); }
/// *elem = MaybeUninit::new(String::from("hello"));
/// data_len += 1;
/// }
///
Expand Down
Loading

0 comments on commit 02785da

Please sign in to comment.