Closed
Description
opened on Jul 30, 2020
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.
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Category: An issue tracking the progress of sth. like the implementation of an RFCRelevant to the language team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.
Activity