Skip to content

Commit b5b5258

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

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/eval_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub(super) fn op_to_const<'tcx>(
119119
};
120120
let val = match immediate {
121121
Ok(mplace) => {
122-
let ptr = mplace.ptr.to_ptr().unwrap();
122+
let ptr = mplace.ptr.assert_ptr();
123123
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
124124
ConstValue::ByRef { alloc, offset: ptr.offset }
125125
}
@@ -133,7 +133,7 @@ pub(super) fn op_to_const<'tcx>(
133133
// comes from a constant so it can happen have `Undef`, because the indirect
134134
// memory that was read had undefined bytes.
135135
let mplace = op.assert_mem_place();
136-
let ptr = mplace.ptr.to_ptr().unwrap();
136+
let ptr = mplace.ptr.assert_ptr();
137137
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
138138
ConstValue::ByRef { alloc, offset: ptr.offset }
139139
}
@@ -176,7 +176,7 @@ fn validate_and_turn_into_const<'tcx>(
176176
// Statics/promoteds are always `ByRef`, for the rest `op_to_const` decides
177177
// whether they become immediates.
178178
if is_static || cid.promoted.is_some() {
179-
let ptr = mplace.ptr.to_ptr()?;
179+
let ptr = mplace.ptr.assert_ptr();
180180
Ok(tcx.mk_const(ty::Const {
181181
val: ty::ConstKind::Value(ConstValue::ByRef {
182182
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
@@ -191,11 +191,12 @@ impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx
191191
if let ty::Dynamic(..) =
192192
self.ecx.tcx.struct_tail_erasing_lifetimes(referenced_ty, self.ecx.param_env).kind
193193
{
194-
if let Ok(vtable) = mplace.meta.unwrap().to_ptr() {
195-
// explitly choose `Immutable` here, since vtables are immutable, even
196-
// if the reference of the fat pointer is mutable
197-
self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?;
198-
}
194+
// Validation has already errored on an invalid vtable pointer so this `assert_ptr`
195+
// will never panic.
196+
let vtable = mplace.meta.unwrap().assert_ptr();
197+
// explitly choose `Immutable` here, since vtables are immutable, even
198+
// if the reference of the fat pointer is mutable
199+
self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?;
199200
}
200201
// Check if we have encountered this pointer+layout combination before.
201202
// Only recurse for allocation-backed pointers.
@@ -280,7 +281,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
280281
ecx,
281282
leftover_allocations,
282283
base_intern_mode,
283-
ret.ptr.to_ptr()?.alloc_id,
284+
// The outermost allocation must exist, because we allocated it with
285+
// `Memory::allocate`.
286+
ret.ptr.assert_ptr().alloc_id,
284287
base_mutability,
285288
Some(ret.layout.ty),
286289
)?;

0 commit comments

Comments
 (0)