File tree Expand file tree Collapse file tree 2 files changed +7
-20
lines changed Expand file tree Collapse file tree 2 files changed +7
-20
lines changed Original file line number Diff line number Diff line change @@ -40,15 +40,17 @@ impl<T: ?Sized> *const T {
4040
4141 #[ inline]
4242 const fn const_impl ( ptr : * const u8 ) -> bool {
43- // Compare via a cast to a thin pointer, so fat pointers are only
44- // considering their "data" part for null-ness.
4543 match ( ptr) . guaranteed_eq ( null_mut ( ) ) {
46- None => false ,
4744 Some ( res) => res,
45+ // To remain maximally convervative, we stop execution when we don't
46+ // know whether the pointer is null or not.
47+ // We can *not* return `false` here, that would be unsound in `NonNull::new`!
48+ None => panic ! ( "null-ness of this pointer cannot be determined in const context" ) ,
4849 }
4950 }
5051
51- #[ allow( unused_unsafe) ]
52+ // Compare via a cast to a thin pointer, so fat pointers are only
53+ // considering their "data" part for null-ness.
5254 const_eval_select ( ( self as * const u8 , ) , const_impl, runtime_impl)
5355 }
5456
Original file line number Diff line number Diff line change @@ -33,22 +33,7 @@ impl<T: ?Sized> *mut T {
3333 #[ rustc_diagnostic_item = "ptr_is_null" ]
3434 #[ inline]
3535 pub const fn is_null ( self ) -> bool {
36- #[ inline]
37- fn runtime_impl ( ptr : * mut u8 ) -> bool {
38- ptr. addr ( ) == 0
39- }
40-
41- #[ inline]
42- const fn const_impl ( ptr : * mut u8 ) -> bool {
43- // Compare via a cast to a thin pointer, so fat pointers are only
44- // considering their "data" part for null-ness.
45- match ( ptr) . guaranteed_eq ( null_mut ( ) ) {
46- None => false ,
47- Some ( res) => res,
48- }
49- }
50-
51- const_eval_select ( ( self as * mut u8 , ) , const_impl, runtime_impl)
36+ self . cast_const ( ) . is_null ( )
5237 }
5338
5439 /// Casts to a pointer of another type.
You can’t perform that action at this time.
0 commit comments