Tracking issue for const <*const T>::is_null
· Issue #74939 · rust-lang/rust (original) (raw)
This is tracking #[feature(const_ptr_is_null)]
.
impl<T: ?Sized> *const T { pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>; pub const fn is_null(&self) -> bool; }
impl<T: ?Sized> *mut T { pub const unsafe fn as_mut<'a>(self) -> Option<&'a mut T>; pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>; pub const fn is_null(&self) -> bool; }
Comparing pointers in const eval is dangerous business.
But checking whether a pointer is the null pointer is actually completely fine, as Rust does not support items being placed at the null address. Any otherwise created null pointers are supposed to return true
for is_null
anyway, so that's ok. Thus, we implement is_null
as ptr.guaranteed_eq(ptr::null())
, which returns true if it's guaranteed that ptr
is null, and there are no cases where it will return false where it may be null
, but we don't know.