Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly document is_null CTFE behavior. #134325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ impl<T: ?Sized> *const T {
///
/// ## Behavior during const evaluation
///
/// When this function is used during const evaluation, it may return `false` for pointers
/// that turn out to be null at runtime. Specifically, when a pointer to some memory
/// is offset beyond its bounds in such a way that the resulting pointer is null,
/// the function will still return `false`. There is no way for CTFE to know
/// the absolute position of that memory, so we cannot tell if the pointer is
/// null or not.
/// When this function is used during const evaluation, this function will
/// panic if CTFE cannot determine whether the pointer is null or not. This
/// panic might or might not occur when `self` is a pointer that is offset
/// beyond the bounds of the memory it initially pointed to. Conversely,
/// this panic will never occur when `self` is in-bounds.
///
/// This inability to determine nullness occurs because there is no way for
/// CTFE to know the absolute position of that memory, so it might or might
/// not be possible to determine whether an offset out of bounds happens to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// not be possible to determine whether an offset out of bounds happens to
/// not be possible to determine whether an out-of-bounds offset happens to

/// result in a null pointer.
///
/// # Examples
///
Expand Down
16 changes: 10 additions & 6 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ impl<T: ?Sized> *mut T {
///
/// ## Behavior during const evaluation
///
/// When this function is used during const evaluation, it may return `false` for pointers
/// that turn out to be null at runtime. Specifically, when a pointer to some memory
/// is offset beyond its bounds in such a way that the resulting pointer is null,
/// the function will still return `false`. There is no way for CTFE to know
/// the absolute position of that memory, so we cannot tell if the pointer is
/// null or not.
/// When this function is used during const evaluation, this function will
/// panic if CTFE cannot determine whether the pointer is null or not. This
/// panic might or might not occur when `self` is a pointer that is offset
/// beyond the bounds of the memory it initially pointed to. Conversely,
/// this panic will never occur when `self` is in-bounds.
///
/// This inability to determine nullness occurs because there is no way for
/// CTFE to know the absolute position of that memory, so it might or might
/// not be possible to determine whether an offset out of bounds happens to
/// result in a null pointer.
///
/// # Examples
///
Expand Down
Loading