rust/compiler
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
..
rustc disable size asserts in the compiler when randomizing layouts 2024-08-31 23:56:45 +02:00
rustc_abi compiler: Reject impossible reprs during enum layout 2024-10-20 02:12:58 -07:00
rustc_arena move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
rustc_ast Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
rustc_ast_ir Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
rustc_ast_lowering Make sure that outer opaques capture inner opaques's lifetimes even with precise capturing syntax 2024-10-19 18:02:26 +00:00
rustc_ast_passes Auto merge of #130654 - lcnr:stabilize-coherence-again, r=compiler-errors 2024-10-15 14:21:34 +00:00
rustc_ast_pretty Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
rustc_attr Handle gracefully true/false in cfg(target(..)) compact 2024-10-16 09:41:49 +02:00
rustc_baked_icu_data Don't add warn(unreachable_pub) to rustc_baked_icu. 2024-08-16 08:46:52 +10:00
rustc_borrowck Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwU 2024-10-21 03:46:28 +00:00
rustc_builtin_macros Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
rustc_codegen_cranelift Fix tests 2024-10-19 18:07:35 +00:00
rustc_codegen_gcc Fix tests 2024-10-19 18:07:35 +00:00
rustc_codegen_llvm Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwU 2024-10-21 03:46:28 +00:00
rustc_codegen_ssa Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay 2024-10-21 18:11:19 +02:00
rustc_const_eval Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay 2024-10-21 18:11:19 +02:00
rustc_data_structures Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay 2024-10-21 18:11:19 +02:00
rustc_driver
rustc_driver_impl Rollup merge of #130899 - bjorn3:wasi_bootstrap_fixes, r=davidtwco 2024-10-07 11:10:53 -07:00
rustc_error_codes Fix typo in E0793 2024-10-09 10:28:16 -07:00
rustc_error_messages Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_errors Rollup merge of #131344 - nnethercote:ref-Lrc, r=compiler-errors 2024-10-07 12:23:54 +02:00
rustc_expand Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
rustc_feature Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay 2024-10-21 18:11:19 +02:00
rustc_fluent_macro use tracked_path in rustc_fluent_macro 2024-10-19 22:32:38 +08:00
rustc_fs_util Couple of changes to make it easier to compile rustc for wasm 2024-09-26 19:51:14 +00:00
rustc_graphviz Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_hir Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
rustc_hir_analysis Auto merge of #131988 - matthiaskrgr:rollup-tx173wn, r=matthiaskrgr 2024-10-21 06:13:34 +00:00
rustc_hir_pretty Move trait bound modifiers into hir::PolyTraitRef 2024-10-14 09:20:38 -04:00
rustc_hir_typeck Auto merge of #131988 - matthiaskrgr:rollup-tx173wn, r=matthiaskrgr 2024-10-21 06:13:34 +00:00
rustc_incremental Rename NestedMetaItem to MetaItemInner 2024-10-06 23:28:30 +09:00
rustc_index Rollup merge of #130625 - heiseish:issue-124028-fix, r=jieyouxu 2024-10-10 12:49:18 +02:00
rustc_index_macros Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_infer refactor fudge_inference, handle effect vars 2024-10-19 00:41:56 +02:00
rustc_interface stabilize -Znext-solver=coherence 2024-10-15 13:11:00 +02:00
rustc_lexer Reserve guarded string literals (RFC 3593) 2024-10-08 18:21:16 -06:00
rustc_lint Auto merge of #130628 - workingjubilee:clean-up-result-ffi-guarantees, r=RalfJung 2024-10-21 08:38:45 +00:00
rustc_lint_defs Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay 2024-10-21 18:11:19 +02:00
rustc_llvm Rollup merge of #131876 - workingjubilee:llvm-c-c-c-comdat, r=Zalathar 2024-10-20 14:06:03 +11:00
rustc_log Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_macros Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_metadata Remove outdated comment 2024-10-20 08:34:25 +00:00
rustc_middle Rollup merge of #130350 - RalfJung:strict-provenance, r=dtolnay 2024-10-21 18:11:19 +02:00
rustc_mir_build Rip out old effects var handling code from traits 2024-10-20 13:40:22 +00:00
rustc_mir_dataflow Get rid of const eval_* and try_eval_* helpers 2024-10-19 18:07:35 +00:00
rustc_mir_transform Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwU 2024-10-21 03:46:28 +00:00
rustc_monomorphize Add fast-path when computing the default visibility 2024-10-14 16:37:54 +02:00
rustc_next_trait_solver Fix transmute goal 2024-10-19 18:07:35 +00:00
rustc_parse Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr 2024-10-15 11:50:31 +00:00
rustc_parse_format Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_passes Auto merge of #131980 - matthiaskrgr:rollup-iy5nw71, r=matthiaskrgr 2024-10-20 21:40:21 +00:00
rustc_pattern_analysis Update rustc-hash to version 2 2024-10-20 00:12:49 -07:00
rustc_privacy Visit opaques for visibilities. 2024-10-04 23:31:55 +00:00
rustc_query_impl Handle rustc_query_impl cases of rustc::potential_query_instability lint 2024-10-03 12:47:08 +03:00
rustc_query_system add unstable support for outputting file checksums for use in cargo 2024-10-01 21:23:20 -06:00
rustc_resolve Stop relying on hashmap iteration for unused macro rules arms 2024-10-20 00:12:52 -07:00
rustc_sanitizers Get rid of const eval_* and try_eval_* helpers 2024-10-19 18:07:35 +00:00
rustc_serialize Fix explicit_iter_loop in rustc_serialize 2024-10-16 15:44:16 +02:00
rustc_session stabilize -Znext-solver=coherence 2024-10-15 13:11:00 +02:00
rustc_smir Get rid of const eval_* and try_eval_* helpers 2024-10-19 18:07:35 +00:00
rustc_span move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
rustc_symbol_mangling Rename normalize to normalize_internal, remove unnecessary usages 2024-10-19 18:07:35 +00:00
rustc_target Rollup merge of #131876 - workingjubilee:llvm-c-c-c-comdat, r=Zalathar 2024-10-20 14:06:03 +11:00
rustc_trait_selection Auto merge of #131988 - matthiaskrgr:rollup-tx173wn, r=matthiaskrgr 2024-10-21 06:13:34 +00:00
rustc_traits move defining_opaque_types out of Canonical 2024-10-17 10:22:52 +02:00
rustc_transmute Fix transmute goal 2024-10-19 18:07:35 +00:00
rustc_ty_utils Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwU 2024-10-21 03:46:28 +00:00
rustc_type_ir Remove the BoundConstness::NotConst variant 2024-10-20 18:33:59 +00:00
rustc_type_ir_macros Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
stable_mir Rollup merge of #131778 - practicalrs:fix_needless_lifetimes, r=jieyouxu 2024-10-16 20:15:56 +02:00