rust/library/std/src
Matthias Krüger 20b1dadf92
Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay
stabilize Strict Provenance and Exposed Provenance APIs

Given that [RFC 3559](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html) has been accepted, t-lang has approved the concept of provenance to exist in the language. So I think it's time that we stabilize the strict provenance and exposed provenance APIs, and discuss provenance explicitly in the docs:
```rust
// core::ptr
pub const fn without_provenance<T>(addr: usize) -> *const T;
pub const fn dangling<T>() -> *const T;
pub const fn without_provenance_mut<T>(addr: usize) -> *mut T;
pub const fn dangling_mut<T>() -> *mut T;
pub fn with_exposed_provenance<T>(addr: usize) -> *const T;
pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T;

impl<T: ?Sized> *const T {
    pub fn addr(self) -> usize;
    pub fn expose_provenance(self) -> usize;
    pub fn with_addr(self, addr: usize) -> Self;
    pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self;
}

impl<T: ?Sized> *mut T {
    pub fn addr(self) -> usize;
    pub fn expose_provenance(self) -> usize;
    pub fn with_addr(self, addr: usize) -> Self;
    pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self;
}

impl<T: ?Sized> NonNull<T> {
    pub fn addr(self) -> NonZero<usize>;
    pub fn with_addr(self, addr: NonZero<usize>) -> Self;
    pub fn map_addr(self, f: impl FnOnce(NonZero<usize>) -> NonZero<usize>) -> Self;
}
```

I also did a pass over the docs to adjust them, because this is no longer an "experiment". The `ptr` docs now discuss the concept of provenance in general, and then they go into the two families of APIs for dealing with provenance: Strict Provenance and Exposed Provenance. I removed the discussion of how pointers also have an associated "address space" -- that is not actually tracked in the pointer value, it is tracked in the type, so IMO it just distracts from the core point of provenance. I also adjusted the docs for `with_exposed_provenance` to make it clear that we cannot guarantee much about this function, it's all best-effort.

There are two unstable lints associated with the strict_provenance feature gate; I moved them to a new [strict_provenance_lints](https://github.com/rust-lang/rust/issues/130351) feature since I didn't want this PR to have an even bigger FCP. ;)

`@rust-lang/opsem` Would be great to get some feedback on the docs here. :)
Nominating for `@rust-lang/libs-api.`

Part of https://github.com/rust-lang/rust/issues/95228.

[FCP comment](https://github.com/rust-lang/rust/pull/130350#issuecomment-2395114536)
2024-10-21 18:11:19 +02:00
..
backtrace remove redundant imports 2023-12-10 10:56:22 +08:00
collections replace placeholder version 2024-10-15 20:13:55 -07:00
env Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
error Reformat use declarations. 2024-07-29 08:26:52 +10:00
f16 std float tests: special-case Miri in feature detection 2024-08-08 12:17:50 +02:00
f32 these tests seem to work fine on i586 these days 2024-09-10 15:57:40 -07:00
f64 these tests seem to work fine on i586 these days 2024-09-10 15:57:40 -07:00
f128 Add core functions for f16 and f128 that require math routines 2024-08-01 15:38:53 -04:00
ffi Use &raw in the standard library 2024-09-25 17:03:20 -07:00
fs Use &raw in the standard library 2024-09-25 17:03:20 -07:00
hash std: implement the random feature 2024-09-23 10:29:51 +02:00
io replace placeholder version 2024-10-15 20:13:55 -07:00
net Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichton 2024-09-30 19:18:49 -04:00
num removed nonfunctioning benchmark 2024-01-11 11:30:12 -05:00
os Rollup merge of #131654 - betrusted-io:xous-various-fixes, r=thomcc 2024-10-18 06:59:05 +02:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
pipe Cleanup sys module to match house style 2024-07-30 19:22:54 +00:00
prelude Avoid comments that describe multiple use items. 2024-07-17 08:02:46 +10:00
process Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
sync mpmc doctest: make sure main thread waits for child threads 2024-10-02 08:00:17 +02:00
sys fix docs 2024-10-20 18:25:38 +03:00
sys_common std: replace LazyBox with OnceBox 2024-10-01 22:05:35 +02:00
thread std: fix stdout-before-main 2024-10-12 13:01:36 +02:00
time Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
alloc.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
ascii.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
backtrace.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
env.rs Rollup merge of #128535 - mmvanheusden:master, r=workingjubilee 2024-09-17 17:28:31 +02:00
error.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
f16.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
f32.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
f64.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
f128.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
fs.rs fix docs 2024-10-20 18:25:38 +03:00
keyword_docs.rs Update use keyword docs to describe precise capturing 2024-10-18 21:17:08 +00:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
macros.rs Add math functions for f16 and f128 2024-08-01 15:38:51 -04:00
num.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
panic.rs Auto merge of #128321 - BatmanAoD:catch-unwind-doc-update, r=Mark-Simulacrum 2024-09-29 05:54:47 +00:00
panicking.rs Rollup merge of #130846 - ChrisDenton:revert-break, r=Noratrieb 2024-09-26 22:20:54 -07:00
pat.rs Add pattern types to parser 2024-04-08 11:57:17 +00:00
path.rs Use &raw in the standard library 2024-09-25 17:03:20 -07:00
pipe.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
process.rs Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
random.rs Add entropy source for RTEMS 2024-10-18 10:26:59 +02:00
rt.rs std: fix stdout-before-main 2024-10-12 13:01:36 +02:00
time.rs [Clippy] Swap instant_subtraction to use diagnostic item instead of path 2024-09-19 13:13:42 +01:00