Commit 20b1dad
authored
Rollup merge of rust-lang#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](rust-lang#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 rust-lang#95228.
[FCP comment](rust-lang#130350 (comment))File tree
90 files changed
+352
-514
lines changed- compiler
- rustc_arena/src
- rustc_codegen_ssa/src
- mir
- rustc_const_eval/src
- rustc_data_structures/src
- rustc_feature/src
- rustc_lint_defs/src
- rustc_middle/src
- rustc_span/src
- library
- alloc
- benches
- src
- tests
- core
- src
- ptr
- sync
- tests
- panic_unwind/src
- portable-simd/crates/core_simd
- src
- tests
- proc_macro/src
- std/src
- unwind/src
- src
- doc/unstable-book/src/language-features
- tools/miri
- src
- tests
- fail
- dangling_pointers
- intrinsics
- provenance
- stacked_borrows
- unaligned_pointers
- uninit
- pass-dep/libc
- pass
- concurrency
- shims
- stacked-borrows
- tests
- codegen
- issues
- mir-opt
- ui
- codegen/equal-pointers-unequal
- exposed-provenance
- strict-provenance
- feature-gates
- lint
- mir/alignment
- structs-enums
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
90 files changed
+352
-514
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
364 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
365 | 368 | | |
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
369 | 372 | | |
| 373 | + | |
370 | 374 | | |
371 | 375 | | |
372 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
598 | | - | |
| 598 | + | |
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2667 | 2667 | | |
2668 | 2668 | | |
2669 | 2669 | | |
2670 | | - | |
2671 | 2670 | | |
2672 | 2671 | | |
2673 | 2672 | | |
| |||
2701 | 2700 | | |
2702 | 2701 | | |
2703 | 2702 | | |
2704 | | - | |
| 2703 | + | |
2705 | 2704 | | |
2706 | 2705 | | |
2707 | 2706 | | |
| |||
2711 | 2710 | | |
2712 | 2711 | | |
2713 | 2712 | | |
2714 | | - | |
2715 | 2713 | | |
2716 | 2714 | | |
2717 | 2715 | | |
| |||
2747 | 2745 | | |
2748 | 2746 | | |
2749 | 2747 | | |
2750 | | - | |
| 2748 | + | |
2751 | 2749 | | |
2752 | 2750 | | |
2753 | 2751 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1913 | 1913 | | |
1914 | 1914 | | |
1915 | 1915 | | |
1916 | | - | |
| 1916 | + | |
1917 | 1917 | | |
1918 | 1918 | | |
1919 | 1919 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
0 commit comments