Skip to content

Commit 6415539

Browse files
committed
Retire to_ptr which should already have no users but still kept getting new ones
1 parent a247b06 commit 6415539

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/librustc/mir/interpret/value.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ impl<'tcx, Tag> Scalar<Tag> {
339339
}
340340

341341
/// Do not call this method! Use either `assert_ptr` or `force_ptr`.
342+
/// This method is intentionally private, do not make it public.
342343
#[inline]
343-
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
344+
fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
344345
match self {
345346
Scalar::Raw { data: 0, .. } => throw_unsup!(InvalidNullPointerUsage),
346347
Scalar::Raw { .. } => throw_unsup!(ReadBytesAsPointer),
@@ -517,12 +518,6 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
517518
}
518519
}
519520

520-
/// Do not call this method! Use either `assert_ptr` or `force_ptr`.
521-
#[inline(always)]
522-
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
523-
self.not_undef()?.to_ptr()
524-
}
525-
526521
/// Do not call this method! Use either `assert_bits` or `force_bits`.
527522
#[inline(always)]
528523
pub fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {

src/librustc/ty/relate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
572572
Ok(ConstValue::Scalar(a_val))
573573
} else if let ty::FnPtr(_) = a.ty.kind {
574574
let alloc_map = tcx.alloc_map.lock();
575-
let a_instance = alloc_map.unwrap_fn(a_val.to_ptr().unwrap().alloc_id);
576-
let b_instance = alloc_map.unwrap_fn(b_val.to_ptr().unwrap().alloc_id);
575+
let a_instance = alloc_map.unwrap_fn(a_val.assert_ptr().alloc_id);
576+
let b_instance = alloc_map.unwrap_fn(b_val.assert_ptr().alloc_id);
577577
if a_instance == b_instance {
578578
Ok(ConstValue::Scalar(a_val))
579579
} else {

src/librustc_mir/const_eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn op_to_const<'tcx>(
8585
};
8686
let val = match immediate {
8787
Ok(mplace) => {
88-
let ptr = mplace.ptr.to_ptr().unwrap();
88+
let ptr = mplace.ptr.assert_ptr();
8989
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
9090
ConstValue::ByRef { alloc, offset: ptr.offset }
9191
},
@@ -99,7 +99,7 @@ fn op_to_const<'tcx>(
9999
// comes from a constant so it can happen have `Undef`, because the indirect
100100
// memory that was read had undefined bytes.
101101
let mplace = op.assert_mem_place();
102-
let ptr = mplace.ptr.to_ptr().unwrap();
102+
let ptr = mplace.ptr.assert_ptr();
103103
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
104104
ConstValue::ByRef { alloc, offset: ptr.offset }
105105
},
@@ -626,7 +626,7 @@ fn validate_and_turn_into_const<'tcx>(
626626
// whether they become immediates.
627627
let def_id = cid.instance.def.def_id();
628628
if tcx.is_static(def_id) || cid.promoted.is_some() {
629-
let ptr = mplace.ptr.to_ptr()?;
629+
let ptr = mplace.ptr.assert_ptr();
630630
Ok(tcx.mk_const(ty::Const {
631631
val: ty::ConstKind::Value(ConstValue::ByRef {
632632
alloc: ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id),

src/librustc_mir/interpret/eval_context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
752752
// FIXME: should we tell the user that there was a local which was never written to?
753753
if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
754754
trace!("deallocating local");
755-
let ptr = ptr.to_ptr()?;
755+
// All locals have a backing allocation, even if the allocation is empty
756+
// due to the local having ZST type.
757+
let ptr = ptr.assert_ptr();
756758
if log_enabled!(::log::Level::Trace) {
757759
self.memory.dump_alloc(ptr.alloc_id);
758760
}

src/librustc_mir/interpret/intern.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ for
207207
self.ecx.tcx.struct_tail_erasing_lifetimes(
208208
referenced_ty, self.ecx.param_env).kind
209209
{
210-
if let Ok(vtable) = mplace.meta.unwrap().to_ptr() {
211-
// explitly choose `Immutable` here, since vtables are immutable, even
212-
// if the reference of the fat pointer is mutable
213-
self.intern_shallow(vtable.alloc_id, Mutability::Immutable, None)?;
214-
}
210+
// Validation has already errored on an invalid vtable pointer so this `assert_ptr`
211+
// will never panic.
212+
let vtable = mplace.meta.unwrap().assert_ptr();
213+
// explitly choose `Immutable` here, since vtables are immutable, even
214+
// if the reference of the fat pointer is mutable
215+
self.intern_shallow(vtable.alloc_id, Mutability::Immutable, None)?;
215216
}
216217
// Check if we have encountered this pointer+layout combination before.
217218
// Only recurse for allocation-backed pointers.
@@ -302,7 +303,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
302303
ecx,
303304
leftover_allocations,
304305
base_intern_mode,
305-
ret.ptr.to_ptr()?.alloc_id,
306+
// The outermost allocation must exist, because we allocated it with
307+
// `Memory::allocate`.
308+
ret.ptr.assert_ptr().alloc_id,
306309
base_mutability,
307310
Some(ret.layout.ty)
308311
)?;

0 commit comments

Comments
 (0)