Skip to content

Commit c4b6224

Browse files
committed
more type sanity checks in Miri
1 parent ad7179d commit c4b6224

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/librustc_mir/interpret/operand.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_target::abi::{Abi, DiscriminantKind, HasDataLayout, LayoutOf, Size};
1515
use rustc_target::abi::{VariantIdx, Variants};
1616

1717
use super::{
18-
from_known_layout, ConstValue, GlobalId, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace,
19-
Place, PlaceTy, Pointer, Scalar, ScalarMaybeUninit,
18+
from_known_layout, mir_assign_valid_types, ConstValue, GlobalId, InterpCx, InterpResult,
19+
MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUninit,
2020
};
2121

2222
/// An `Immediate` represents a single immediate self-contained Rust value.
@@ -469,6 +469,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
469469
.try_fold(base_op, |op, elem| self.operand_projection(op, elem))?;
470470

471471
trace!("eval_place_to_op: got {:?}", *op);
472+
// Sanity-check the type we ended up with.
473+
debug_assert!(mir_assign_valid_types(
474+
*self.tcx,
475+
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
476+
place.ty(&self.frame().body.local_decls, *self.tcx).ty
477+
))?,
478+
op.layout,
479+
));
472480
Ok(op)
473481
}
474482

src/librustc_mir/interpret/place.rs

+8
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,14 @@ where
638638
}
639639

640640
self.dump_place(place_ty.place);
641+
// Sanity-check the type we ended up with.
642+
debug_assert!(mir_assign_valid_types(
643+
*self.tcx,
644+
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
645+
place.ty(&self.frame().body.local_decls, *self.tcx).ty
646+
))?,
647+
place_ty.layout,
648+
));
641649
Ok(place_ty)
642650
}
643651

0 commit comments

Comments
 (0)