|
3 | 3 | //! After a const evaluation has computed a value, before we destroy the const evaluator's session
|
4 | 4 | //! memory, we need to extract all memory allocations to the global memory pool so they stay around.
|
5 | 5 |
|
6 |
| -use rustc::ty::layout::LayoutOf; |
7 | 6 | use rustc::ty::{Ty, TyCtxt, ParamEnv, self};
|
8 | 7 | use rustc::mir::interpret::{
|
9 | 8 | InterpResult, ErrorHandled,
|
@@ -143,21 +142,18 @@ for
|
143 | 142 | // Handle Reference types, as these are the only relocations supported by const eval.
|
144 | 143 | // Raw pointers (and boxes) are handled by the `leftover_relocations` logic.
|
145 | 144 | let ty = mplace.layout.ty;
|
146 |
| - if let ty::Ref(_, _, mutability) = ty.sty { |
| 145 | + if let ty::Ref(_, referenced_ty, mutability) = ty.sty { |
147 | 146 | let value = self.ecx.read_immediate(mplace.into())?;
|
148 | 147 | // Handle trait object vtables
|
149 | 148 | 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 { |
153 | 150 | if let Ok(vtable) = meta.unwrap().to_ptr() {
|
154 | 151 | // explitly choose `Immutable` here, since vtables are immutable, even
|
155 | 152 | // if the reference of the fat pointer is mutable
|
156 | 153 | self.intern_shallow(vtable, Mutability::Immutable)?;
|
157 | 154 | }
|
158 | 155 | }
|
159 | 156 | }
|
160 |
| - } |
161 | 157 | let mplace = self.ecx.ref_to_mplace(value)?;
|
162 | 158 | // Check if we have encountered this pointer+layout combination before.
|
163 | 159 | // Only recurse for allocation-backed pointers.
|
|
0 commit comments