From: Oliver Scherer Date: Sat, 14 Dec 2019 11:15:37 +0000 (+0100) Subject: Interning even happens when validation of a constant fails X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=0e969b73f6f633187a829111d3e80423e85fd513;p=rust.git Interning even happens when validation of a constant fails --- diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index aaeff02fc05..2d66fb46311 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -191,12 +191,18 @@ fn visit_primitive(&mut self, mplace: MPlaceTy<'tcx>) -> InterpResult<'tcx> { if let ty::Dynamic(..) = self.ecx.tcx.struct_tail_erasing_lifetimes(referenced_ty, self.ecx.param_env).kind { - // Validation has already errored on an invalid vtable pointer so this `assert_ptr` - // will never panic. - let vtable = mplace.meta.unwrap().assert_ptr(); - // explitly choose `Immutable` here, since vtables are immutable, even - // if the reference of the fat pointer is mutable - self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?; + // Validation has already errored on an invalid vtable pointer so we can safely not + // do anything if this is not a real pointer + if let Scalar::Ptr(vtable) = mplace.meta.unwrap() { + // explitly choose `Immutable` here, since vtables are immutable, even + // if the reference of the fat pointer is mutable + self.intern_shallow(vtable.alloc_id, Mutability::Not, None)?; + } else { + self.ecx().tcx.sess.delay_span_bug( + syntax_pos::DUMMY_SP, + "vtables pointers cannot be integer pointers", + ); + } } // Check if we have encountered this pointer+layout combination before. // Only recurse for allocation-backed pointers.