File tree Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -34,12 +34,24 @@ impl<T: ?Sized> *const T {
34
34
#[ rustc_const_unstable( feature = "const_ptr_is_null" , issue = "74939" ) ]
35
35
#[ inline]
36
36
pub const fn is_null ( self ) -> bool {
37
+ #[ inline]
38
+ const fn ct ( ptr : * const u8 ) -> bool {
39
+ match ( ptr) . guaranteed_eq ( null ( ) ) {
40
+ None => false ,
41
+ Some ( res) => res,
42
+ }
43
+ }
44
+
45
+ #[ inline]
46
+ fn rt ( ptr : * const u8 ) -> bool {
47
+ ptr. addr ( ) == 0
48
+ }
49
+
37
50
// Compare via a cast to a thin pointer, so fat pointers are only
38
51
// considering their "data" part for null-ness.
39
- match ( self as * const u8 ) . guaranteed_eq ( null ( ) ) {
40
- None => false ,
41
- Some ( res) => res,
42
- }
52
+
53
+ // SAFETY: NOYET
54
+ unsafe { intrinsics:: const_eval_select ( ( self as * const u8 , ) , ct, rt) }
43
55
}
44
56
45
57
/// Casts to a pointer of another type.
Original file line number Diff line number Diff line change @@ -33,12 +33,24 @@ impl<T: ?Sized> *mut T {
33
33
#[ rustc_const_unstable( feature = "const_ptr_is_null" , issue = "74939" ) ]
34
34
#[ inline]
35
35
pub const fn is_null ( self ) -> bool {
36
+ #[ inline]
37
+ const fn ct ( ptr : * mut u8 ) -> bool {
38
+ match ( ptr) . guaranteed_eq ( null_mut ( ) ) {
39
+ None => false ,
40
+ Some ( res) => res,
41
+ }
42
+ }
43
+
44
+ #[ inline]
45
+ fn rt ( ptr : * mut u8 ) -> bool {
46
+ ptr. addr ( ) == 0
47
+ }
48
+
36
49
// Compare via a cast to a thin pointer, so fat pointers are only
37
50
// considering their "data" part for null-ness.
38
- match ( self as * mut u8 ) . guaranteed_eq ( null_mut ( ) ) {
39
- None => false ,
40
- Some ( res) => res,
41
- }
51
+
52
+ // SAFETY: NOYET
53
+ unsafe { intrinsics:: const_eval_select ( ( self as * mut u8 , ) , ct, rt) }
42
54
}
43
55
44
56
/// Casts to a pointer of another type.
You can’t perform that action at this time.
0 commit comments