@@ -2892,6 +2892,17 @@ impl<T: ?Sized> !Send for NonNull<T> { }
2892
2892
impl < T : ?Sized > !Sync for NonNull < T > { }
2893
2893
2894
2894
impl < T : Sized > NonNull < T > {
2895
+ /// No docs here
2896
+ #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2897
+ #[ inline]
2898
+ #[ cfg( stage0) ]
2899
+ pub fn dangling ( ) -> Self {
2900
+ unsafe {
2901
+ let ptr = mem:: align_of :: < T > ( ) as * mut T ;
2902
+ NonNull :: new_unchecked ( ptr)
2903
+ }
2904
+ }
2905
+
2895
2906
/// Creates a new `NonNull` that is dangling, but well-aligned.
2896
2907
///
2897
2908
/// This is useful for initializing types which lazily allocate, like
@@ -2903,6 +2914,8 @@ impl<T: Sized> NonNull<T> {
2903
2914
/// some other means.
2904
2915
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2905
2916
#[ inline]
2917
+ #[ cfg( not( stage0) ) ]
2918
+ #[ rustc_const_unstable( feature = "const_ptr_nonnull" ) ]
2906
2919
pub const fn dangling ( ) -> Self {
2907
2920
unsafe {
2908
2921
let ptr = mem:: align_of :: < T > ( ) as * mut T ;
@@ -2963,9 +2976,21 @@ impl<T: ?Sized> NonNull<T> {
2963
2976
& mut * self . as_ptr ( )
2964
2977
}
2965
2978
2979
+ /// No docs here
2980
+ #[ stable( feature = "nonnull_cast" , since = "1.27.0" ) ]
2981
+ #[ inline]
2982
+ #[ cfg( stage0) ]
2983
+ pub fn cast < U > ( self ) -> NonNull < U > {
2984
+ unsafe {
2985
+ NonNull :: new_unchecked ( self . as_ptr ( ) as * mut U )
2986
+ }
2987
+ }
2988
+
2966
2989
/// Cast to a pointer of another type
2967
2990
#[ stable( feature = "nonnull_cast" , since = "1.27.0" ) ]
2968
2991
#[ inline]
2992
+ #[ cfg( not( stage0) ) ]
2993
+ #[ rustc_const_unstable( feature = "const_ptr_nonnull" ) ]
2969
2994
pub const fn cast < U > ( self ) -> NonNull < U > {
2970
2995
unsafe {
2971
2996
NonNull :: new_unchecked ( self . as_ptr ( ) as * mut U )
0 commit comments