From 95b853cc74fc7a36dd92f163a8660ee6f1b6ff87 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 23 May 2020 17:54:26 +0200 Subject: [PATCH] more type sanity checks in Miri --- src/librustc_mir/interpret/operand.rs | 7 +++++++ src/librustc_mir/interpret/place.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index f546f6236d777..1283f55cb2d33 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -469,6 +469,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .try_fold(base_op, |op, elem| self.operand_projection(op, elem))?; trace!("eval_place_to_op: got {:?}", *op); + // Sanity-check the type we ended up with. + debug_assert_eq!( + self.subst_from_current_frame_and_normalize_erasing_regions( + place.ty(&self.frame().body.local_decls, *self.tcx).ty + ), + op.layout.ty, + ); Ok(op) } diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 6dadb8e4c67f4..6a64cd3ade8f3 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -638,6 +638,13 @@ where } self.dump_place(place_ty.place); + // Sanity-check the type we ended up with. + debug_assert_eq!( + self.subst_from_current_frame_and_normalize_erasing_regions( + place.ty(&self.frame().body.local_decls, *self.tcx).ty + ), + place_ty.layout.ty, + ); Ok(place_ty) }