Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ea31f83

Browse files
authoredFeb 14, 2023
Rollup merge of #108044 - RalfJung:from-addr-invalid, r=oli-obk
interpret: rename Pointer::from_addr → from_addr_invalid This function corresponds to `ptr::invalid` in the standard library; the previous name was not clear enough IMO.
2 parents 5aaaac8 + 91d2516 commit ea31f83

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed
 

‎compiler/rustc_const_eval/src/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
517517
// Allow these casts, but make the pointer not dereferenceable.
518518
// (I.e., they behave like transmutation.)
519519
// This is correct because no pointers can ever be exposed in compile-time evaluation.
520-
Ok(Pointer::from_addr(addr))
520+
Ok(Pointer::from_addr_invalid(addr))
521521
}
522522

523523
#[inline(always)]

‎compiler/rustc_const_eval/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'tcx, Prov: Provenance> MPlaceTy<'tcx, Prov> {
178178
pub fn fake_alloc_zst(layout: TyAndLayout<'tcx>) -> Self {
179179
assert!(layout.is_zst());
180180
let align = layout.align.abi;
181-
let ptr = Pointer::from_addr(align.bytes()); // no provenance, absolute address
181+
let ptr = Pointer::from_addr_invalid(align.bytes()); // no provenance, absolute address
182182
MPlaceTy { mplace: MemPlace { ptr, meta: MemPlaceMeta::None }, layout, align }
183183
}
184184

‎compiler/rustc_middle/src/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl fmt::Display for UndefinedBehaviorInfo {
323323
write!(
324324
f,
325325
"{msg}{pointer} is a dangling pointer (it has no provenance)",
326-
pointer = Pointer::<Option<AllocId>>::from_addr(*i),
326+
pointer = Pointer::<Option<AllocId>>::from_addr_invalid(*i),
327327
)
328328
}
329329
AlignmentCheckFailed { required, has } => write!(

‎compiler/rustc_middle/src/mir/interpret/pointer.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,16 @@ impl<Prov> Pointer<Option<Prov>> {
251251
}
252252

253253
impl<Prov> Pointer<Option<Prov>> {
254+
/// Creates a pointer to the given address, with invalid provenance (i.e., cannot be used for
255+
/// any memory access).
254256
#[inline(always)]
255-
pub fn from_addr(addr: u64) -> Self {
257+
pub fn from_addr_invalid(addr: u64) -> Self {
256258
Pointer { provenance: None, offset: Size::from_bytes(addr) }
257259
}
258260

259261
#[inline(always)]
260262
pub fn null() -> Self {
261-
Pointer::from_addr(0)
263+
Pointer::from_addr_invalid(0)
262264
}
263265
}
264266

‎compiler/rustc_middle/src/mir/interpret/value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
322322
Right(ptr) => Ok(ptr.into()),
323323
Left(bits) => {
324324
let addr = u64::try_from(bits).unwrap();
325-
Ok(Pointer::from_addr(addr))
325+
Ok(Pointer::from_addr_invalid(addr))
326326
}
327327
}
328328
}

0 commit comments

Comments
 (0)
Please sign in to comment.