Skip to content

Commit e146ab2

Browse files
authored
Rollup merge of #144539 - RalfJung:const_with_exposed_provenance, r=oli-obk
constify with_exposed_provenance We allow `int as ptr` in const, so it only makes sense to also allow this function. Otherwise, `const fn` can't be ported to use the more explicit exposed provenance APIs. Note that as of today, `with_exposed_provenance` in const is equivalent to `without_provenance`. However, we probably don't want to promise that: if someone does `with_exposed_provenance(MMIO_ADDR)` in const and then uses that pointer at runtime, that is something we should ensure keeps working; if someone does the same with `without_provenance` then I would consider that UB. Tracking: #144538 Cc `````@rust-lang/wg-const-eval````` `````@rust-lang/opsem`````
2 parents 3a3db99 + d12ecde commit e146ab2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/core/src/ptr/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,10 @@ pub const fn dangling_mut<T>() -> *mut T {
974974
#[must_use]
975975
#[inline(always)]
976976
#[stable(feature = "exposed_provenance", since = "1.84.0")]
977+
#[rustc_const_unstable(feature = "const_exposed_provenance", issue = "144538")]
977978
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
978979
#[allow(fuzzy_provenance_casts)] // this *is* the explicit provenance API one should use instead
979-
pub fn with_exposed_provenance<T>(addr: usize) -> *const T {
980+
pub const fn with_exposed_provenance<T>(addr: usize) -> *const T {
980981
addr as *const T
981982
}
982983

@@ -1014,9 +1015,10 @@ pub fn with_exposed_provenance<T>(addr: usize) -> *const T {
10141015
#[must_use]
10151016
#[inline(always)]
10161017
#[stable(feature = "exposed_provenance", since = "1.84.0")]
1018+
#[rustc_const_unstable(feature = "const_exposed_provenance", issue = "144538")]
10171019
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10181020
#[allow(fuzzy_provenance_casts)] // this *is* the explicit provenance API one should use instead
1019-
pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
1021+
pub const fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
10201022
addr as *mut T
10211023
}
10221024

0 commit comments

Comments
 (0)