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 @@ -1020,3 +1020,20 @@ fn test_ptr_swap_nonoverlapping_is_untyped() {
1020
1020
ptr_swap_nonoverlapping_is_untyped_inner ( ) ;
1021
1021
const { ptr_swap_nonoverlapping_is_untyped_inner ( ) } ;
1022
1022
}
1023
+
1024
+ #[ test]
1025
+ fn test_ptr_default ( ) {
1026
+ #[ derive( Default ) ]
1027
+ struct PtrDefaultTest {
1028
+ ptr : * const u64 ,
1029
+ }
1030
+ let default = PtrDefaultTest :: default ( ) ;
1031
+ assert ! ( default . ptr. is_null( ) ) ;
1032
+
1033
+ #[ derive( Default ) ]
1034
+ struct PtrMutDefaultTest {
1035
+ ptr : * mut u64 ,
1036
+ }
1037
+ let default = PtrMutDefaultTest :: default ( ) ;
1038
+ assert ! ( default . ptr. is_null( ) ) ;
1039
+ }
You can’t perform that action at this time.
0 commit comments