diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 31ee3e6519afc..b96643ea70f2e 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -118,6 +118,7 @@ impl Immediate { (Immediate::Scalar(scalar), Abi::Scalar(s)) => { assert_eq!(scalar.size(), s.size(cx)); if !matches!(s.primitive(), abi::Pointer(..)) { + // This is not a pointer, it should not carry provenance. assert!(matches!(scalar, Scalar::Int(..))); } } diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 32f90254a9470..64c5ad8bb143f 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -651,10 +651,10 @@ where if !self.validation_in_progress() { M::after_local_write(self, local, /*storage_live*/ false)?; } - // Double-check that the value we are storing and the local fit to each other. - if cfg!(debug_assertions) { - src.assert_matches_abi(local_layout.abi, self); - } + // Double-check that the value we are storing and the local fit to each other. We do + // this even with debug assertions as interpreter behavior can get really strange + // when this is violated. + src.assert_matches_abi(local_layout.abi, self); } Left(mplace) => { self.write_immediate_to_mplace_no_validate(src, mplace.layout, mplace.mplace)?; @@ -672,6 +672,7 @@ where layout: TyAndLayout<'tcx>, dest: MemPlace, ) -> InterpResult<'tcx> { + // Ensure the value matches the type of the place it is written to. if cfg!(debug_assertions) { value.assert_matches_abi(layout.abi, self); }