@@ -70,7 +70,6 @@ use fmt;
7070use hash;
7171use marker:: { PhantomData , Unsize } ;
7272use mem:: { self , MaybeUninit } ;
73- use nonzero:: NonZero ;
7473
7574use cmp:: Ordering :: { self , Less , Equal , Greater } ;
7675
@@ -2718,8 +2717,9 @@ impl<T: ?Sized> PartialOrd for *mut T {
27182717 (if you also use #[may_dangle]), Send, and/or Sync") ]
27192718#[ doc( hidden) ]
27202719#[ repr( transparent) ]
2720+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
27212721pub struct Unique < T : ?Sized > {
2722- pointer : NonZero < * const T > ,
2722+ pointer : * const T ,
27232723 // NOTE: this marker has no consequences for variance, but is necessary
27242724 // for dropck to understand that we logically own a `T`.
27252725 //
@@ -2776,21 +2776,21 @@ impl<T: ?Sized> Unique<T> {
27762776 ///
27772777 /// `ptr` must be non-null.
27782778 pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2779- Unique { pointer : NonZero ( ptr as _ ) , _marker : PhantomData }
2779+ Unique { pointer : ptr as _ , _marker : PhantomData }
27802780 }
27812781
27822782 /// Creates a new `Unique` if `ptr` is non-null.
27832783 pub fn new ( ptr : * mut T ) -> Option < Self > {
27842784 if !ptr. is_null ( ) {
2785- Some ( Unique { pointer : unsafe { NonZero ( ptr as _ ) } , _marker : PhantomData } )
2785+ Some ( unsafe { Unique { pointer : ptr as _ , _marker : PhantomData } } )
27862786 } else {
27872787 None
27882788 }
27892789 }
27902790
27912791 /// Acquires the underlying `*mut` pointer.
27922792 pub fn as_ptr ( self ) -> * mut T {
2793- self . pointer . 0 as * mut T
2793+ self . pointer as * mut T
27942794 }
27952795
27962796 /// Dereferences the content.
@@ -2838,21 +2838,21 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
28382838#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
28392839impl < ' a , T : ?Sized > From < & ' a mut T > for Unique < T > {
28402840 fn from ( reference : & ' a mut T ) -> Self {
2841- Unique { pointer : unsafe { NonZero ( reference as * mut T ) } , _marker : PhantomData }
2841+ unsafe { Unique { pointer : reference as * mut T , _marker : PhantomData } }
28422842 }
28432843}
28442844
28452845#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
28462846impl < ' a , T : ?Sized > From < & ' a T > for Unique < T > {
28472847 fn from ( reference : & ' a T ) -> Self {
2848- Unique { pointer : unsafe { NonZero ( reference as * const T ) } , _marker : PhantomData }
2848+ unsafe { Unique { pointer : reference as * const T , _marker : PhantomData } }
28492849 }
28502850}
28512851
28522852#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
28532853impl < ' a , T : ?Sized > From < NonNull < T > > for Unique < T > {
28542854 fn from ( p : NonNull < T > ) -> Self {
2855- Unique { pointer : p. pointer , _marker : PhantomData }
2855+ unsafe { Unique { pointer : p. pointer , _marker : PhantomData } }
28562856 }
28572857}
28582858
@@ -2875,8 +2875,9 @@ impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> {
28752875/// provide a public API that follows the normal shared XOR mutable rules of Rust.
28762876#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
28772877#[ repr( transparent) ]
2878+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
28782879pub struct NonNull < T : ?Sized > {
2879- pointer : NonZero < * const T > ,
2880+ pointer : * const T ,
28802881}
28812882
28822883/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
@@ -2918,7 +2919,7 @@ impl<T: ?Sized> NonNull<T> {
29182919 #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
29192920 #[ inline]
29202921 pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2921- NonNull { pointer : NonZero ( ptr as _ ) }
2922+ NonNull { pointer : ptr as _ }
29222923 }
29232924
29242925 /// Creates a new `NonNull` if `ptr` is non-null.
@@ -2936,7 +2937,7 @@ impl<T: ?Sized> NonNull<T> {
29362937 #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
29372938 #[ inline]
29382939 pub const fn as_ptr ( self ) -> * mut T {
2939- self . pointer . 0 as * mut T
2940+ self . pointer as * mut T
29402941 }
29412942
29422943 /// Dereferences the content.
@@ -3040,22 +3041,22 @@ impl<T: ?Sized> hash::Hash for NonNull<T> {
30403041impl < T : ?Sized > From < Unique < T > > for NonNull < T > {
30413042 #[ inline]
30423043 fn from ( unique : Unique < T > ) -> Self {
3043- NonNull { pointer : unique. pointer }
3044+ unsafe { NonNull { pointer : unique. pointer } }
30443045 }
30453046}
30463047
30473048#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
30483049impl < ' a , T : ?Sized > From < & ' a mut T > for NonNull < T > {
30493050 #[ inline]
30503051 fn from ( reference : & ' a mut T ) -> Self {
3051- NonNull { pointer : unsafe { NonZero ( reference as * mut T ) } }
3052+ unsafe { NonNull { pointer : reference as * mut T } }
30523053 }
30533054}
30543055
30553056#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
30563057impl < ' a , T : ?Sized > From < & ' a T > for NonNull < T > {
30573058 #[ inline]
30583059 fn from ( reference : & ' a T ) -> Self {
3059- NonNull { pointer : unsafe { NonZero ( reference as * const T ) } }
3060+ unsafe { NonNull { pointer : reference as * const T } }
30603061 }
30613062}
0 commit comments