Skip to content

Commit cc5cc67

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

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
@@ -367,8 +367,9 @@ impl<'tcx, Tag> Scalar<Tag> {
367367
}
368368

369369
/// Do not call this method! Use either `assert_ptr` or `force_ptr`.
370+
/// This method is intentionally private, do not make it public.
370371
#[inline]
371-
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
372+
fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
372373
match self {
373374
Scalar::Raw { data: 0, .. } => throw_unsup!(InvalidNullPointerUsage),
374375
Scalar::Raw { .. } => throw_unsup!(ReadBytesAsPointer),
@@ -544,12 +545,6 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
544545
}
545546
}
546547

547-
/// Do not call this method! Use either `assert_ptr` or `force_ptr`.
548-
#[inline(always)]
549-
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
550-
self.not_undef()?.to_ptr()
551-
}
552-
553548
/// Do not call this method! Use either `assert_bits` or `force_bits`.
554549
#[inline(always)]
555550
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
@@ -537,8 +537,8 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
537537
Ok(ConstValue::Scalar(a_val))
538538
} else if let ty::FnPtr(_) = a.ty.kind {
539539
let alloc_map = tcx.alloc_map.lock();
540-
let a_instance = alloc_map.unwrap_fn(a_val.to_ptr().unwrap().alloc_id);
541-
let b_instance = alloc_map.unwrap_fn(b_val.to_ptr().unwrap().alloc_id);
540+
let a_instance = alloc_map.unwrap_fn(a_val.assert_ptr().alloc_id);
541+
let b_instance = alloc_map.unwrap_fn(b_val.assert_ptr().alloc_id);
542542
if a_instance == b_instance {
543543
Ok(ConstValue::Scalar(a_val))
544544
} 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
@@ -743,7 +743,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
743743
// FIXME: should we tell the user that there was a local which was never written to?
744744
if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
745745
trace!("deallocating local");
746-
let ptr = ptr.to_ptr()?;
746+
// All locals have a backing allocation, even if the allocation is empty
747+
// due to the local having ZST type.
748+
let ptr = ptr.assert_ptr();
747749
if log_enabled!(::log::Level::Trace) {
748750
self.memory.dump_alloc(ptr.alloc_id);
749751
}

src/librustc_mir/interpret/intern.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx
192192
if let ty::Dynamic(..) =
193193
self.ecx.tcx.struct_tail_erasing_lifetimes(referenced_ty, self.ecx.param_env).kind
194194
{
195-
if let Ok(vtable) = mplace.meta.unwrap().to_ptr() {
196-
// explitly choose `Immutable` here, since vtables are immutable, even
197-
// if the reference of the fat pointer is mutable
198-
self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?;
199-
}
195+
// Validation has already errored on an invalid vtable pointer so this `assert_ptr`
196+
// will never panic.
197+
let vtable = mplace.meta.unwrap().assert_ptr();
198+
// explitly choose `Immutable` here, since vtables are immutable, even
199+
// if the reference of the fat pointer is mutable
200+
self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?;
200201
}
201202
// Check if we have encountered this pointer+layout combination before.
202203
// Only recurse for allocation-backed pointers.
@@ -281,7 +282,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
281282
ecx,
282283
leftover_allocations,
283284
base_intern_mode,
284-
ret.ptr.to_ptr()?.alloc_id,
285+
// The outermost allocation must exist, because we allocated it with
286+
// `Memory::allocate`.
287+
ret.ptr.assert_ptr().alloc_id,
285288
base_mutability,
286289
Some(ret.layout.ty),
287290
)?;

0 commit comments

Comments
 (0)