@@ -70,7 +70,6 @@ use fmt;
70
70
use hash;
71
71
use marker:: { PhantomData , Unsize } ;
72
72
use mem:: { self , MaybeUninit } ;
73
- use nonzero:: NonZero ;
74
73
75
74
use cmp:: Ordering :: { self , Less , Equal , Greater } ;
76
75
@@ -2718,8 +2717,9 @@ impl<T: ?Sized> PartialOrd for *mut T {
2718
2717
(if you also use #[may_dangle]), Send, and/or Sync") ]
2719
2718
#[ doc( hidden) ]
2720
2719
#[ repr( transparent) ]
2720
+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
2721
2721
pub struct Unique < T : ?Sized > {
2722
- pointer : NonZero < * const T > ,
2722
+ pointer : * const T ,
2723
2723
// NOTE: this marker has no consequences for variance, but is necessary
2724
2724
// for dropck to understand that we logically own a `T`.
2725
2725
//
@@ -2776,21 +2776,21 @@ impl<T: ?Sized> Unique<T> {
2776
2776
///
2777
2777
/// `ptr` must be non-null.
2778
2778
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 }
2780
2780
}
2781
2781
2782
2782
/// Creates a new `Unique` if `ptr` is non-null.
2783
2783
pub fn new ( ptr : * mut T ) -> Option < Self > {
2784
2784
if !ptr. is_null ( ) {
2785
- Some ( Unique { pointer : unsafe { NonZero ( ptr as _ ) } , _marker : PhantomData } )
2785
+ Some ( unsafe { Unique { pointer : ptr as _ , _marker : PhantomData } } )
2786
2786
} else {
2787
2787
None
2788
2788
}
2789
2789
}
2790
2790
2791
2791
/// Acquires the underlying `*mut` pointer.
2792
2792
pub fn as_ptr ( self ) -> * mut T {
2793
- self . pointer . 0 as * mut T
2793
+ self . pointer as * mut T
2794
2794
}
2795
2795
2796
2796
/// Dereferences the content.
@@ -2838,21 +2838,21 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
2838
2838
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2839
2839
impl < ' a , T : ?Sized > From < & ' a mut T > for Unique < T > {
2840
2840
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 } }
2842
2842
}
2843
2843
}
2844
2844
2845
2845
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2846
2846
impl < ' a , T : ?Sized > From < & ' a T > for Unique < T > {
2847
2847
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 } }
2849
2849
}
2850
2850
}
2851
2851
2852
2852
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2853
2853
impl < ' a , T : ?Sized > From < NonNull < T > > for Unique < T > {
2854
2854
fn from ( p : NonNull < T > ) -> Self {
2855
- Unique { pointer : p. pointer , _marker : PhantomData }
2855
+ unsafe { Unique { pointer : p. pointer , _marker : PhantomData } }
2856
2856
}
2857
2857
}
2858
2858
@@ -2875,8 +2875,9 @@ impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> {
2875
2875
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
2876
2876
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2877
2877
#[ repr( transparent) ]
2878
+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
2878
2879
pub struct NonNull < T : ?Sized > {
2879
- pointer : NonZero < * const T > ,
2880
+ pointer : * const T ,
2880
2881
}
2881
2882
2882
2883
/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
@@ -2918,7 +2919,7 @@ impl<T: ?Sized> NonNull<T> {
2918
2919
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2919
2920
#[ inline]
2920
2921
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2921
- NonNull { pointer : NonZero ( ptr as _ ) }
2922
+ NonNull { pointer : ptr as _ }
2922
2923
}
2923
2924
2924
2925
/// Creates a new `NonNull` if `ptr` is non-null.
@@ -2936,7 +2937,7 @@ impl<T: ?Sized> NonNull<T> {
2936
2937
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2937
2938
#[ inline]
2938
2939
pub const fn as_ptr ( self ) -> * mut T {
2939
- self . pointer . 0 as * mut T
2940
+ self . pointer as * mut T
2940
2941
}
2941
2942
2942
2943
/// Dereferences the content.
@@ -3040,22 +3041,22 @@ impl<T: ?Sized> hash::Hash for NonNull<T> {
3040
3041
impl < T : ?Sized > From < Unique < T > > for NonNull < T > {
3041
3042
#[ inline]
3042
3043
fn from ( unique : Unique < T > ) -> Self {
3043
- NonNull { pointer : unique. pointer }
3044
+ unsafe { NonNull { pointer : unique. pointer } }
3044
3045
}
3045
3046
}
3046
3047
3047
3048
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
3048
3049
impl < ' a , T : ?Sized > From < & ' a mut T > for NonNull < T > {
3049
3050
#[ inline]
3050
3051
fn from ( reference : & ' a mut T ) -> Self {
3051
- NonNull { pointer : unsafe { NonZero ( reference as * mut T ) } }
3052
+ unsafe { NonNull { pointer : reference as * mut T } }
3052
3053
}
3053
3054
}
3054
3055
3055
3056
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
3056
3057
impl < ' a , T : ?Sized > From < & ' a T > for NonNull < T > {
3057
3058
#[ inline]
3058
3059
fn from ( reference : & ' a T ) -> Self {
3059
- NonNull { pointer : unsafe { NonZero ( reference as * const T ) } }
3060
+ unsafe { NonNull { pointer : reference as * const T } }
3060
3061
}
3061
3062
}
0 commit comments