rust/compiler/rustc_codegen_ssa/src/mir
Matthias Krüger 80d592cc24
Rollup merge of #122964 - joboet:pointer_expose, r=Amanieu
Rename `expose_addr` to `expose_provenance`

`expose_addr` is a bad name, an address is just a number and cannot be exposed. The operation is actually about the provenance of the pointer.

This PR thus changes the name of the method to `expose_provenance` without changing its return type. There is sufficient precedence for returning a useful value from an operation that does something else without the name indicating such, e.g. [`Option::insert`](https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.insert) and [`MaybeUninit::write`](https://doc.rust-lang.org/nightly/std/mem/union.MaybeUninit.html#method.write).

Returning the address is merely convenient, not a fundamental part of the operation. This is implied by the fact that integers do not have provenance since
```rust
let addr = ptr.addr();
ptr.expose_provenance();
let new = ptr::with_exposed_provenance(addr);
```
must behave exactly like
```rust
let addr = ptr.expose_provenance();
let new = ptr::with_exposed_provenance(addr);
```
as the result of `ptr.expose_provenance()` and `ptr.addr()` is the same integer. Therefore, this PR removes the `#[must_use]` annotation on the function and updates the documentation to reflect the important part.

~~An alternative name would be `expose_provenance`. I'm not at all opposed to that, but it makes a stronger implication than we might want that the provenance of the pointer returned by `ptr::with_exposed_provenance`[^1] is the same as that what was exposed, which is not yet specified as such IIUC. IMHO `expose` does not make that connection.~~

A previous version of this PR suggested `expose` as name, libs-api [decided on](https://github.com/rust-lang/rust/pull/122964#issuecomment-2033194319) `expose_provenance` to keep the symmetry with `with_exposed_provenance`.

CC `@RalfJung`
r? libs-api

[^1]: I'm using the new name for `from_exposed_addr` suggested by #122935 here.
2024-04-03 22:11:00 +02:00
..
analyze.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
block.rs Rollup merge of #122619 - erikdesjardins:cast, r=compiler-errors 2024-04-03 22:11:00 +02:00
constant.rs Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
coverageinfo.rs Unbox and unwrap the contents of StatementKind::Coverage 2024-03-23 22:05:11 +11:00
debuginfo.rs Eagerly convert some ctors to use their specialized ctors 2024-03-22 11:12:01 -04:00
intrinsic.rs Auto merge of #122582 - scottmcm:swap-intrinsic-v2, r=oli-obk 2024-03-23 13:57:55 +00:00
locals.rs Implement async gen blocks 2023-12-08 17:23:25 +00:00
mod.rs Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiser 2024-03-14 20:00:18 +01:00
operand.rs only set noalias on Box with the global allocator 2024-03-05 15:03:33 +01:00
place.rs use GEP inbounds for ZST and DST field offsets 2024-03-04 09:32:33 -05:00
rvalue.rs rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
statement.rs Unbox and unwrap the contents of StatementKind::Coverage 2024-03-23 22:05:11 +11:00