Skip to content

Commit 5c6b7ac

Browse files
authored
Rollup merge of rust-lang#61404 - RalfJung:miri-unsize, r=oli-obk
miri unsizing: fix projecting into a field of an operand I don't know why this open-coded an operand field projection. Probably this code predates one or more of my refactorings. Fixes rust-lang/miri#754 r? @oli-obk
2 parents b920f1d + f23cbea commit 5c6b7ac

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

src/librustc_mir/interpret/cast.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::mir::interpret::{
1111
use rustc::mir::CastKind;
1212
use rustc_apfloat::Float;
1313

14-
use super::{InterpretCx, Machine, PlaceTy, OpTy, ImmTy, Immediate};
14+
use super::{InterpretCx, Machine, PlaceTy, OpTy, Immediate};
1515

1616
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> {
1717
fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool {
@@ -306,6 +306,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
306306
src: OpTy<'tcx, M::PointerTag>,
307307
dest: PlaceTy<'tcx, M::PointerTag>,
308308
) -> EvalResult<'tcx> {
309+
trace!("Unsizing {:?} into {:?}", src, dest);
309310
match (&src.layout.ty.sty, &dest.layout.ty.sty) {
310311
(&ty::Ref(_, s, _), &ty::Ref(_, d, _)) |
311312
(&ty::Ref(_, s, _), &ty::RawPtr(TypeAndMut { ty: d, .. })) |
@@ -335,20 +336,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
335336
if dst_field.layout.is_zst() {
336337
continue;
337338
}
338-
let src_field = match src.try_as_mplace() {
339-
Ok(mplace) => {
340-
let src_field = self.mplace_field(mplace, i as u64)?;
341-
src_field.into()
342-
}
343-
Err(..) => {
344-
let src_field_layout = src.layout.field(self, i)?;
345-
// this must be a field covering the entire thing
346-
assert_eq!(src.layout.fields.offset(i).bytes(), 0);
347-
assert_eq!(src_field_layout.size, src.layout.size);
348-
// just sawp out the layout
349-
OpTy::from(ImmTy { imm: src.to_immediate(), layout: src_field_layout })
350-
}
351-
};
339+
let src_field = self.operand_field(src, i as u64)?;
352340
if src_field.layout.ty == dst_field.layout.ty {
353341
self.copy_op(src_field, dst_field)?;
354342
} else {

0 commit comments

Comments
 (0)