Skip to content

Commit 68ecc21

Browse files
committed
Interning even happens when validation of a constant fails
1 parent 6976435 commit 68ecc21

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

0 commit comments

Comments
 (0)