Closed
Description
The feature gate for this is #![feature(const_ptr_offset)]
. Miri has been able to handle this for some time. This feature allows code like:
static FOO: u8 = 42;
static PTR1: *const u8 = &FOO as *const u8;
static PTR2: *const u8 = PTR1.wrapping_offset(1);
-
The following intrinsic functions will be made
const fn
: -
The allows the following
*const
/*mut
methods to beconst fn
: -
The following methods are not part of this issue:
align_offset
: See align_offset guarantees #62420offset_from
: Tracked as part of Tracking issue for ptr::offset_from (feature: ptr_offset_from) #41079 and Tracking Issue for const offset_from (const_ptr_offset_from) #92980wrapping_offset_from
: Not possible across different allocations- Any read/write methods: Tracked in [tracking issue] dereferencing raw pointers inside constants (const_raw_ptr_deref) #51911
Steps (based on #69821)
- Implemented in Make pointer offset methods/intrinsics const #71500
- Check if any other
core
/alloc
/std
functions should be made const along with this. - Remove miri's implementations for
offset
andarith_offset
- Final commenting period (FCP): Tracking Issue for making ptr offset methods "const fn" #71499 (comment)
- Stabilization PR
Unresolved Questions
- How should
offset == 0
be handled?- As implemented, we allow offsets of 0 for all pointers (including dangling pointers) except for null pointers.
- Should we allow offsets of 0 for null pointers?
- The documentation is a bit unclear on this, see: ptr::offset should explicitly clarify 0-sized offset semantics #65108 and @RalfJung's comment
Metadata
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 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.