diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py index 3ddd6657e8b4c..385ce8efab87b 100644 --- a/src/etc/debugger_pretty_printers_common.py +++ b/src/etc/debugger_pretty_printers_common.py @@ -342,8 +342,7 @@ def extract_length_ptr_and_cap_from_std_vec(vec_val): vec_ptr_val = buf.get_child_at_index(0) capacity = buf.get_child_at_index(1).as_integer() - unique_ptr_val = vec_ptr_val.get_child_at_index(0) - data_ptr = unique_ptr_val.get_child_at_index(0) + data_ptr = vec_ptr_val.get_child_at_index(0) assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR return (length, data_ptr, capacity) @@ -360,8 +359,7 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val): vec_ptr_val = buf.get_child_at_index(0) capacity = buf.get_child_at_index(1).as_integer() - unique_ptr_val = vec_ptr_val.get_child_at_index(0) - data_ptr = unique_ptr_val.get_child_at_index(0) + data_ptr = vec_ptr_val.get_child_at_index(0) assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR return (tail, head, data_ptr, capacity) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index 11365a67a14dc..08ae289d60374 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -322,9 +322,7 @@ def children(self): # Yield each key (and optionally value) from a BoxedNode. def children_of_node(boxed_node, height, want_values): - ptr = boxed_node['ptr']['pointer'] - # This is written oddly because we don't want to rely on the field name being `__0`. - node_ptr = ptr[ptr.type.fields()[0]] + node_ptr = boxed_node['ptr']['pointer'] if height > 0: type_name = str(node_ptr.type.target()).replace('LeafNode', 'InternalNode') node_type = gdb.lookup_type(type_name) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 088a00a6c0d4b..5ea765d3585a2 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -216,7 +216,6 @@ pub mod alloc; // note: does not need to be public mod iter_private; -mod nonzero; mod tuple; mod unit; diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs deleted file mode 100644 index 65e1887f05e5d..0000000000000 --- a/src/libcore/nonzero.rs +++ /dev/null @@ -1,23 +0,0 @@ -//! Exposes the NonZero lang item which provides optimization hints. - -use ops::{CoerceUnsized, DispatchFromDyn}; -use marker::Freeze; - -/// A wrapper type for raw pointers and integers that will never be -/// NULL or 0 that might allow certain optimizations. -#[rustc_layout_scalar_valid_range_start(1)] -#[derive(Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); - -// Do not call `T::clone` as theoretically it could turn the field into `0` -// invalidating `NonZero`'s invariant. -impl Clone for NonZero { - fn clone(&self) -> Self { - unsafe { NonZero(self.0) } - } -} - -impl + Freeze, U: Freeze> CoerceUnsized> for NonZero {} - -impl + Freeze, U: Freeze> DispatchFromDyn> for NonZero {} diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 3112db4ad5df0..e776513770ec6 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -6,7 +6,6 @@ use convert::TryFrom; use fmt; use intrinsics; use mem; -use nonzero::NonZero; use ops; use str::FromStr; @@ -48,7 +47,8 @@ assert_eq!(size_of::>(), size_of::<", st #[stable(feature = "nonzero", since = "1.28.0")] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[repr(transparent)] - pub struct $Ty(NonZero<$Int>); + #[rustc_layout_scalar_valid_range_start(1)] + pub struct $Ty($Int); } impl $Ty { @@ -60,7 +60,7 @@ assert_eq!(size_of::>(), size_of::<", st #[stable(feature = "nonzero", since = "1.28.0")] #[inline] pub const unsafe fn new_unchecked(n: $Int) -> Self { - $Ty(NonZero(n)) + $Ty(n) } /// Create a non-zero if the given value is not zero. @@ -68,7 +68,7 @@ assert_eq!(size_of::>(), size_of::<", st #[inline] pub fn new(n: $Int) -> Option { if n != 0 { - Some($Ty(unsafe { NonZero(n) })) + Some(unsafe { $Ty(n) }) } else { None } @@ -78,7 +78,7 @@ assert_eq!(size_of::>(), size_of::<", st #[stable(feature = "nonzero", since = "1.28.0")] #[inline] pub fn get(self) -> $Int { - self.0 .0 + self.0 } } @@ -86,7 +86,7 @@ assert_eq!(size_of::>(), size_of::<", st #[stable(feature = "from_nonzero", since = "1.31.0")] impl From<$Ty> for $Int { fn from(nonzero: $Ty) -> Self { - nonzero.0 .0 + nonzero.0 } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index c220c548dc397..b9420f32a9492 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -70,7 +70,6 @@ use fmt; use hash; use marker::{PhantomData, Unsize}; use mem::{self, MaybeUninit}; -use nonzero::NonZero; use cmp::Ordering::{self, Less, Equal, Greater}; @@ -2718,8 +2717,9 @@ impl PartialOrd for *mut T { (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: NonZero<*const T>, + pointer: *const T, // NOTE: this marker has no consequences for variance, but is necessary // for dropck to understand that we logically own a `T`. // @@ -2776,13 +2776,13 @@ impl Unique { /// /// `ptr` must be non-null. pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { - Unique { pointer: NonZero(ptr as _), _marker: PhantomData } + Unique { pointer: ptr as _, _marker: PhantomData } } /// Creates a new `Unique` if `ptr` is non-null. pub fn new(ptr: *mut T) -> Option { if !ptr.is_null() { - Some(Unique { pointer: unsafe { NonZero(ptr as _) }, _marker: PhantomData }) + Some(unsafe { Unique { pointer: ptr as _, _marker: PhantomData } }) } else { None } @@ -2790,7 +2790,7 @@ impl Unique { /// Acquires the underlying `*mut` pointer. pub fn as_ptr(self) -> *mut T { - self.pointer.0 as *mut T + self.pointer as *mut T } /// Dereferences the content. @@ -2838,21 +2838,21 @@ impl fmt::Pointer for Unique { #[unstable(feature = "ptr_internals", issue = "0")] impl<'a, T: ?Sized> From<&'a mut T> for Unique { fn from(reference: &'a mut T) -> Self { - Unique { pointer: unsafe { NonZero(reference as *mut T) }, _marker: PhantomData } + unsafe { Unique { pointer: reference as *mut T, _marker: PhantomData } } } } #[unstable(feature = "ptr_internals", issue = "0")] impl<'a, T: ?Sized> From<&'a T> for Unique { fn from(reference: &'a T) -> Self { - Unique { pointer: unsafe { NonZero(reference as *const T) }, _marker: PhantomData } + unsafe { Unique { pointer: reference as *const T, _marker: PhantomData } } } } #[unstable(feature = "ptr_internals", issue = "0")] impl<'a, T: ?Sized> From> for Unique { fn from(p: NonNull) -> Self { - Unique { pointer: p.pointer, _marker: PhantomData } + unsafe { Unique { pointer: p.pointer, _marker: PhantomData } } } } @@ -2875,8 +2875,9 @@ impl<'a, T: ?Sized> From> for Unique { /// provide a public API that follows the normal shared XOR mutable rules of Rust. #[stable(feature = "nonnull", since = "1.25.0")] #[repr(transparent)] +#[rustc_layout_scalar_valid_range_start(1)] pub struct NonNull { - pointer: NonZero<*const T>, + pointer: *const T, } /// `NonNull` pointers are not `Send` because the data they reference may be aliased. @@ -2918,7 +2919,7 @@ impl NonNull { #[stable(feature = "nonnull", since = "1.25.0")] #[inline] pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { - NonNull { pointer: NonZero(ptr as _) } + NonNull { pointer: ptr as _ } } /// Creates a new `NonNull` if `ptr` is non-null. @@ -2936,7 +2937,7 @@ impl NonNull { #[stable(feature = "nonnull", since = "1.25.0")] #[inline] pub const fn as_ptr(self) -> *mut T { - self.pointer.0 as *mut T + self.pointer as *mut T } /// Dereferences the content. @@ -3040,7 +3041,7 @@ impl hash::Hash for NonNull { impl From> for NonNull { #[inline] fn from(unique: Unique) -> Self { - NonNull { pointer: unique.pointer } + unsafe { NonNull { pointer: unique.pointer } } } } @@ -3048,7 +3049,7 @@ impl From> for NonNull { impl<'a, T: ?Sized> From<&'a mut T> for NonNull { #[inline] fn from(reference: &'a mut T) -> Self { - NonNull { pointer: unsafe { NonZero(reference as *mut T) } } + unsafe { NonNull { pointer: reference as *mut T } } } } @@ -3056,6 +3057,6 @@ impl<'a, T: ?Sized> From<&'a mut T> for NonNull { impl<'a, T: ?Sized> From<&'a T> for NonNull { #[inline] fn from(reference: &'a T) -> Self { - NonNull { pointer: unsafe { NonZero(reference as *const T) } } + unsafe { NonNull { pointer: reference as *const T } } } } diff --git a/src/test/ui/print_type_sizes/niche-filling.stdout b/src/test/ui/print_type_sizes/niche-filling.stdout index 79f9ef5a231d3..0789c6d7f3486 100644 --- a/src/test/ui/print_type_sizes/niche-filling.stdout +++ b/src/test/ui/print_type_sizes/niche-filling.stdout @@ -36,8 +36,6 @@ print-type-size type: `MyOption`: 4 bytes, alignment: 4 by print-type-size variant `None`: 0 bytes print-type-size variant `Some`: 4 bytes print-type-size field `.0`: 4 bytes -print-type-size type: `core::nonzero::NonZero`: 4 bytes, alignment: 4 bytes -print-type-size field `.0`: 4 bytes print-type-size type: `std::num::NonZeroU32`: 4 bytes, alignment: 4 bytes print-type-size field `.0`: 4 bytes print-type-size type: `Enum4<(), (), (), MyOption>`: 2 bytes, alignment: 1 bytes