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 be const fn:
-
The following methods are not part of this issue:
Steps (based on #69821)
Unresolved Questions
- How should
offset == 0 be handled?
CC: @RalfJung @oli-obk @rust-lang/wg-const-eval
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:The following intrinsic functions will be made
const fn:intrinsics::offsetintrinsics::arith_offsetThe allows the following
*const/*mutmethods to beconst fn:offsetwrapping_offsetadd/subwrapping_add/wrapping_subThe 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 allocationsSteps (based on #69821)
core/alloc/stdfunctions should be made const along with this.offsetandarith_offsetUnresolved Questions
offset == 0be handled?CC: @RalfJung @oli-obk @rust-lang/wg-const-eval