Skip to content

Commit 0e969b7

Browse files
committed
Interning even happens when validation of a constant fails
1 parent a0bd1a6 commit 0e969b7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/librustc_mir/interpret/intern.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,18 @@ 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-
// 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)?;
194+
// Validation has already errored on an invalid vtable pointer so we can safely not
195+
// do anything if this is not a real pointer
196+
if let Scalar::Ptr(vtable) = mplace.meta.unwrap() {
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)?;
200+
} else {
201+
self.ecx().tcx.sess.delay_span_bug(
202+
syntax_pos::DUMMY_SP,
203+
"vtables pointers cannot be integer pointers",
204+
);
205+
}
200206
}
201207
// Check if we have encountered this pointer+layout combination before.
202208
// Only recurse for allocation-backed pointers.

0 commit comments

Comments
 (0)