Skip to content

Commit 354163d

Browse files
committed
Simplify vtable interning
1 parent 166c49d commit 354163d

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/librustc_mir/interpret/intern.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! After a const evaluation has computed a value, before we destroy the const evaluator's session
44
//! memory, we need to extract all memory allocations to the global memory pool so they stay around.
55
6-
use rustc::ty::layout::LayoutOf;
76
use rustc::ty::{Ty, TyCtxt, ParamEnv, self};
87
use rustc::mir::interpret::{
98
InterpResult, ErrorHandled,
@@ -143,21 +142,18 @@ for
143142
// Handle Reference types, as these are the only relocations supported by const eval.
144143
// Raw pointers (and boxes) are handled by the `leftover_relocations` logic.
145144
let ty = mplace.layout.ty;
146-
if let ty::Ref(_, _, mutability) = ty.sty {
145+
if let ty::Ref(_, referenced_ty, mutability) = ty.sty {
147146
let value = self.ecx.read_immediate(mplace.into())?;
148147
// Handle trait object vtables
149148
if let Ok(meta) = value.to_meta() {
150-
let layout = self.ecx.layout_of(ty.builtin_deref(true).unwrap().ty)?;
151-
if layout.is_unsized() {
152-
if let ty::Dynamic(..) = self.ecx.tcx.struct_tail(layout.ty).sty {
149+
if let ty::Dynamic(..) = self.ecx.tcx.struct_tail(referenced_ty).sty {
153150
if let Ok(vtable) = meta.unwrap().to_ptr() {
154151
// explitly choose `Immutable` here, since vtables are immutable, even
155152
// if the reference of the fat pointer is mutable
156153
self.intern_shallow(vtable, Mutability::Immutable)?;
157154
}
158155
}
159156
}
160-
}
161157
let mplace = self.ecx.ref_to_mplace(value)?;
162158
// Check if we have encountered this pointer+layout combination before.
163159
// Only recurse for allocation-backed pointers.

src/test/ui/consts/miri_unleashed/mutable_references_ice.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// rustc-env:RUST_BACKTRACE=0
44
// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET"
55
// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS"
6+
// normalize-stderr-test "src/librustc_mir/interpret/intern.rs:[0-9]*:[0-9]*" -> "src/librustc_mir/interpret/intern.rs:LL:CC"
67

78
#![allow(const_err)]
89

src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
warning: skipping const checks
2-
--> $DIR/mutable_references_ice.rs:26:9
2+
--> $DIR/mutable_references_ice.rs:27:9
33
|
44
LL | *MUH.x.get() = 99;
55
| ^^^^^^^^^^^^^^^^^
66

77
thread 'rustc' panicked at 'assertion failed: `(left != right)`
88
left: `Const`,
9-
right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites may arbitrarily decide to change, too.', src/librustc_mir/interpret/intern.rs:127:17
9+
right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites may arbitrarily decide to change, too.', src/librustc_mir/interpret/intern.rs:LL:CC
1010
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
1111

1212
error: internal compiler error: unexpected panic

0 commit comments

Comments
 (0)