Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c3e928d

Browse files
committedOct 21, 2024
stabilize Strict Provenance and Exposed Provenance
This comes with a big docs rewrite.
1 parent bfab34a commit c3e928d

File tree

5 files changed

+312
-387
lines changed

5 files changed

+312
-387
lines changed
 

‎compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
361361
(Int(..) | Float(_), Int(..) | Float(_)) => bx.bitcast(imm, to_backend_ty),
362362
(Pointer(..), Pointer(..)) => bx.pointercast(imm, to_backend_ty),
363363
(Int(..), Pointer(..)) => bx.ptradd(bx.const_null(bx.type_ptr()), imm),
364-
(Pointer(..), Int(..)) => bx.ptrtoint(imm, to_backend_ty),
364+
(Pointer(..), Int(..)) => {
365+
// FIXME: this exposes the provenance, which shouldn't be necessary.
366+
bx.ptrtoint(imm, to_backend_ty)
367+
}
365368
(Float(_), Pointer(..)) => {
366369
let int_imm = bx.bitcast(imm, bx.cx().type_isize());
367370
bx.ptradd(bx.const_null(bx.type_ptr()), int_imm)
368371
}
369372
(Pointer(..), Float(_)) => {
373+
// FIXME: this exposes the provenance, which shouldn't be necessary.
370374
let int_imm = bx.ptrtoint(imm, bx.cx().type_isize());
371375
bx.bitcast(int_imm, to_backend_ty)
372376
}

‎library/core/src/ptr/const_ptr.rs

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ impl<T: ?Sized> *const T {
137137

138138
/// Gets the "address" portion of the pointer.
139139
///
140-
/// This is similar to `self as usize`, which semantically discards *provenance* and
141-
/// *address-space* information. However, unlike `self as usize`, casting the returned address
142-
/// back to a pointer yields a [pointer without provenance][without_provenance], which is undefined behavior to dereference. To
143-
/// properly restore the lost information and obtain a dereferenceable pointer, use
140+
/// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
141+
/// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
142+
/// casting the returned address back to a pointer yields a [pointer without
143+
/// provenance][without_provenance], which is undefined behavior to dereference. To properly
144+
/// restore the lost information and obtain a dereferenceable pointer, use
144145
/// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
145146
///
146147
/// If using those APIs is not possible because there is no way to preserve a pointer with the
@@ -155,90 +156,81 @@ impl<T: ?Sized> *const T {
155156
/// perform a change of representation to produce a value containing only the address
156157
/// portion of the pointer. What that means is up to the platform to define.
157158
///
158-
/// This API and its claimed semantics are part of the Strict Provenance experiment, and as such
159-
/// might change in the future (including possibly weakening this so it becomes wholly
160-
/// equivalent to `self as usize`). See the [module documentation][crate::ptr] for details.
159+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
161160
#[must_use]
162161
#[inline(always)]
163-
#[unstable(feature = "strict_provenance", issue = "95228")]
162+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
164163
pub fn addr(self) -> usize {
165-
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
164+
// A pointer-to-integer transmute currently has exactly the right semantics: it returns the
165+
// address without exposing the provenance. Note that this is *not* a stable guarantee about
166+
// transmute semantics, it relies on sysroot crates having special status.
166167
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
167168
// provenance).
168169
unsafe { mem::transmute(self.cast::<()>()) }
169170
}
170171

171-
/// Exposes the "provenance" part of the pointer for future use in
172-
/// [`with_exposed_provenance`][] and returns the "address" portion.
172+
/// Exposes the ["provenance"][crate::ptr#provenance] part of the pointer for future use in
173+
/// [`with_exposed_provenance`] and returns the "address" portion.
173174
///
174-
/// This is equivalent to `self as usize`, which semantically discards *provenance* and
175-
/// *address-space* information. Furthermore, this (like the `as` cast) has the implicit
176-
/// side-effect of marking the provenance as 'exposed', so on platforms that support it you can
177-
/// later call [`with_exposed_provenance`][] to reconstitute the original pointer including its
178-
/// provenance. (Reconstructing address space information, if required, is your responsibility.)
175+
/// This is equivalent to `self as usize`, which semantically discards provenance information.
176+
/// Furthermore, this (like the `as` cast) has the implicit side-effect of marking the
177+
/// provenance as 'exposed', so on platforms that support it you can later call
178+
/// [`with_exposed_provenance`] to reconstitute the original pointer including its provenance.
179179
///
180-
/// Using this method means that code is *not* following [Strict
181-
/// Provenance][super#strict-provenance] rules. Supporting
182-
/// [`with_exposed_provenance`][] complicates specification and reasoning and may not be supported by
183-
/// tools that help you to stay conformant with the Rust memory model, so it is recommended to
184-
/// use [`addr`][pointer::addr] wherever possible.
180+
/// Due to its inherent ambiguity, [`with_exposed_provenance`] may not be supported by tools
181+
/// that help you to stay conformant with the Rust memory model. It is recommended to use
182+
/// [Strict Provenance][crate::ptr#strict-provenance] APIs such as [`with_addr`][pointer::with_addr]
183+
/// wherever possible, in which case [`addr`][pointer::addr] should be used instead of `expose_provenance`.
185184
///
186185
/// On most platforms this will produce a value with the same bytes as the original pointer,
187186
/// because all the bytes are dedicated to describing the address. Platforms which need to store
188187
/// additional information in the pointer may not support this operation, since the 'expose'
189-
/// side-effect which is required for [`with_exposed_provenance`][] to work is typically not
188+
/// side-effect which is required for [`with_exposed_provenance`] to work is typically not
190189
/// available.
191190
///
192-
/// It is unclear whether this method can be given a satisfying unambiguous specification. This
193-
/// API and its claimed semantics are part of [Exposed Provenance][super#exposed-provenance].
191+
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
194192
///
195193
/// [`with_exposed_provenance`]: with_exposed_provenance
196194
#[must_use]
197195
#[inline(always)]
198-
#[unstable(feature = "exposed_provenance", issue = "95228")]
196+
#[stable(feature = "exposed_provenance", since = "CURRENT_RUSTC_VERSION")]
199197
pub fn expose_provenance(self) -> usize {
200-
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
201198
self.cast::<()>() as usize
202199
}
203200

204-
/// Creates a new pointer with the given address.
201+
/// Creates a new pointer with the given address and the [provenance][crate::ptr#provenance] of
202+
/// `self`.
205203
///
206-
/// This performs the same operation as an `addr as ptr` cast, but copies
207-
/// the *address-space* and *provenance* of `self` to the new pointer.
208-
/// This allows us to dynamically preserve and propagate this important
209-
/// information in a way that is otherwise impossible with a unary cast.
204+
/// This is similar to a `addr as *const T` cast, but copies
205+
/// the *provenance* of `self` to the new pointer.
206+
/// This avoids the inherent ambiguity of the unary cast.
210207
///
211208
/// This is equivalent to using [`wrapping_offset`][pointer::wrapping_offset] to offset
212209
/// `self` to the given address, and therefore has all the same capabilities and restrictions.
213210
///
214-
/// This API and its claimed semantics are part of the Strict Provenance experiment,
215-
/// see the [module documentation][crate::ptr] for details.
211+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
216212
#[must_use]
217213
#[inline]
218-
#[unstable(feature = "strict_provenance", issue = "95228")]
214+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
219215
pub fn with_addr(self, addr: usize) -> Self {
220-
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
221-
//
222-
// In the mean-time, this operation is defined to be "as if" it was
223-
// a wrapping_offset, so we can emulate it as such. This should properly
224-
// restore pointer provenance even under today's compiler.
216+
// This should probably be an intrinsic to avoid doing any sort of arithmetic, but
217+
// meanwhile, we can implement it with `wrapping_offset`, which preserves the pointer's
218+
// provenance.
225219
let self_addr = self.addr() as isize;
226220
let dest_addr = addr as isize;
227221
let offset = dest_addr.wrapping_sub(self_addr);
228-
229-
// This is the canonical desugaring of this operation
230222
self.wrapping_byte_offset(offset)
231223
}
232224

233-
/// Creates a new pointer by mapping `self`'s address to a new one.
225+
/// Creates a new pointer by mapping `self`'s address to a new one, preserving the
226+
/// [provenance][crate::ptr#provenance] of `self`.
234227
///
235228
/// This is a convenience for [`with_addr`][pointer::with_addr], see that method for details.
236229
///
237-
/// This API and its claimed semantics are part of the Strict Provenance experiment,
238-
/// see the [module documentation][crate::ptr] for details.
230+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
239231
#[must_use]
240232
#[inline]
241-
#[unstable(feature = "strict_provenance", issue = "95228")]
233+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
242234
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self {
243235
self.with_addr(f(self.addr()))
244236
}
@@ -379,7 +371,7 @@ impl<T: ?Sized> *const T {
379371
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
380372
/// "wrapping around"), must fit in an `isize`.
381373
///
382-
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
374+
/// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
383375
/// [allocated object], and the entire memory range between `self` and the result must be in
384376
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
385377
/// of the address space.
@@ -611,7 +603,7 @@ impl<T: ?Sized> *const T {
611603
/// * `self` and `origin` must either
612604
///
613605
/// * point to the same address, or
614-
/// * both be *derived from* a pointer to the same [allocated object], and the memory range between
606+
/// * both be [derived from][crate::ptr#provenance] a pointer to the same [allocated object], and the memory range between
615607
/// the two pointers must be in bounds of that object. (See below for an example.)
616608
///
617609
/// * The distance between the pointers, in bytes, must be an exact multiple
@@ -871,7 +863,7 @@ impl<T: ?Sized> *const T {
871863
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
872864
/// "wrapping around"), must fit in an `isize`.
873865
///
874-
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
866+
/// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
875867
/// [allocated object], and the entire memory range between `self` and the result must be in
876868
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
877869
/// of the address space.
@@ -978,7 +970,7 @@ impl<T: ?Sized> *const T {
978970
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
979971
/// "wrapping around"), must fit in an `isize`.
980972
///
981-
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
973+
/// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
982974
/// [allocated object], and the entire memory range between `self` and the result must be in
983975
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
984976
/// of the address space.

‎library/core/src/ptr/mod.rs

Lines changed: 214 additions & 275 deletions
Large diffs are not rendered by default.

‎library/core/src/ptr/mut_ptr.rs

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ impl<T: ?Sized> *mut T {
124124

125125
/// Gets the "address" portion of the pointer.
126126
///
127-
/// This is similar to `self as usize`, which semantically discards *provenance* and
128-
/// *address-space* information. However, unlike `self as usize`, casting the returned address
129-
/// back to a pointer yields a [pointer without provenance][without_provenance_mut], which is undefined
130-
/// behavior to dereference. To properly restore the lost information and obtain a
131-
/// dereferenceable pointer, use [`with_addr`][pointer::with_addr] or
132-
/// [`map_addr`][pointer::map_addr].
127+
/// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
128+
/// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
129+
/// casting the returned address back to a pointer yields a [pointer without
130+
/// provenance][without_provenance_mut], which is undefined behavior to dereference. To properly
131+
/// restore the lost information and obtain a dereferenceable pointer, use
132+
/// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
133133
///
134134
/// If using those APIs is not possible because there is no way to preserve a pointer with the
135135
/// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
@@ -143,89 +143,80 @@ impl<T: ?Sized> *mut T {
143143
/// perform a change of representation to produce a value containing only the address
144144
/// portion of the pointer. What that means is up to the platform to define.
145145
///
146-
/// This API and its claimed semantics are part of the Strict Provenance experiment, and as such
147-
/// might change in the future (including possibly weakening this so it becomes wholly
148-
/// equivalent to `self as usize`). See the [module documentation][crate::ptr] for details.
146+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
149147
#[must_use]
150148
#[inline(always)]
151-
#[unstable(feature = "strict_provenance", issue = "95228")]
149+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
152150
pub fn addr(self) -> usize {
153-
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
151+
// A pointer-to-integer transmute currently has exactly the right semantics: it returns the
152+
// address without exposing the provenance. Note that this is *not* a stable guarantee about
153+
// transmute semantics, it relies on sysroot crates having special status.
154154
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
155155
// provenance).
156156
unsafe { mem::transmute(self.cast::<()>()) }
157157
}
158158

159-
/// Exposes the "provenance" part of the pointer for future use in
160-
/// [`with_exposed_provenance`][] and returns the "address" portion.
159+
/// Exposes the ["provenance"][crate::ptr#provenance] part of the pointer for future use in
160+
/// [`with_exposed_provenance_mut`] and returns the "address" portion.
161161
///
162-
/// This is equivalent to `self as usize`, which semantically discards *provenance* and
163-
/// *address-space* information. Furthermore, this (like the `as` cast) has the implicit
164-
/// side-effect of marking the provenance as 'exposed', so on platforms that support it you can
165-
/// later call [`with_exposed_provenance_mut`][] to reconstitute the original pointer including its
166-
/// provenance. (Reconstructing address space information, if required, is your responsibility.)
162+
/// This is equivalent to `self as usize`, which semantically discards provenance information.
163+
/// Furthermore, this (like the `as` cast) has the implicit side-effect of marking the
164+
/// provenance as 'exposed', so on platforms that support it you can later call
165+
/// [`with_exposed_provenance_mut`] to reconstitute the original pointer including its provenance.
167166
///
168-
/// Using this method means that code is *not* following [Strict
169-
/// Provenance][super#strict-provenance] rules. Supporting
170-
/// [`with_exposed_provenance_mut`][] complicates specification and reasoning and may not be supported
171-
/// by tools that help you to stay conformant with the Rust memory model, so it is recommended
172-
/// to use [`addr`][pointer::addr] wherever possible.
167+
/// Due to its inherent ambiguity, [`with_exposed_provenance_mut`] may not be supported by tools
168+
/// that help you to stay conformant with the Rust memory model. It is recommended to use
169+
/// [Strict Provenance][crate::ptr#strict-provenance] APIs such as [`with_addr`][pointer::with_addr]
170+
/// wherever possible, in which case [`addr`][pointer::addr] should be used instead of `expose_provenance`.
173171
///
174172
/// On most platforms this will produce a value with the same bytes as the original pointer,
175173
/// because all the bytes are dedicated to describing the address. Platforms which need to store
176174
/// additional information in the pointer may not support this operation, since the 'expose'
177-
/// side-effect which is required for [`with_exposed_provenance_mut`][] to work is typically not
175+
/// side-effect which is required for [`with_exposed_provenance_mut`] to work is typically not
178176
/// available.
179177
///
180-
/// It is unclear whether this method can be given a satisfying unambiguous specification. This
181-
/// API and its claimed semantics are part of [Exposed Provenance][super#exposed-provenance].
178+
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
182179
///
183180
/// [`with_exposed_provenance_mut`]: with_exposed_provenance_mut
184181
#[inline(always)]
185-
#[unstable(feature = "exposed_provenance", issue = "95228")]
182+
#[stable(feature = "exposed_provenance", since = "CURRENT_RUSTC_VERSION")]
186183
pub fn expose_provenance(self) -> usize {
187-
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
188184
self.cast::<()>() as usize
189185
}
190186

191-
/// Creates a new pointer with the given address.
187+
/// Creates a new pointer with the given address and the [provenance][crate::ptr#provenance] of
188+
/// `self`.
192189
///
193-
/// This performs the same operation as an `addr as ptr` cast, but copies
194-
/// the *address-space* and *provenance* of `self` to the new pointer.
195-
/// This allows us to dynamically preserve and propagate this important
196-
/// information in a way that is otherwise impossible with a unary cast.
190+
/// This is similar to a `addr as *mut T` cast, but copies
191+
/// the *provenance* of `self` to the new pointer.
192+
/// This avoids the inherent ambiguity of the unary cast.
197193
///
198194
/// This is equivalent to using [`wrapping_offset`][pointer::wrapping_offset] to offset
199195
/// `self` to the given address, and therefore has all the same capabilities and restrictions.
200196
///
201-
/// This API and its claimed semantics are an extension to the Strict Provenance experiment,
202-
/// see the [module documentation][crate::ptr] for details.
197+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
203198
#[must_use]
204199
#[inline]
205-
#[unstable(feature = "strict_provenance", issue = "95228")]
200+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
206201
pub fn with_addr(self, addr: usize) -> Self {
207-
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
208-
//
209-
// In the mean-time, this operation is defined to be "as if" it was
210-
// a wrapping_offset, so we can emulate it as such. This should properly
211-
// restore pointer provenance even under today's compiler.
202+
// This should probably be an intrinsic to avoid doing any sort of arithmetic, but
203+
// meanwhile, we can implement it with `wrapping_offset`, which preserves the pointer's
204+
// provenance.
212205
let self_addr = self.addr() as isize;
213206
let dest_addr = addr as isize;
214207
let offset = dest_addr.wrapping_sub(self_addr);
215-
216-
// This is the canonical desugaring of this operation
217208
self.wrapping_byte_offset(offset)
218209
}
219210

220-
/// Creates a new pointer by mapping `self`'s address to a new one.
211+
/// Creates a new pointer by mapping `self`'s address to a new one, preserving the original
212+
/// pointer's [provenance][crate::ptr#provenance].
221213
///
222214
/// This is a convenience for [`with_addr`][pointer::with_addr], see that method for details.
223215
///
224-
/// This API and its claimed semantics are part of the Strict Provenance experiment,
225-
/// see the [module documentation][crate::ptr] for details.
216+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
226217
#[must_use]
227218
#[inline]
228-
#[unstable(feature = "strict_provenance", issue = "95228")]
219+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
229220
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self {
230221
self.with_addr(f(self.addr()))
231222
}
@@ -376,7 +367,7 @@ impl<T: ?Sized> *mut T {
376367
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
377368
/// "wrapping around"), must fit in an `isize`.
378369
///
379-
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
370+
/// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
380371
/// [allocated object], and the entire memory range between `self` and the result must be in
381372
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
382373
/// of the address space.
@@ -777,7 +768,7 @@ impl<T: ?Sized> *mut T {
777768
/// * `self` and `origin` must either
778769
///
779770
/// * point to the same address, or
780-
/// * both be *derived from* a pointer to the same [allocated object], and the memory range between
771+
/// * both be [derived from][crate::ptr#provenance] a pointer to the same [allocated object], and the memory range between
781772
/// the two pointers must be in bounds of that object. (See below for an example.)
782773
///
783774
/// * The distance between the pointers, in bytes, must be an exact multiple
@@ -954,7 +945,7 @@ impl<T: ?Sized> *mut T {
954945
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
955946
/// "wrapping around"), must fit in an `isize`.
956947
///
957-
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
948+
/// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
958949
/// [allocated object], and the entire memory range between `self` and the result must be in
959950
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
960951
/// of the address space.
@@ -1061,7 +1052,7 @@ impl<T: ?Sized> *mut T {
10611052
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
10621053
/// "wrapping around"), must fit in an `isize`.
10631054
///
1064-
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
1055+
/// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
10651056
/// [allocated object], and the entire memory range between `self` and the result must be in
10661057
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
10671058
/// of the address space.

‎library/core/src/ptr/non_null.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,40 +283,39 @@ impl<T: ?Sized> NonNull<T> {
283283
///
284284
/// For more details see the equivalent method on a raw pointer, [`pointer::addr`].
285285
///
286-
/// This API and its claimed semantics are part of the Strict Provenance experiment,
287-
/// see the [`ptr` module documentation][crate::ptr].
286+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
288287
#[must_use]
289288
#[inline]
290-
#[unstable(feature = "strict_provenance", issue = "95228")]
289+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
291290
pub fn addr(self) -> NonZero<usize> {
292291
// SAFETY: The pointer is guaranteed by the type to be non-null,
293292
// meaning that the address will be non-zero.
294293
unsafe { NonZero::new_unchecked(self.pointer.addr()) }
295294
}
296295

297-
/// Creates a new pointer with the given address.
296+
/// Creates a new pointer with the given address and the [provenance][crate::ptr#provenance] of
297+
/// `self`.
298298
///
299299
/// For more details see the equivalent method on a raw pointer, [`pointer::with_addr`].
300300
///
301-
/// This API and its claimed semantics are part of the Strict Provenance experiment,
302-
/// see the [`ptr` module documentation][crate::ptr].
301+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
303302
#[must_use]
304303
#[inline]
305-
#[unstable(feature = "strict_provenance", issue = "95228")]
304+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
306305
pub fn with_addr(self, addr: NonZero<usize>) -> Self {
307306
// SAFETY: The result of `ptr::from::with_addr` is non-null because `addr` is guaranteed to be non-zero.
308307
unsafe { NonNull::new_unchecked(self.pointer.with_addr(addr.get()) as *mut _) }
309308
}
310309

311-
/// Creates a new pointer by mapping `self`'s address to a new one.
310+
/// Creates a new pointer by mapping `self`'s address to a new one, preserving the
311+
/// [provenance][crate::ptr#provenance] of `self`.
312312
///
313313
/// For more details see the equivalent method on a raw pointer, [`pointer::map_addr`].
314314
///
315-
/// This API and its claimed semantics are part of the Strict Provenance experiment,
316-
/// see the [`ptr` module documentation][crate::ptr].
315+
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
317316
#[must_use]
318317
#[inline]
319-
#[unstable(feature = "strict_provenance", issue = "95228")]
318+
#[stable(feature = "strict_provenance", since = "CURRENT_RUSTC_VERSION")]
320319
pub fn map_addr(self, f: impl FnOnce(NonZero<usize>) -> NonZero<usize>) -> Self {
321320
self.with_addr(f(self.addr()))
322321
}

0 commit comments

Comments
 (0)
Please sign in to comment.