File tree 3 files changed +33
-0
lines changed
3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1739,3 +1739,11 @@ impl<T: ?Sized> PartialOrd for *const T {
1739
1739
* self >= * other
1740
1740
}
1741
1741
}
1742
+
1743
+ #[ stable( feature = "raw_ptr_default" , since = "CURRENT_RUSTC_VERSION" ) ]
1744
+ impl < T : ?Sized + Thin > Default for * const T {
1745
+ /// Returns the default value of [`null()`][crate::ptr::null].
1746
+ fn default ( ) -> Self {
1747
+ crate :: ptr:: null ( )
1748
+ }
1749
+ }
Original file line number Diff line number Diff line change @@ -2156,3 +2156,11 @@ impl<T: ?Sized> PartialOrd for *mut T {
2156
2156
* self >= * other
2157
2157
}
2158
2158
}
2159
+
2160
+ #[ stable( feature = "raw_ptr_default" , since = "CURRENT_RUSTC_VERSION" ) ]
2161
+ impl < T : ?Sized + Thin > Default for * mut T {
2162
+ /// Returns the default value of [`null_mut()`][crate::ptr::null_mut].
2163
+ fn default ( ) -> Self {
2164
+ crate :: ptr:: null_mut ( )
2165
+ }
2166
+ }
Original file line number Diff line number Diff line change @@ -984,3 +984,20 @@ fn test_ptr_metadata_in_const() {
984
984
assert_eq ! ( SLICE_META , 3 ) ;
985
985
assert_eq ! ( DYN_META . size_of( ) , 42 ) ;
986
986
}
987
+
988
+ #[ test]
989
+ fn test_ptr_default ( ) {
990
+ #[ derive( Default ) ]
991
+ struct PtrDefaultTest {
992
+ ptr : * const u64 ,
993
+ }
994
+ let default = PtrDefaultTest :: default ( ) ;
995
+ assert ! ( default . ptr. is_null( ) ) ;
996
+
997
+ #[ derive( Default ) ]
998
+ struct PtrMutDefaultTest {
999
+ ptr : * mut u64 ,
1000
+ }
1001
+ let default = PtrMutDefaultTest :: default ( ) ;
1002
+ assert ! ( default . ptr. is_null( ) ) ;
1003
+ }
You can’t perform that action at this time.
0 commit comments