]> git.lizzy.rs Git - rust.git/commitdiff
Interning even happens when validation of a constant fails
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Sat, 14 Dec 2019 11:15:37 +0000 (12:15 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 26 Dec 2019 21:50:17 +0000 (22:50 +0100)
src/librustc_mir/interpret/intern.rs

index aaeff02fc052a1481237a7b1c90451b221e779b0..2d66fb463115cd084535b4dc01c6a23db4af0d1c 100644 (file)
@@ -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.