diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index d31c73cc1bd8d..ec9ecdba349f6 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -3,7 +3,7 @@ #![stable(feature = "alloc_module", since = "1.28.0")] use core::intrinsics::{self, min_align_of_val, size_of_val}; -use core::ptr::{NonNull, Unique}; +use core::ptr::NonNull; #[stable(feature = "alloc_module", since = "1.28.0")] #[doc(inline)] @@ -258,7 +258,7 @@ unsafe impl AllocRef for Global { } } -/// The allocator for unique pointers. +/// The allocator for Box. // This function must not unwind. If it does, MIR codegen will fail. #[cfg(not(test))] #[lang = "exchange_malloc"] @@ -276,9 +276,9 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { // This signature has to be the same as `Box`, otherwise an ICE will happen. // When an additional parameter to `Box` is added (like `A: AllocRef`), this has to be added here as // well. -// For example if `Box` is changed to `struct Box(Unique, A)`, -// this function has to be changed to `fn box_free(Unique, A)` as well. -pub(crate) unsafe fn box_free(ptr: Unique) { +// For example if `Box` is changed to `struct Box(NonNull, A)`, +// this function has to be changed to `fn box_free(NonNull, A)` as well. +pub(crate) unsafe fn box_free(ptr: NonNull) { let size = size_of_val(ptr.as_ref()); let align = min_align_of_val(ptr.as_ref()); let layout = Layout::from_size_align_unchecked(size, align); diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index db7420954a091..206ea56413bf4 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -136,13 +136,13 @@ use core::fmt; use core::future::Future; use core::hash::{Hash, Hasher}; use core::iter::{FromIterator, FusedIterator, Iterator}; -use core::marker::{Unpin, Unsize}; +use core::marker::{PhantomData, Unpin, Unsize}; use core::mem; use core::ops::{ CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver, }; use core::pin::Pin; -use core::ptr::{self, NonNull, Unique}; +use core::ptr::{self, NonNull}; use core::task::{Context, Poll}; use crate::alloc::{self, AllocInit, AllocRef, Global}; @@ -156,7 +156,26 @@ use crate::vec::Vec; #[lang = "owned_box"] #[fundamental] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Box(Unique); +pub struct Box(BoxPtr); + +// FIXME: remove this struct and give `Box` two fields. +// Currently this causes an ICE with 'assertion failed: sig.c_variadic || extra_args.is_empty()' +struct BoxPtr { + ptr: NonNull, + + // NOTE: this marker has no consequences for variance, but is necessary + // for dropck to understand that we logically own a `T`. + // + // For details, see: + // https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md#phantom-data + _phantom: PhantomData, +} + +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl Send for Box {} + +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl Sync for Box {} impl Box { /// Allocates memory on the heap and then places `x` into it. @@ -382,7 +401,7 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub unsafe fn from_raw(raw: *mut T) -> Self { - Box(Unique::new_unchecked(raw)) + Box(BoxPtr { ptr: NonNull::new_unchecked(raw), _phantom: PhantomData }) } /// Consumes the `Box`, returning a wrapped raw pointer. @@ -462,22 +481,14 @@ impl Box { #[unstable(feature = "box_into_raw_non_null", issue = "47336")] #[inline] pub fn into_raw_non_null(b: Box) -> NonNull { - Box::into_unique(b).into() - } - - #[unstable(feature = "ptr_internals", issue = "none", reason = "use into_raw_non_null instead")] - #[inline] - #[doc(hidden)] - pub fn into_unique(b: Box) -> Unique { - let b = mem::ManuallyDrop::new(b); - let mut unique = b.0; + let mut b = mem::ManuallyDrop::new(b); // Box is kind-of a library type, but recognized as a "unique pointer" by // Stacked Borrows. This function here corresponds to "reborrowing to // a raw pointer", but there is no actual reborrow here -- so // without some care, the pointer we are returning here still carries // the tag of `b`, with `Unique` permission. // We round-trip through a mutable reference to avoid that. - unsafe { Unique::new_unchecked(unique.as_mut() as *mut T) } + unsafe { NonNull::new_unchecked(b.0.ptr.as_mut() as *mut T) } } /// Consumes and leaks the `Box`, returning a mutable reference, @@ -910,7 +921,7 @@ impl fmt::Debug for Box { impl fmt::Pointer for Box { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // It's not possible to extract the inner Uniq directly from the Box, - // instead we cast it to a *const which aliases the Unique + // instead we cast it to a *const which aliases the NonNull let ptr: *const T = &**self; fmt::Pointer::fmt(&ptr, f) } @@ -1025,9 +1036,11 @@ impl + ?Sized> Fn for Box { #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Box {} +impl, U: ?Sized> CoerceUnsized> for BoxPtr {} #[unstable(feature = "dispatch_from_dyn", issue = "none")] impl, U: ?Sized> DispatchFromDyn> for Box {} +impl, U: ?Sized> DispatchFromDyn> for BoxPtr {} #[stable(feature = "boxed_slice_from_iter", since = "1.32.0")] impl FromIterator for Box<[A]> { diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 84d34db2d458a..b8f50185a2f94 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -34,7 +34,7 @@ use core::cmp::Ordering; use core::marker::PhantomData; use core::mem::{self, MaybeUninit}; -use core::ptr::{self, NonNull, Unique}; +use core::ptr::{self, NonNull}; use core::slice; use crate::alloc::{AllocRef, Global, Layout}; @@ -118,20 +118,20 @@ impl InternalNode { /// of nodes it actually contains, and, partially due to this lack of information, /// has no destructor. struct BoxedNode { - ptr: Unique>, + ptr: NonNull>, } impl BoxedNode { fn from_leaf(node: Box>) -> Self { - BoxedNode { ptr: Box::into_unique(node) } + BoxedNode { ptr: Box::into_raw_non_null(node) } } fn from_internal(node: Box>) -> Self { - BoxedNode { ptr: Box::into_unique(node).cast() } + BoxedNode { ptr: Box::into_raw_non_null(node).cast() } } unsafe fn from_ptr(ptr: NonNull>) -> Self { - BoxedNode { ptr: Unique::from(ptr) } + BoxedNode { ptr: NonNull::from(ptr) } } fn as_ptr(&self) -> NonNull> { diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index a2071844d5dac..14bb8e2785da1 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -105,7 +105,6 @@ #![feature(optin_builtin_traits)] #![feature(or_patterns)] #![feature(pattern)] -#![feature(ptr_internals)] #![feature(ptr_offset_from)] #![feature(rustc_attrs)] #![feature(receiver_trait)] diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 0780b33e53ae6..42973262abfa3 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -3,9 +3,10 @@ use core::alloc::MemoryBlock; use core::cmp; +use core::marker::PhantomData; use core::mem::{self, ManuallyDrop, MaybeUninit}; use core::ops::Drop; -use core::ptr::{NonNull, Unique}; +use core::ptr::NonNull; use core::slice; use crate::alloc::{ @@ -25,14 +26,15 @@ mod tests; /// involved. This type is excellent for building your own data structures like Vec and VecDeque. /// In particular: /// -/// * Produces `Unique::empty()` on zero-sized types. -/// * Produces `Unique::empty()` on zero-length allocations. -/// * Avoids freeing `Unique::empty()`. +/// * Produces `NonNull::dangling()` on zero-sized types. +/// * Produces `NonNull::dangling()` on zero-length allocations. +/// * Avoids freeing `NonNull::dangling()`. /// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics). /// * Guards against 32-bit systems allocating more than isize::MAX bytes. /// * Guards against overflowing your length. /// * Calls `handle_alloc_error` for fallible allocations. -/// * Contains a `ptr::Unique` and thus endows the user with all related benefits. +/// * Contains a `ptr::NonNull` and thus endows the user with enum layout optimizations. +/// * Is `Send` and `Sync` when items are. /// * Uses the excess returned from the allocator to use the largest available capacity. /// /// This type does not in anyway inspect the memory that it manages. When dropped it *will* @@ -44,11 +46,24 @@ mod tests; /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] pub struct RawVec { - ptr: Unique, + ptr: NonNull, cap: usize, alloc: A, + + // NOTE: this marker has no consequences for variance, but is necessary + // for dropck to understand that we logically own a `T`. + // + // For details, see: + // https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md#phantom-data + _phantom: PhantomData, } +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl Send for RawVec {} + +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl Sync for RawVec {} + impl RawVec { /// HACK(Centril): This exists because `#[unstable]` `const fn`s needn't conform /// to `min_const_fn` and so they cannot be called in `min_const_fn`s either. @@ -125,7 +140,7 @@ impl RawVec { /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. - Self { ptr: Unique::empty(), cap: 0, alloc } + Self { ptr: NonNull::dangling(), cap: 0, alloc, _phantom: PhantomData } } /// Like `with_capacity`, but parameterized over the choice of @@ -154,6 +169,7 @@ impl RawVec { ptr: memory.ptr.cast().into(), cap: Self::capacity_from_bytes(memory.size), alloc, + _phantom: PhantomData, } } } @@ -168,11 +184,11 @@ impl RawVec { /// If the `ptr` and `capacity` come from a `RawVec` created via `a`, then this is guaranteed. #[inline] pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, a: A) -> Self { - Self { ptr: Unique::new_unchecked(ptr), cap: capacity, alloc: a } + Self { ptr: NonNull::new_unchecked(ptr), cap: capacity, alloc: a, _phantom: PhantomData } } /// Gets a raw pointer to the start of the allocation. Note that this is - /// `Unique::empty()` if `capacity == 0` or `T` is zero-sized. In the former case, you must + /// `NonNull::dangling()` if `capacity == 0` or `T` is zero-sized. In the former case, you must /// be careful. pub fn ptr(&self) -> *mut T { self.ptr.as_ptr() diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index fb9f5faa018a4..51d8a6c386ecd 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -984,8 +984,8 @@ impl Rc { fn from_box(v: Box) -> Rc { unsafe { - let box_unique = Box::into_unique(v); - let bptr = box_unique.as_ptr(); + let box_non_null = Box::into_raw_non_null(v); + let bptr = box_non_null.as_ptr(); let value_size = size_of_val(&*bptr); let ptr = Self::allocate_for_ptr(bptr); @@ -998,7 +998,7 @@ impl Rc { ); // Free the allocation without dropping its contents - box_free(box_unique); + box_free(box_non_null); Self::from_ptr(ptr) } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index cde412bee78d9..8a246c23c8f10 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -862,8 +862,8 @@ impl Arc { fn from_box(v: Box) -> Arc { unsafe { - let box_unique = Box::into_unique(v); - let bptr = box_unique.as_ptr(); + let box_non_null = Box::into_raw_non_null(v); + let bptr = box_non_null.as_ptr(); let value_size = size_of_val(&*bptr); let ptr = Self::allocate_for_ptr(bptr); @@ -876,7 +876,7 @@ impl Arc { ); // Free the allocation without dropping its contents - box_free(box_unique); + box_free(box_non_null); Self::from_ptr(ptr) } diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 84f28488c74b6..2420b47764daf 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -91,10 +91,6 @@ mod non_null; #[stable(feature = "nonnull", since = "1.25.0")] pub use non_null::NonNull; -mod unique; -#[unstable(feature = "ptr_internals", issue = "none")] -pub use unique::Unique; - mod const_ptr; mod mut_ptr; diff --git a/src/libcore/ptr/non_null.rs b/src/libcore/ptr/non_null.rs index 626e58d49306e..fecb0a95d96a9 100644 --- a/src/libcore/ptr/non_null.rs +++ b/src/libcore/ptr/non_null.rs @@ -5,7 +5,6 @@ use crate::hash; use crate::marker::Unsize; use crate::mem; use crate::ops::{CoerceUnsized, DispatchFromDyn}; -use crate::ptr::Unique; // ignore-tidy-undocumented-unsafe @@ -201,14 +200,6 @@ impl hash::Hash for NonNull { } } -#[unstable(feature = "ptr_internals", issue = "none")] -impl From> for NonNull { - #[inline] - fn from(unique: Unique) -> Self { - unsafe { NonNull::new_unchecked(unique.as_ptr()) } - } -} - #[stable(feature = "nonnull", since = "1.25.0")] impl From<&mut T> for NonNull { #[inline] diff --git a/src/libcore/ptr/unique.rs b/src/libcore/ptr/unique.rs deleted file mode 100644 index 87b56d951c6ce..0000000000000 --- a/src/libcore/ptr/unique.rs +++ /dev/null @@ -1,189 +0,0 @@ -use crate::convert::From; -use crate::fmt; -use crate::marker::{PhantomData, Unsize}; -use crate::mem; -use crate::ops::{CoerceUnsized, DispatchFromDyn}; -use crate::ptr::NonNull; - -// ignore-tidy-undocumented-unsafe - -/// A wrapper around a raw non-null `*mut T` that indicates that the possessor -/// of this wrapper owns the referent. Useful for building abstractions like -/// `Box`, `Vec`, `String`, and `HashMap`. -/// -/// Unlike `*mut T`, `Unique` behaves "as if" it were an instance of `T`. -/// It implements `Send`/`Sync` if `T` is `Send`/`Sync`. It also implies -/// the kind of strong aliasing guarantees an instance of `T` can expect: -/// the referent of the pointer should not be modified without a unique path to -/// its owning Unique. -/// -/// If you're uncertain of whether it's correct to use `Unique` for your purposes, -/// consider using `NonNull`, which has weaker semantics. -/// -/// Unlike `*mut T`, the pointer must always be non-null, even if the pointer -/// is never dereferenced. This is so that enums may use this forbidden value -/// as a discriminant -- `Option>` has the same size as `Unique`. -/// However the pointer may still dangle if it isn't dereferenced. -/// -/// Unlike `*mut T`, `Unique` is covariant over `T`. This should always be correct -/// for any type which upholds Unique's aliasing requirements. -#[unstable( - feature = "ptr_internals", - issue = "none", - reason = "use `NonNull` instead and consider `PhantomData` \ - (if you also use `#[may_dangle]`), `Send`, and/or `Sync`" -)] -#[doc(hidden)] -#[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(1)] -pub struct Unique { - pointer: *const T, - // NOTE: this marker has no consequences for variance, but is necessary - // for dropck to understand that we logically own a `T`. - // - // For details, see: - // https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md#phantom-data - _marker: PhantomData, -} - -/// `Unique` pointers are `Send` if `T` is `Send` because the data they -/// reference is unaliased. Note that this aliasing invariant is -/// unenforced by the type system; the abstraction using the -/// `Unique` must enforce it. -#[unstable(feature = "ptr_internals", issue = "none")] -unsafe impl Send for Unique {} - -/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they -/// reference is unaliased. Note that this aliasing invariant is -/// unenforced by the type system; the abstraction using the -/// `Unique` must enforce it. -#[unstable(feature = "ptr_internals", issue = "none")] -unsafe impl Sync for Unique {} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl Unique { - /// Creates a new `Unique` that is dangling, but well-aligned. - /// - /// This is useful for initializing types which lazily allocate, like - /// `Vec::new` does. - /// - /// Note that the pointer value may potentially represent a valid pointer to - /// a `T`, which means this must not be used as a "not yet initialized" - /// sentinel value. Types that lazily allocate must track initialization by - /// some other means. - // FIXME: rename to dangling() to match NonNull? - #[inline] - pub const fn empty() -> Self { - unsafe { Unique::new_unchecked(mem::align_of::() as *mut T) } - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl Unique { - /// Creates a new `Unique`. - /// - /// # Safety - /// - /// `ptr` must be non-null. - #[inline] - pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { - Unique { pointer: ptr as _, _marker: PhantomData } - } - - /// Creates a new `Unique` if `ptr` is non-null. - #[inline] - pub fn new(ptr: *mut T) -> Option { - if !ptr.is_null() { - Some(unsafe { Unique { pointer: ptr as _, _marker: PhantomData } }) - } else { - None - } - } - - /// Acquires the underlying `*mut` pointer. - #[inline] - pub const fn as_ptr(self) -> *mut T { - self.pointer as *mut T - } - - /// Dereferences the content. - /// - /// The resulting lifetime is bound to self so this behaves "as if" - /// it were actually an instance of T that is getting borrowed. If a longer - /// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`. - #[inline] - pub unsafe fn as_ref(&self) -> &T { - &*self.as_ptr() - } - - /// Mutably dereferences the content. - /// - /// The resulting lifetime is bound to self so this behaves "as if" - /// it were actually an instance of T that is getting borrowed. If a longer - /// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`. - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - &mut *self.as_ptr() - } - - /// Casts to a pointer of another type. - #[inline] - pub const fn cast(self) -> Unique { - unsafe { Unique::new_unchecked(self.as_ptr() as *mut U) } - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl Clone for Unique { - #[inline] - fn clone(&self) -> Self { - *self - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl Copy for Unique {} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl CoerceUnsized> for Unique where T: Unsize {} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl DispatchFromDyn> for Unique where T: Unsize {} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl fmt::Debug for Unique { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Pointer::fmt(&self.as_ptr(), f) - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl fmt::Pointer for Unique { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Pointer::fmt(&self.as_ptr(), f) - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl From<&mut T> for Unique { - #[inline] - fn from(reference: &mut T) -> Self { - unsafe { Unique { pointer: reference as *mut T, _marker: PhantomData } } - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl From<&T> for Unique { - #[inline] - fn from(reference: &T) -> Self { - unsafe { Unique { pointer: reference as *const T, _marker: PhantomData } } - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl From> for Unique { - #[inline] - fn from(p: NonNull) -> Self { - unsafe { Unique::new_unchecked(p.as_ptr()) } - } -} diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 6b7672a57f055..3a44d4b3e813a 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -2250,7 +2250,6 @@ where } } - // FIXME(eddyb) This should be for `ptr::Unique`, not `Box`. if let Some(ref mut pointee) = result { if let ty::Adt(def, _) = this.ty.kind { if def.is_box() && offset.bytes() == 0 { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 9d2810cacc2bf..74552e0dfa92d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -290,7 +290,6 @@ #![feature(panic_internals)] #![feature(panic_unwind)] #![feature(prelude_import)] -#![feature(ptr_internals)] #![feature(raw)] #![feature(renamed_spin_loop)] #![feature(rustc_attrs)] diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 6ad5519d34aa9..eb1cf003d7440 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -10,7 +10,7 @@ use crate::future::Future; use crate::ops::{Deref, DerefMut}; use crate::panicking; use crate::pin::Pin; -use crate::ptr::{NonNull, Unique}; +use crate::ptr::NonNull; use crate::rc::Rc; use crate::sync::atomic; use crate::sync::{Arc, Mutex, RwLock}; @@ -193,7 +193,6 @@ pub struct AssertUnwindSafe(#[stable(feature = "catch_unwind", since = "1.9.0 // // * By default everything is unwind safe // * pointers T contains mutability of some form are not unwind safe -// * Unique, an owning pointer, lifts an implementation // * Types like Mutex/RwLock which are explicitly poisoned are unwind safe // * Our custom AssertUnwindSafe wrapper is indeed unwind safe @@ -205,11 +204,15 @@ impl UnwindSafe for &T {} impl UnwindSafe for *const T {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl UnwindSafe for *mut T {} -#[unstable(feature = "ptr_internals", issue = "none")] -impl UnwindSafe for Unique {} #[stable(feature = "nonnull", since = "1.25.0")] impl UnwindSafe for NonNull {} #[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for Box {} +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for Vec {} +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for alloc::collections::VecDeque {} +#[stable(feature = "catch_unwind", since = "1.9.0")] impl UnwindSafe for Mutex {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl UnwindSafe for RwLock {} diff --git a/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff b/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff index 7f2f7cdb17668..9f1075eb3b514 100644 --- a/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff +++ b/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff @@ -19,7 +19,7 @@ _2 = Box(std::vec::Vec); // bb0[2]: scope 0 at $DIR/inline-into-box-place.rs:8:29: 8:43 - (*_2) = const std::vec::Vec::::new() -> [return: bb2, unwind: bb4]; // bb0[3]: scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 + _4 = &mut (*_2); // bb0[3]: scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 -+ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::Unique:: { pointer: {0x4 as *const u32}, _marker: std::marker::PhantomData:: }, cap: 0usize, alloc: std::alloc::Global }; // bb0[4]: scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL ++ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::NonNull:: { pointer: {0x4 as *const u32} }, cap: 0usize, alloc: std::alloc::Global, _phantom: std::marker::PhantomData:: }; // bb0[4]: scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL // ty::Const - // + ty: fn() -> std::vec::Vec {std::vec::Vec::::new} - // + val: Value(Scalar()) @@ -70,13 +70,13 @@ } - bb4 (cleanup): { -- _3 = const alloc::alloc::box_free::>(move (_2.0: std::ptr::Unique>)) -> bb1; // bb4[0]: scope 0 at $DIR/inline-into-box-place.rs:8:42: 8:43 +- _3 = const alloc::alloc::box_free::>(move (_2.0: std::boxed::BoxPtr>)) -> bb1; // bb4[0]: scope 0 at $DIR/inline-into-box-place.rs:8:42: 8:43 - // ty::Const -- // + ty: unsafe fn(std::ptr::Unique>) {alloc::alloc::box_free::>} +- // + ty: unsafe fn(std::ptr::NonNull>) {alloc::alloc::box_free::>} - // + val: Value(Scalar()) - // mir::Constant - // + span: $DIR/inline-into-box-place.rs:8:42: 8:43 -- // + literal: Const { ty: unsafe fn(std::ptr::Unique>) {alloc::alloc::box_free::>}, val: Value(Scalar()) } +- // + literal: Const { ty: unsafe fn(std::ptr::NonNull>) {alloc::alloc::box_free::>}, val: Value(Scalar()) } + bb2: { + StorageDead(_1); // bb2[0]: scope 0 at $DIR/inline-into-box-place.rs:9:1: 9:2 + return; // bb2[1]: scope 0 at $DIR/inline-into-box-place.rs:9:2: 9:2 diff --git a/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff b/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff index b968b33ac5274..d5ea86fc06db0 100644 --- a/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff +++ b/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff @@ -19,7 +19,7 @@ _2 = Box(std::vec::Vec); // bb0[2]: scope 0 at $DIR/inline-into-box-place.rs:8:29: 8:43 - (*_2) = const std::vec::Vec::::new() -> [return: bb2, unwind: bb4]; // bb0[3]: scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 + _4 = &mut (*_2); // bb0[3]: scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 -+ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::Unique:: { pointer: {0x4 as *const u32}, _marker: std::marker::PhantomData:: }, cap: 0usize, alloc: std::alloc::Global }; // bb0[4]: scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL ++ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::NonNull:: { pointer: {0x4 as *const u32} }, cap: 0usize, alloc: std::alloc::Global, _phantom: std::marker::PhantomData:: }; // bb0[4]: scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL // ty::Const - // + ty: fn() -> std::vec::Vec {std::vec::Vec::::new} - // + val: Value(Scalar()) @@ -70,13 +70,13 @@ } - bb4 (cleanup): { -- _3 = const alloc::alloc::box_free::>(move (_2.0: std::ptr::Unique>)) -> bb1; // bb4[0]: scope 0 at $DIR/inline-into-box-place.rs:8:42: 8:43 +- _3 = const alloc::alloc::box_free::>(move (_2.0: std::boxed::BoxPtr>)) -> bb1; // bb4[0]: scope 0 at $DIR/inline-into-box-place.rs:8:42: 8:43 - // ty::Const -- // + ty: unsafe fn(std::ptr::Unique>) {alloc::alloc::box_free::>} +- // + ty: unsafe fn(std::ptr::NonNull>) {alloc::alloc::box_free::>} - // + val: Value(Scalar()) - // mir::Constant - // + span: $DIR/inline-into-box-place.rs:8:42: 8:43 -- // + literal: Const { ty: unsafe fn(std::ptr::Unique>) {alloc::alloc::box_free::>}, val: Value(Scalar()) } +- // + literal: Const { ty: unsafe fn(std::ptr::NonNull>) {alloc::alloc::box_free::>}, val: Value(Scalar()) } + bb2: { + StorageDead(_1); // bb2[0]: scope 0 at $DIR/inline-into-box-place.rs:9:1: 9:2 + return; // bb2[1]: scope 0 at $DIR/inline-into-box-place.rs:9:2: 9:2 diff --git a/src/test/ui/consts/const-ptr-nonnull-rpass.rs b/src/test/ui/consts/const-ptr-nonnull-rpass.rs index 67d52ad08246a..5c892bcffaf70 100644 --- a/src/test/ui/consts/const-ptr-nonnull-rpass.rs +++ b/src/test/ui/consts/const-ptr-nonnull-rpass.rs @@ -1,6 +1,6 @@ // run-pass -#![feature(ptr_internals, test)] +#![feature(test)] extern crate test; use test::black_box as b; // prevent promotion of the argument and const-propagation of the result diff --git a/src/test/ui/consts/const-ptr-unique-rpass.rs b/src/test/ui/consts/const-ptr-unique-rpass.rs deleted file mode 100644 index e8735e1a32c2c..0000000000000 --- a/src/test/ui/consts/const-ptr-unique-rpass.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-pass - -#![feature(ptr_internals, test)] - -extern crate test; -use test::black_box as b; // prevent promotion of the argument and const-propagation of the result - -use std::ptr::Unique; - - -const PTR: *mut u32 = Unique::empty().as_ptr(); - -pub fn main() { - // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them. - assert_eq!(PTR, b:: _>(Unique::::empty)().as_ptr()); -} diff --git a/src/test/ui/consts/const-ptr-unique.rs b/src/test/ui/consts/const-ptr-unique.rs deleted file mode 100644 index 252c5d1a9cda5..0000000000000 --- a/src/test/ui/consts/const-ptr-unique.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(ptr_internals)] - -use std::ptr::Unique; - -fn main() { - let mut i: u32 = 10; - let unique = Unique::new(&mut i).unwrap(); - let x: &'static *mut u32 = &(unique.as_ptr()); - //~^ ERROR temporary value dropped while borrowed -} diff --git a/src/test/ui/consts/const-ptr-unique.stderr b/src/test/ui/consts/const-ptr-unique.stderr deleted file mode 100644 index 3644cf4cec7d3..0000000000000 --- a/src/test/ui/consts/const-ptr-unique.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0716]: temporary value dropped while borrowed - --> $DIR/const-ptr-unique.rs:8:33 - | -LL | let x: &'static *mut u32 = &(unique.as_ptr()); - | ----------------- ^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use - | | - | type annotation requires that borrow lasts for `'static` -LL | -LL | } - | - temporary value is freed at the end of this statement - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0716`. diff --git a/src/test/ui/feature-gate/issue-49983-see-issue-0.rs b/src/test/ui/feature-gate/issue-49983-see-issue-0.rs index eeb80d014b2d5..707d0fbaf12ff 100644 --- a/src/test/ui/feature-gate/issue-49983-see-issue-0.rs +++ b/src/test/ui/feature-gate/issue-49983-see-issue-0.rs @@ -1,6 +1,6 @@ extern crate core; // error should not say "(see issue #0)" -#[allow(unused_imports)] use core::ptr::Unique; //~ ERROR use of unstable library feature +#[allow(unused_imports)] use core::ops::DispatchFromDyn; //~ ERROR use of unstable library feature fn main() {} diff --git a/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr b/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr index 314238a34df86..a1842a8202ca7 100644 --- a/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr +++ b/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr @@ -1,10 +1,10 @@ -error[E0658]: use of unstable library feature 'ptr_internals': use `NonNull` instead and consider `PhantomData` (if you also use `#[may_dangle]`), `Send`, and/or `Sync` +error[E0658]: use of unstable library feature 'dispatch_from_dyn' --> $DIR/issue-49983-see-issue-0.rs:4:30 | -LL | #[allow(unused_imports)] use core::ptr::Unique; - | ^^^^^^^^^^^^^^^^^ +LL | #[allow(unused_imports)] use core::ops::DispatchFromDyn; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: add `#![feature(ptr_internals)]` to the crate attributes to enable + = help: add `#![feature(dispatch_from_dyn)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/issues/issue-7364.stderr b/src/test/ui/issues/issue-7364.stderr index 1f1079555a91f..2e3a029cb0324 100644 --- a/src/test/ui/issues/issue-7364.stderr +++ b/src/test/ui/issues/issue-7364.stderr @@ -17,8 +17,7 @@ LL | static boxed: Box> = box RefCell::new(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::cell::RefCell` cannot be shared between threads safely | = help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell` - = note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique>` - = note: required because it appears within the type `std::boxed::Box>` + = note: required because of the requirements on the impl of `std::marker::Sync` for `std::boxed::Box>` = note: shared static variables must have a type that implements `Sync` error: aborting due to 3 previous errors diff --git a/src/test/ui/kindck/kindck-send-object.stderr b/src/test/ui/kindck/kindck-send-object.stderr index a59a375c6c837..82e72b3c4d05a 100644 --- a/src/test/ui/kindck/kindck-send-object.stderr +++ b/src/test/ui/kindck/kindck-send-object.stderr @@ -20,8 +20,7 @@ LL | assert_send::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Dummy` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `dyn Dummy` - = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique` - = note: required because it appears within the type `std::boxed::Box` + = note: required because of the requirements on the impl of `std::marker::Send` for `std::boxed::Box` error: aborting due to 2 previous errors diff --git a/src/test/ui/kindck/kindck-send-object1.stderr b/src/test/ui/kindck/kindck-send-object1.stderr index b6d82e3195e04..f527c37476d64 100644 --- a/src/test/ui/kindck/kindck-send-object1.stderr +++ b/src/test/ui/kindck/kindck-send-object1.stderr @@ -28,8 +28,7 @@ LL | assert_send::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Dummy + 'a)` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `(dyn Dummy + 'a)` - = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<(dyn Dummy + 'a)>` - = note: required because it appears within the type `std::boxed::Box<(dyn Dummy + 'a)>` + = note: required because of the requirements on the impl of `std::marker::Send` for `std::boxed::Box<(dyn Dummy + 'a)>` error: aborting due to 3 previous errors diff --git a/src/test/ui/kindck/kindck-send-object2.stderr b/src/test/ui/kindck/kindck-send-object2.stderr index e6daf987c8c48..9ce169d933757 100644 --- a/src/test/ui/kindck/kindck-send-object2.stderr +++ b/src/test/ui/kindck/kindck-send-object2.stderr @@ -20,8 +20,7 @@ LL | assert_send::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Dummy` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `dyn Dummy` - = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique` - = note: required because it appears within the type `std::boxed::Box` + = note: required because of the requirements on the impl of `std::marker::Send` for `std::boxed::Box` error: aborting due to 2 previous errors diff --git a/src/test/ui/kindck/kindck-send-owned.stderr b/src/test/ui/kindck/kindck-send-owned.stderr index 2c6c2c6267dc0..e2a3261775357 100644 --- a/src/test/ui/kindck/kindck-send-owned.stderr +++ b/src/test/ui/kindck/kindck-send-owned.stderr @@ -8,8 +8,7 @@ LL | assert_send::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut u8` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `*mut u8` - = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<*mut u8>` - = note: required because it appears within the type `std::boxed::Box<*mut u8>` + = note: required because of the requirements on the impl of `std::marker::Send` for `std::boxed::Box<*mut u8>` error: aborting due to previous error diff --git a/src/test/ui/lint/lint-ctypes-enum.rs b/src/test/ui/lint/lint-ctypes-enum.rs index ccda005575c6e..7f3fc271c557e 100644 --- a/src/test/ui/lint/lint-ctypes-enum.rs +++ b/src/test/ui/lint/lint-ctypes-enum.rs @@ -1,5 +1,4 @@ #![feature(transparent_unions)] -#![feature(ptr_internals)] #![deny(improper_ctypes)] #![allow(dead_code)] @@ -45,8 +44,6 @@ extern { fn option_ref(x: Option<&'static u8>); fn option_fn(x: Option); fn nonnull(x: Option>); - fn unique(x: Option>); - //~^ ERROR `extern` block uses type `std::option::Option>` fn nonzero_u8(x: Option); fn nonzero_u16(x: Option); fn nonzero_u32(x: Option); diff --git a/src/test/ui/lint/lint-ctypes-enum.stderr b/src/test/ui/lint/lint-ctypes-enum.stderr index 297ac2237a53f..defc2b7ccf3b1 100644 --- a/src/test/ui/lint/lint-ctypes-enum.stderr +++ b/src/test/ui/lint/lint-ctypes-enum.stderr @@ -1,24 +1,24 @@ error: `extern` block uses type `U`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:39:13 + --> $DIR/lint-ctypes-enum.rs:38:13 | LL | fn uf(x: U); | ^ not FFI-safe | note: the lint level is defined here - --> $DIR/lint-ctypes-enum.rs:3:9 + --> $DIR/lint-ctypes-enum.rs:2:9 | LL | #![deny(improper_ctypes)] | ^^^^^^^^^^^^^^^ = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint note: the type is defined here - --> $DIR/lint-ctypes-enum.rs:9:1 + --> $DIR/lint-ctypes-enum.rs:8:1 | LL | enum U { A } | ^^^^^^^^^^^^ error: `extern` block uses type `B`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:40:13 + --> $DIR/lint-ctypes-enum.rs:39:13 | LL | fn bf(x: B); | ^ not FFI-safe @@ -26,13 +26,13 @@ LL | fn bf(x: B); = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint note: the type is defined here - --> $DIR/lint-ctypes-enum.rs:10:1 + --> $DIR/lint-ctypes-enum.rs:9:1 | LL | enum B { C, D } | ^^^^^^^^^^^^^^^ error: `extern` block uses type `T`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:41:13 + --> $DIR/lint-ctypes-enum.rs:40:13 | LL | fn tf(x: T); | ^ not FFI-safe @@ -40,22 +40,13 @@ LL | fn tf(x: T); = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint note: the type is defined here - --> $DIR/lint-ctypes-enum.rs:11:1 + --> $DIR/lint-ctypes-enum.rs:10:1 | LL | enum T { E, F, G } | ^^^^^^^^^^^^^^^^^^ -error: `extern` block uses type `std::option::Option>`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:48:17 - | -LL | fn unique(x: Option>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe - | - = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum - = note: enum has no representation hint - error: `extern` block uses type `u128`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:54:23 + --> $DIR/lint-ctypes-enum.rs:51:23 | LL | fn nonzero_u128(x: Option); | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -63,7 +54,7 @@ LL | fn nonzero_u128(x: Option); = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `i128`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:61:23 + --> $DIR/lint-ctypes-enum.rs:58:23 | LL | fn nonzero_i128(x: Option); | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -71,7 +62,7 @@ LL | fn nonzero_i128(x: Option); = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `std::option::Option>`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:66:28 + --> $DIR/lint-ctypes-enum.rs:63:28 | LL | fn transparent_union(x: Option>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -80,7 +71,7 @@ LL | fn transparent_union(x: Option>); = note: enum has no representation hint error: `extern` block uses type `std::option::Option>`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:68:20 + --> $DIR/lint-ctypes-enum.rs:65:20 | LL | fn repr_rust(x: Option>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -89,7 +80,7 @@ LL | fn repr_rust(x: Option>); = note: enum has no representation hint error: `extern` block uses type `std::result::Result<(), std::num::NonZeroI32>`, which is not FFI-safe - --> $DIR/lint-ctypes-enum.rs:69:20 + --> $DIR/lint-ctypes-enum.rs:66:20 | LL | fn no_result(x: Result<(), num::NonZeroI32>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -97,5 +88,5 @@ LL | fn no_result(x: Result<(), num::NonZeroI32>); = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors diff --git a/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr b/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr index 446b8dbf1148f..37e95ea303cb9 100644 --- a/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr +++ b/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr @@ -56,8 +56,7 @@ LL | is_send(Box::new(TestType)); | help: consider borrowing here: `&Box::new(TestType)` | = note: the trait bound `dummy2::TestType: std::marker::Send` is not satisfied - = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique` - = note: required because it appears within the type `std::boxed::Box` + = note: required because of the requirements on the impl of `std::marker::Send` for `std::boxed::Box` error[E0277]: `dummy3::TestType` cannot be sent between threads safely --> $DIR/negated-auto-traits-error.rs:56:13 @@ -70,8 +69,7 @@ LL | is_send(Box::new(Outer2(TestType))); | = help: within `Outer2`, the trait `std::marker::Send` is not implemented for `dummy3::TestType` = note: required because it appears within the type `Outer2` - = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique>` - = note: required because it appears within the type `std::boxed::Box>` + = note: required because of the requirements on the impl of `std::marker::Send` for `std::boxed::Box>` error[E0277]: `main::TestType` cannot be sent between threads safely --> $DIR/negated-auto-traits-error.rs:66:13 diff --git a/src/test/ui/unique-object-noncopyable.stderr b/src/test/ui/unique-object-noncopyable.stderr index 161e25bb8c5f1..4ee4ead4f5de0 100644 --- a/src/test/ui/unique-object-noncopyable.stderr +++ b/src/test/ui/unique-object-noncopyable.stderr @@ -12,7 +12,7 @@ LL | let _z = y.clone(); | ::: $SRC_DIR/liballoc/boxed.rs:LL:COL | -LL | pub struct Box(Unique); +LL | pub struct Box(BoxPtr); | ------------------------------------- doesn't satisfy `std::boxed::Box: std::clone::Clone` | ::: $SRC_DIR/libcore/clone.rs:LL:COL diff --git a/src/test/ui/unique-pinned-nocopy.stderr b/src/test/ui/unique-pinned-nocopy.stderr index 38c110c04c479..08606037b889e 100644 --- a/src/test/ui/unique-pinned-nocopy.stderr +++ b/src/test/ui/unique-pinned-nocopy.stderr @@ -9,7 +9,7 @@ LL | let _j = i.clone(); | ::: $SRC_DIR/liballoc/boxed.rs:LL:COL | -LL | pub struct Box(Unique); +LL | pub struct Box(BoxPtr); | ------------------------------------- doesn't satisfy `std::boxed::Box: std::clone::Clone` | ::: $SRC_DIR/libcore/clone.rs:LL:COL