From 4aecee5dc097784a51634b19df7b37514476234c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 25 Jun 2022 19:26:08 -0400 Subject: [PATCH] reject deref'ing Box deeper in const-eval interpreter --- compiler/rustc_const_eval/src/interpret/place.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 3dbcba72baf3..8cc35f799aae 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -286,6 +286,9 @@ where ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { let pointee_type = val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type").ty; + if val.layout.ty.is_box() { + bug!("dereferencing {:?}", val.layout.ty); + } let layout = self.layout_of(pointee_type)?; let (ptr, meta) = match **val { Immediate::Scalar(ptr) => (ptr, MemPlaceMeta::None), @@ -313,11 +316,6 @@ where ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { let val = self.read_immediate(src)?; trace!("deref to {} on {:?}", val.layout.ty, *val); - - if val.layout.ty.is_box() { - bug!("dereferencing {:?}", val.layout.ty); - } - let mplace = self.ref_to_mplace(&val)?; self.check_mplace_access(mplace, CheckInAllocMsg::DerefTest)?; Ok(mplace)