Skip to content

Commit a77c209

Browse files
committed
strict provenance: rename addr → bare_addr
1 parent 3793e5b commit a77c209

File tree

61 files changed

+243
-225
lines changed

Some content is hidden

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

61 files changed

+243
-225
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<T> TypedArena<T> {
172172
fn can_allocate(&self, additional: usize) -> bool {
173173
// FIXME: this should *likely* use `offset_from`, but more
174174
// investigation is needed (including running tests in miri).
175-
let available_bytes = self.end.get().addr() - self.ptr.get().addr();
175+
let available_bytes = self.end.get().bare_addr() - self.ptr.get().bare_addr();
176176
let additional_bytes = additional.checked_mul(mem::size_of::<T>()).unwrap();
177177
available_bytes >= additional_bytes
178178
}
@@ -245,7 +245,7 @@ impl<T> TypedArena<T> {
245245
if mem::needs_drop::<T>() {
246246
// FIXME: this should *likely* use `offset_from`, but more
247247
// investigation is needed (including running tests in miri).
248-
let used_bytes = self.ptr.get().addr() - last_chunk.start().addr();
248+
let used_bytes = self.ptr.get().bare_addr() - last_chunk.start().bare_addr();
249249
last_chunk.entries = used_bytes / mem::size_of::<T>();
250250
}
251251

@@ -271,9 +271,9 @@ impl<T> TypedArena<T> {
271271
// chunks.
272272
fn clear_last_chunk(&self, last_chunk: &mut ArenaChunk<T>) {
273273
// Determine how much was filled.
274-
let start = last_chunk.start().addr();
274+
let start = last_chunk.start().bare_addr();
275275
// We obtain the value of the pointer to the first uninitialized element.
276-
let end = self.ptr.get().addr();
276+
let end = self.ptr.get().bare_addr();
277277
// We then calculate the number of elements to be dropped in the last chunk,
278278
// which is the filled area's length.
279279
let diff = if mem::size_of::<T>() == 0 {
@@ -396,11 +396,11 @@ impl DroplessArena {
396396
self.start.set(chunk.start());
397397

398398
// Align the end to DROPLESS_ALIGNMENT.
399-
let end = align_down(chunk.end().addr(), DROPLESS_ALIGNMENT);
399+
let end = align_down(chunk.end().bare_addr(), DROPLESS_ALIGNMENT);
400400

401401
// Make sure we don't go past `start`. This should not happen since the allocation
402402
// should be at least DROPLESS_ALIGNMENT - 1 bytes.
403-
debug_assert!(chunk.start().addr() <= end);
403+
debug_assert!(chunk.start().bare_addr() <= end);
404404

405405
self.end.set(chunk.end().with_addr(end));
406406

@@ -415,9 +415,9 @@ impl DroplessArena {
415415
// This loop executes once or twice: if allocation fails the first
416416
// time, the `grow` ensures it will succeed the second time.
417417
loop {
418-
let start = self.start.get().addr();
418+
let start = self.start.get().bare_addr();
419419
let old_end = self.end.get();
420-
let end = old_end.addr();
420+
let end = old_end.bare_addr();
421421

422422
// Align allocated bytes so that `self.end` stays aligned to
423423
// DROPLESS_ALIGNMENT.

compiler/rustc_codegen_ssa/src/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
138138
fn to_raw_string(&self) -> String {
139139
match *self {
140140
MonoItem::Fn(instance) => {
141-
format!("Fn({:?}, {})", instance.def, instance.args.as_ptr().addr())
141+
format!("Fn({:?}, {})", instance.def, instance.args.as_ptr().bare_addr())
142142
}
143143
MonoItem::Static(id) => format!("Static({id:?})"),
144144
MonoItem::GlobalAsm(id) => format!("GlobalAsm({id:?})"),

compiler/rustc_data_structures/src/tagged_ptr/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ where
104104
#[inline]
105105
pub fn tag(&self) -> T {
106106
// Unpack the tag, according to the `self.packed` encoding scheme
107-
let tag = self.packed.addr().get() >> Self::TAG_BIT_SHIFT;
107+
let tag = self.packed.bare_addr().get() >> Self::TAG_BIT_SHIFT;
108108

109109
// Safety:
110110
// The shift retrieves the original value from `T::into_usize`,

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ hir_typeck_lossy_provenance_int2ptr =
9090
9191
hir_typeck_lossy_provenance_ptr2int =
9292
under strict provenance it is considered bad style to cast pointer `{$expr_ty}` to integer `{$cast_ty}`
93-
.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
93+
.suggestion = use `.bare_addr()` to obtain the address of a pointer without its provenance -- but note that this cannot be cast back to a pointer later; you need to use `with_addr` instead
94+
.help = if you need to cast the address back to a pointer later, use `.expose_addr()` 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

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,28 +256,28 @@ pub enum LossyProvenancePtr2IntSuggestion<'tcx> {
256256
NeedsParensCast {
257257
#[suggestion_part(code = "(")]
258258
expr_span: Span,
259-
#[suggestion_part(code = ").addr() as {cast_ty}")]
259+
#[suggestion_part(code = ").bare_addr() as {cast_ty}")]
260260
cast_span: Span,
261261
cast_ty: Ty<'tcx>,
262262
},
263263
#[multipart_suggestion(hir_typeck_suggestion, applicability = "maybe-incorrect")]
264264
NeedsParens {
265265
#[suggestion_part(code = "(")]
266266
expr_span: Span,
267-
#[suggestion_part(code = ").addr()")]
267+
#[suggestion_part(code = ").bare_addr()")]
268268
cast_span: Span,
269269
},
270270
#[suggestion(
271271
hir_typeck_suggestion,
272-
code = ".addr() as {cast_ty}",
272+
code = ".bare_addr() as {cast_ty}",
273273
applicability = "maybe-incorrect"
274274
)]
275275
NeedsCast {
276276
#[primary_span]
277277
cast_span: Span,
278278
cast_ty: Ty<'tcx>,
279279
},
280-
#[suggestion(hir_typeck_suggestion, code = ".addr()", applicability = "maybe-incorrect")]
280+
#[suggestion(hir_typeck_suggestion, code = ".bare_addr()", applicability = "maybe-incorrect")]
281281
Other {
282282
#[primary_span]
283283
cast_span: Span,

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> GenericArg<'tcx> {
149149
// pointers were originally created from `Interned` types in `pack()`,
150150
// and this is just going in the other direction.
151151
unsafe {
152-
match self.ptr.addr().get() & TAG_MASK {
152+
match self.ptr.bare_addr().get() & TAG_MASK {
153153
REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked(
154154
ptr.cast::<ty::RegionKind<'tcx>>().as_ref(),
155155
))),

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ impl<'tcx> Term<'tcx> {
624624
// pointers were originally created from `Interned` types in `pack()`,
625625
// and this is just going in the other direction.
626626
unsafe {
627-
match self.ptr.addr().get() & TAG_MASK {
627+
match self.ptr.bare_addr().get() & TAG_MASK {
628628
TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked(
629629
ptr.cast::<WithCachedTypeInfo<ty::TyKind<'tcx>>>().as_ref(),
630630
))),

library/alloc/src/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@ impl<T, A: Allocator> Weak<T, A> {
28402840
}
28412841

28422842
pub(crate) fn is_dangling<T: ?Sized>(ptr: *const T) -> bool {
2843-
(ptr.cast::<()>()).addr() == usize::MAX
2843+
(ptr.cast::<()>()).bare_addr() == usize::MAX
28442844
}
28452845

28462846
/// Helper type to allow accessing the reference counts without

library/alloc/src/vec/into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
222222
#[inline]
223223
fn size_hint(&self) -> (usize, Option<usize>) {
224224
let exact = if T::IS_ZST {
225-
self.end.addr().wrapping_sub(self.ptr.as_ptr().addr())
225+
self.end.bare_addr().wrapping_sub(self.ptr.as_ptr().bare_addr())
226226
} else {
227227
unsafe { non_null!(self.end, T).sub_ptr(self.ptr) }
228228
};

library/core/src/hash/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ mod impls {
956956
#[inline]
957957
fn hash<H: Hasher>(&self, state: &mut H) {
958958
let (address, metadata) = self.to_raw_parts();
959-
state.write_usize(address.addr());
959+
state.write_usize(address.bare_addr());
960960
metadata.hash(state);
961961
}
962962
}
@@ -966,7 +966,7 @@ mod impls {
966966
#[inline]
967967
fn hash<H: Hasher>(&self, state: &mut H) {
968968
let (address, metadata) = self.to_raw_parts();
969-
state.write_usize(address.addr());
969+
state.write_usize(address.bare_addr());
970970
metadata.hash(state);
971971
}
972972
}

0 commit comments

Comments
 (0)