Skip to content

Commit 80d592c

Browse files
authored
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](#122964 (comment)) `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.
2 parents bc8415b + 989660c commit 80d592c

File tree

49 files changed

+105
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+105
-99
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22612261
}
22622262
}
22632263

2264-
CastKind::PointerExposeAddress => {
2264+
CastKind::PointerExposeProvenance => {
22652265
let ty_from = op.ty(body, tcx);
22662266
let cast_ty_from = CastTy::from_ty(ty_from);
22672267
let cast_ty_to = CastTy::from_ty(*ty);
@@ -2271,7 +2271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22712271
span_mirbug!(
22722272
self,
22732273
rvalue,
2274-
"Invalid PointerExposeAddress cast {:?} -> {:?}",
2274+
"Invalid PointerExposeProvenance cast {:?} -> {:?}",
22752275
ty_from,
22762276
ty
22772277
)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ fn codegen_stmt<'tcx>(
649649
| CastKind::IntToFloat
650650
| CastKind::FnPtrToPtr
651651
| CastKind::PtrToPtr
652-
| CastKind::PointerExposeAddress
652+
| CastKind::PointerExposeProvenance
653653
| CastKind::PointerWithExposedProvenance,
654654
ref operand,
655655
to_ty,

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
965965
});
966966
}
967967

968-
sym::simd_expose_addr | sym::simd_with_exposed_provenance | sym::simd_cast_ptr => {
968+
sym::simd_expose_provenance | sym::simd_with_exposed_provenance | sym::simd_cast_ptr => {
969969
intrinsic_args!(fx, args => (arg); intrinsic);
970970
ret.write_cvalue_transmute(fx, arg);
971971
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
21112111
return Ok(args[0].immediate());
21122112
}
21132113

2114-
if name == sym::simd_expose_addr {
2114+
if name == sym::simd_expose_provenance {
21152115
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
21162116
require!(
21172117
in_len == out_len,

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
405405
let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty));
406406

407407
let val = match *kind {
408-
mir::CastKind::PointerExposeAddress => {
408+
mir::CastKind::PointerExposeProvenance => {
409409
assert!(bx.cx().is_backend_immediate(cast));
410410
let llptr = operand.immediate();
411411
let llcast_ty = bx.cx().immediate_backend_type(cast);

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3434
self.unsize_into(src, cast_layout, dest)?;
3535
}
3636

37-
CastKind::PointerExposeAddress => {
37+
CastKind::PointerExposeProvenance => {
3838
let src = self.read_immediate(src)?;
39-
let res = self.pointer_expose_address_cast(&src, cast_layout)?;
39+
let res = self.pointer_expose_provenance_cast(&src, cast_layout)?;
4040
self.write_immediate(*res, dest)?;
4141
}
4242

@@ -225,7 +225,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
225225
}
226226
}
227227

228-
pub fn pointer_expose_address_cast(
228+
pub fn pointer_expose_provenance_cast(
229229
&mut self,
230230
src: &ImmTy<'tcx, M::Provenance>,
231231
cast_to: TyAndLayout<'tcx>,

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
544544
// Unsizing is implemented for CTFE.
545545
}
546546

547-
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => {
547+
Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => {
548548
self.check_op(ops::RawPtrToIntCast);
549549
}
550550
Rvalue::Cast(CastKind::PointerWithExposedProvenance, _, _) => {

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10771077
}
10781078
// FIXME: Add Checks for these
10791079
CastKind::PointerWithExposedProvenance
1080-
| CastKind::PointerExposeAddress
1080+
| CastKind::PointerExposeProvenance
10811081
| CastKind::PointerCoercion(_) => {}
10821082
CastKind::IntToInt | CastKind::IntToFloat => {
10831083
let input_valid = op_ty.is_integral() || op_ty.is_char() || op_ty.is_bool();

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ pub fn check_intrinsic_type(
627627
sym::simd_cast
628628
| sym::simd_as
629629
| sym::simd_cast_ptr
630-
| sym::simd_expose_addr
630+
| sym::simd_expose_provenance
631631
| sym::simd_with_exposed_provenance => (2, 0, vec![param(0)], param(1)),
632632
sym::simd_bitmask => (2, 0, vec![param(0)], param(1)),
633633
sym::simd_select | sym::simd_select_bitmask => {

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ hir_typeck_lossy_provenance_int2ptr =
9191
hir_typeck_lossy_provenance_ptr2int =
9292
under strict provenance it is considered bad style to cast pointer `{$expr_ty}` to integer `{$cast_ty}`
9393
.suggestion = use `.addr()` to obtain the address of a pointer
94-
.help = if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_addr()` instead
94+
.help = if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_provenance()` instead
9595
9696
hir_typeck_method_call_on_unknown_raw_pointee =
9797
cannot call a method on a raw pointer with an unknown pointee type

0 commit comments

Comments
 (0)