Skip to content

Commit 67b9d7d

Browse files
committed
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance
1 parent c3b05c6 commit 67b9d7d

File tree

31 files changed

+85
-85
lines changed

31 files changed

+85
-85
lines changed

compiler/rustc_hir_typeck/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ hir_typeck_invalid_callee = expected function, found {$ty}
8686
hir_typeck_lossy_provenance_int2ptr =
8787
strict provenance disallows casting integer `{$expr_ty}` to pointer `{$cast_ty}`
8888
.suggestion = use `.with_addr()` to adjust a valid pointer in the same allocation, to this address
89-
.help = if you can't comply with strict provenance and don't have a pointer with the correct provenance you can use `std::ptr::from_exposed_addr()` instead
89+
.help = if you can't comply with strict provenance and don't have a pointer with the correct provenance you can use `std::ptr::with_exposed_provenance()` instead
9090
9191
hir_typeck_lossy_provenance_ptr2int =
9292
under strict provenance it is considered bad style to cast pointer `{$expr_ty}` to integer `{$cast_ty}`

compiler/rustc_lint_defs/src/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2749,19 +2749,19 @@ declare_lint! {
27492749
/// memory the pointer is allowed to read/write. Casting an integer, which
27502750
/// doesn't have provenance, to a pointer requires the compiler to assign
27512751
/// (guess) provenance. The compiler assigns "all exposed valid" (see the
2752-
/// docs of [`ptr::from_exposed_addr`] for more information about this
2752+
/// docs of [`ptr::with_exposed_provenance`] for more information about this
27532753
/// "exposing"). This penalizes the optimiser and is not well suited for
27542754
/// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
27552755
/// platforms).
27562756
///
27572757
/// It is much better to use [`ptr::with_addr`] instead to specify the
27582758
/// provenance you want. If using this function is not possible because the
27592759
/// code relies on exposed provenance then there is as an escape hatch
2760-
/// [`ptr::from_exposed_addr`].
2760+
/// [`ptr::with_exposed_provenance`].
27612761
///
27622762
/// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
27632763
/// [`ptr::with_addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.with_addr
2764-
/// [`ptr::from_exposed_addr`]: https://doc.rust-lang.org/core/ptr/fn.from_exposed_addr.html
2764+
/// [`ptr::with_exposed_provenance`]: https://doc.rust-lang.org/core/ptr/fn.with_exposed_provenance.html
27652765
pub FUZZY_PROVENANCE_CASTS,
27662766
Allow,
27672767
"a fuzzy integer to pointer cast is used",

compiler/rustc_middle/src/mir/syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ pub enum CastKind {
13181318
/// See the docs on `expose_addr` for more details.
13191319
PointerExposeAddress,
13201320
/// An address-to-pointer cast that picks up an exposed provenance.
1321-
/// See the docs on `from_exposed_addr` for more details.
1321+
/// See the docs on `with_exposed_provenance` for more details.
13221322
PointerFromExposedAddress,
13231323
/// Pointer related casts that are done by coercions. Note that reference-to-raw-ptr casts are
13241324
/// translated into `&raw mut/const *r`, i.e., they are not actually casts.

library/core/src/ptr/const_ptr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<T: ?Sized> *const T {
165165
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
166166
#[deprecated(
167167
since = "1.67.0",
168-
note = "replaced by the `ptr::from_exposed_addr` function, or update \
168+
note = "replaced by the `ptr::with_exposed_provenance` function, or update \
169169
your code to follow the strict provenance rules using its APIs"
170170
)]
171171
#[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function
@@ -187,7 +187,7 @@ impl<T: ?Sized> *const T {
187187
///
188188
/// If using those APIs is not possible because there is no way to preserve a pointer with the
189189
/// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
190-
/// or [`expose_addr`][pointer::expose_addr] and [`from_exposed_addr`][from_exposed_addr]
190+
/// or [`expose_addr`][pointer::expose_addr] and [`with_exposed_provenance`][with_exposed_provenance]
191191
/// instead. However, note that this makes your code less portable and less amenable to tools
192192
/// that check for compliance with the Rust memory model.
193193
///
@@ -211,30 +211,30 @@ impl<T: ?Sized> *const T {
211211
}
212212

213213
/// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future
214-
/// use in [`from_exposed_addr`][].
214+
/// use in [`with_exposed_provenance`][].
215215
///
216216
/// This is equivalent to `self as usize`, which semantically discards *provenance* and
217217
/// *address-space* information. Furthermore, this (like the `as` cast) has the implicit
218218
/// side-effect of marking the provenance as 'exposed', so on platforms that support it you can
219-
/// later call [`from_exposed_addr`][] to reconstitute the original pointer including its
219+
/// later call [`with_exposed_provenance`][] to reconstitute the original pointer including its
220220
/// provenance. (Reconstructing address space information, if required, is your responsibility.)
221221
///
222222
/// Using this method means that code is *not* following [Strict
223223
/// Provenance][super#strict-provenance] rules. Supporting
224-
/// [`from_exposed_addr`][] complicates specification and reasoning and may not be supported by
224+
/// [`with_exposed_provenance`][] complicates specification and reasoning and may not be supported by
225225
/// tools that help you to stay conformant with the Rust memory model, so it is recommended to
226226
/// use [`addr`][pointer::addr] wherever possible.
227227
///
228228
/// On most platforms this will produce a value with the same bytes as the original pointer,
229229
/// because all the bytes are dedicated to describing the address. Platforms which need to store
230230
/// additional information in the pointer may not support this operation, since the 'expose'
231-
/// side-effect which is required for [`from_exposed_addr`][] to work is typically not
231+
/// side-effect which is required for [`with_exposed_provenance`][] to work is typically not
232232
/// available.
233233
///
234234
/// It is unclear whether this method can be given a satisfying unambiguous specification. This
235235
/// API and its claimed semantics are part of [Exposed Provenance][super#exposed-provenance].
236236
///
237-
/// [`from_exposed_addr`]: from_exposed_addr
237+
/// [`with_exposed_provenance`]: with_exposed_provenance
238238
#[must_use]
239239
#[inline(always)]
240240
#[unstable(feature = "exposed_provenance", issue = "95228")]

library/core/src/ptr/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,13 @@
340340
//! clear where a satisfying unambiguous semantics can be defined for Exposed Provenance.
341341
//! Furthermore, Exposed Provenance will not work (well) with tools like [Miri] and [CHERI].
342342
//!
343-
//! Exposed Provenance is provided by the [`expose_addr`] and [`from_exposed_addr`] methods, which
343+
//! Exposed Provenance is provided by the [`expose_addr`] and [`with_exposed_provenance`] methods, which
344344
//! are meant to replace `as` casts between pointers and integers. [`expose_addr`] is a lot like
345345
//! [`addr`], but additionally adds the provenance of the pointer to a global list of 'exposed'
346346
//! provenances. (This list is purely conceptual, it exists for the purpose of specifying Rust but
347-
//! is not materialized in actual executions, except in tools like [Miri].) [`from_exposed_addr`]
347+
//! is not materialized in actual executions, except in tools like [Miri].) [`with_exposed_provenance`]
348348
//! can be used to construct a pointer with one of these previously 'exposed' provenances.
349-
//! [`from_exposed_addr`] takes only `addr: usize` as arguments, so unlike in [`with_addr`] there is
349+
//! [`with_exposed_provenance`] takes only `addr: usize` as arguments, so unlike in [`with_addr`] there is
350350
//! no indication of what the correct provenance for the returned pointer is -- and that is exactly
351351
//! what makes pointer-usize-pointer roundtrips so tricky to rigorously specify! There is no
352352
//! algorithm that decides which provenance will be used. You can think of this as "guessing" the
@@ -355,10 +355,10 @@
355355
//! there is *no* previously 'exposed' provenance that justifies the way the returned pointer will
356356
//! be used, the program has undefined behavior.
357357
//!
358-
//! Using [`expose_addr`] or [`from_exposed_addr`] (or the `as` casts) means that code is
358+
//! Using [`expose_addr`] or [`with_exposed_provenance`] (or the `as` casts) means that code is
359359
//! *not* following Strict Provenance rules. The goal of the Strict Provenance experiment is to
360360
//! determine how far one can get in Rust without the use of [`expose_addr`] and
361-
//! [`from_exposed_addr`], and to encourage code to be written with Strict Provenance APIs only.
361+
//! [`with_exposed_provenance`], and to encourage code to be written with Strict Provenance APIs only.
362362
//! Maximizing the amount of such code is a major win for avoiding specification complexity and to
363363
//! facilitate adoption of tools like [CHERI] and [Miri] that can be a big help in increasing the
364364
//! confidence in (unsafe) Rust code.
@@ -375,7 +375,7 @@
375375
//! [`addr`]: pointer::addr
376376
//! [`ptr::dangling`]: core::ptr::dangling
377377
//! [`expose_addr`]: pointer::expose_addr
378-
//! [`from_exposed_addr`]: from_exposed_addr
378+
//! [`with_exposed_provenance`]: with_exposed_provenance
379379
//! [Miri]: https://github.com/rust-lang/miri
380380
//! [CHERI]: https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/
381381
//! [Strict Provenance]: https://github.com/rust-lang/rust/issues/95228
@@ -582,7 +582,7 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
582582
/// little more than a usize address in disguise.
583583
///
584584
/// This is different from `addr as *const T`, which creates a pointer that picks up a previously
585-
/// exposed provenance. See [`from_exposed_addr`] for more details on that operation.
585+
/// exposed provenance. See [`with_exposed_provenance`] for more details on that operation.
586586
///
587587
/// This API and its claimed semantics are part of the Strict Provenance experiment,
588588
/// see the [module documentation][crate::ptr] for details.
@@ -593,7 +593,7 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
593593
pub const fn without_provenance<T>(addr: usize) -> *const T {
594594
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
595595
// We use transmute rather than a cast so tools like Miri can tell that this
596-
// is *not* the same as from_exposed_addr.
596+
// is *not* the same as with_exposed_provenance.
597597
// SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
598598
// pointer).
599599
unsafe { mem::transmute(addr) }
@@ -626,7 +626,7 @@ pub const fn dangling<T>() -> *const T {
626626
/// little more than a usize address in disguise.
627627
///
628628
/// This is different from `addr as *mut T`, which creates a pointer that picks up a previously
629-
/// exposed provenance. See [`from_exposed_addr_mut`] for more details on that operation.
629+
/// exposed provenance. See [`with_exposed_provenance_mut`] for more details on that operation.
630630
///
631631
/// This API and its claimed semantics are part of the Strict Provenance experiment,
632632
/// see the [module documentation][crate::ptr] for details.
@@ -637,7 +637,7 @@ pub const fn dangling<T>() -> *const T {
637637
pub const fn without_provenance_mut<T>(addr: usize) -> *mut T {
638638
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
639639
// We use transmute rather than a cast so tools like Miri can tell that this
640-
// is *not* the same as from_exposed_addr.
640+
// is *not* the same as with_exposed_provenance.
641641
// SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
642642
// pointer).
643643
unsafe { mem::transmute(addr) }
@@ -700,7 +700,7 @@ pub const fn dangling_mut<T>() -> *mut T {
700700
#[unstable(feature = "exposed_provenance", issue = "95228")]
701701
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
702702
#[allow(fuzzy_provenance_casts)] // this *is* the explicit provenance API one should use instead
703-
pub fn from_exposed_addr<T>(addr: usize) -> *const T
703+
pub fn with_exposed_provenance<T>(addr: usize) -> *const T
704704
where
705705
T: Sized,
706706
{
@@ -740,7 +740,7 @@ where
740740
#[unstable(feature = "exposed_provenance", issue = "95228")]
741741
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
742742
#[allow(fuzzy_provenance_casts)] // this *is* the explicit provenance API one should use instead
743-
pub fn from_exposed_addr_mut<T>(addr: usize) -> *mut T
743+
pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T
744744
where
745745
T: Sized,
746746
{

library/core/src/ptr/mut_ptr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<T: ?Sized> *mut T {
171171
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
172172
#[deprecated(
173173
since = "1.67.0",
174-
note = "replaced by the `ptr::from_exposed_addr_mut` function, or \
174+
note = "replaced by the `ptr::with_exposed_provenance_mut` function, or \
175175
update your code to follow the strict provenance rules using its APIs"
176176
)]
177177
#[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function
@@ -194,7 +194,7 @@ impl<T: ?Sized> *mut T {
194194
///
195195
/// If using those APIs is not possible because there is no way to preserve a pointer with the
196196
/// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
197-
/// or [`expose_addr`][pointer::expose_addr] and [`from_exposed_addr`][from_exposed_addr]
197+
/// or [`expose_addr`][pointer::expose_addr] and [`with_exposed_provenance`][with_exposed_provenance]
198198
/// instead. However, note that this makes your code less portable and less amenable to tools
199199
/// that check for compliance with the Rust memory model.
200200
///
@@ -218,30 +218,30 @@ impl<T: ?Sized> *mut T {
218218
}
219219

220220
/// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future
221-
/// use in [`from_exposed_addr`][].
221+
/// use in [`with_exposed_provenance`][].
222222
///
223223
/// This is equivalent to `self as usize`, which semantically discards *provenance* and
224224
/// *address-space* information. Furthermore, this (like the `as` cast) has the implicit
225225
/// side-effect of marking the provenance as 'exposed', so on platforms that support it you can
226-
/// later call [`from_exposed_addr_mut`][] to reconstitute the original pointer including its
226+
/// later call [`with_exposed_provenance_mut`][] to reconstitute the original pointer including its
227227
/// provenance. (Reconstructing address space information, if required, is your responsibility.)
228228
///
229229
/// Using this method means that code is *not* following [Strict
230230
/// Provenance][super#strict-provenance] rules. Supporting
231-
/// [`from_exposed_addr_mut`][] complicates specification and reasoning and may not be supported
231+
/// [`with_exposed_provenance_mut`][] complicates specification and reasoning and may not be supported
232232
/// by tools that help you to stay conformant with the Rust memory model, so it is recommended
233233
/// to use [`addr`][pointer::addr] wherever possible.
234234
///
235235
/// On most platforms this will produce a value with the same bytes as the original pointer,
236236
/// because all the bytes are dedicated to describing the address. Platforms which need to store
237237
/// additional information in the pointer may not support this operation, since the 'expose'
238-
/// side-effect which is required for [`from_exposed_addr_mut`][] to work is typically not
238+
/// side-effect which is required for [`with_exposed_provenance_mut`][] to work is typically not
239239
/// available.
240240
///
241241
/// It is unclear whether this method can be given a satisfying unambiguous specification. This
242242
/// API and its claimed semantics are part of [Exposed Provenance][super#exposed-provenance].
243243
///
244-
/// [`from_exposed_addr_mut`]: from_exposed_addr_mut
244+
/// [`with_exposed_provenance_mut`]: with_exposed_provenance_mut
245245
#[must_use]
246246
#[inline(always)]
247247
#[unstable(feature = "exposed_provenance", issue = "95228")]

library/portable-simd/crates/core_simd/src/simd/ptr/const_ptr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ pub trait SimdConstPtr: Copy + Sealed {
5151
fn with_addr(self, addr: Self::Usize) -> Self;
5252

5353
/// Gets the "address" portion of the pointer, and "exposes" the provenance part for future use
54-
/// in [`Self::from_exposed_addr`].
54+
/// in [`Self::with_exposed_provenance`].
5555
fn expose_addr(self) -> Self::Usize;
5656

5757
/// Convert an address back to a pointer, picking up a previously "exposed" provenance.
5858
///
59-
/// Equivalent to calling [`core::ptr::from_exposed_addr`] on each element.
60-
fn from_exposed_addr(addr: Self::Usize) -> Self;
59+
/// Equivalent to calling [`core::ptr::with_exposed_provenance`] on each element.
60+
fn with_exposed_provenance(addr: Self::Usize) -> Self;
6161

6262
/// Calculates the offset from a pointer using wrapping arithmetic.
6363
///
@@ -137,7 +137,7 @@ where
137137
}
138138

139139
#[inline]
140-
fn from_exposed_addr(addr: Self::Usize) -> Self {
140+
fn with_exposed_provenance(addr: Self::Usize) -> Self {
141141
// Safety: `self` is a pointer vector
142142
unsafe { core::intrinsics::simd::simd_from_exposed_addr(addr) }
143143
}

library/portable-simd/crates/core_simd/src/simd/ptr/mut_ptr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ pub trait SimdMutPtr: Copy + Sealed {
4848
fn with_addr(self, addr: Self::Usize) -> Self;
4949

5050
/// Gets the "address" portion of the pointer, and "exposes" the provenance part for future use
51-
/// in [`Self::from_exposed_addr`].
51+
/// in [`Self::with_exposed_provenance`].
5252
fn expose_addr(self) -> Self::Usize;
5353

5454
/// Convert an address back to a pointer, picking up a previously "exposed" provenance.
5555
///
56-
/// Equivalent to calling [`core::ptr::from_exposed_addr_mut`] on each element.
57-
fn from_exposed_addr(addr: Self::Usize) -> Self;
56+
/// Equivalent to calling [`core::ptr::with_exposed_provenance_mut`] on each element.
57+
fn with_exposed_provenance(addr: Self::Usize) -> Self;
5858

5959
/// Calculates the offset from a pointer using wrapping arithmetic.
6060
///
@@ -134,7 +134,7 @@ where
134134
}
135135

136136
#[inline]
137-
fn from_exposed_addr(addr: Self::Usize) -> Self {
137+
fn with_exposed_provenance(addr: Self::Usize) -> Self {
138138
// Safety: `self` is a pointer vector
139139
unsafe { core::intrinsics::simd::simd_from_exposed_addr(addr) }
140140
}

library/portable-simd/crates/core_simd/tests/pointers.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ mod const_ptr {
8080
);
8181
}
8282

83-
fn from_exposed_addr<const LANES: usize>() {
83+
fn with_exposed_provenance<const LANES: usize>() {
8484
test_helpers::test_unary_elementwise(
85-
&Simd::<*const u32, LANES>::from_exposed_addr,
86-
&core::ptr::from_exposed_addr::<u32>,
85+
&Simd::<*const u32, LANES>::with_exposed_provenance,
86+
&core::ptr::with_exposed_provenance::<u32>,
8787
&|_| true,
8888
);
8989
}
@@ -103,10 +103,10 @@ mod mut_ptr {
103103
);
104104
}
105105

106-
fn from_exposed_addr<const LANES: usize>() {
106+
fn with_exposed_provenance<const LANES: usize>() {
107107
test_helpers::test_unary_elementwise(
108-
&Simd::<*mut u32, LANES>::from_exposed_addr,
109-
&core::ptr::from_exposed_addr_mut::<u32>,
108+
&Simd::<*mut u32, LANES>::with_exposed_provenance,
109+
&core::ptr::with_exposed_provenance_mut::<u32>,
110110
&|_| true,
111111
);
112112
}

library/std/src/os/xous/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pub(crate) unsafe fn map_memory<T>(
389389
let result = a0;
390390

391391
if result == SyscallResult::MemoryRange as usize {
392-
let start = core::ptr::from_exposed_addr_mut::<T>(a1);
392+
let start = core::ptr::with_exposed_provenance_mut::<T>(a1);
393393
let len = a2 / core::mem::size_of::<T>();
394394
let end = unsafe { start.add(len) };
395395
Ok(unsafe { core::slice::from_raw_parts_mut(start, len) })

library/std/src/sys/pal/hermit/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Thread {
4747
extern "C" fn thread_start(main: usize) {
4848
unsafe {
4949
// Finally, let's run some code.
50-
Box::from_raw(ptr::from_exposed_addr::<Box<dyn FnOnce()>>(main).cast_mut())();
50+
Box::from_raw(ptr::with_exposed_provenance::<Box<dyn FnOnce()>>(main).cast_mut())();
5151

5252
// run all destructors
5353
run_dtors();

library/std/src/sys/pal/itron/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Thread {
9898
});
9999

100100
unsafe extern "C" fn trampoline(exinf: isize) {
101-
let p_inner: *mut ThreadInner = crate::ptr::from_exposed_addr_mut(exinf as usize);
101+
let p_inner: *mut ThreadInner = crate::ptr::with_exposed_provenance_mut(exinf as usize);
102102
// Safety: `ThreadInner` is alive at this point
103103
let inner = unsafe { &*p_inner };
104104

0 commit comments

Comments
 (0)