about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-08-31 11:29:02 +0200
committerRalf Jung <post@ralfj.de>2024-08-31 11:29:02 +0200
commitd0aedfbb900309bb633b3ba04bf008183cfdd9a7 (patch)
treebd27610dc20d985b99393191d4a0369390b625e8 /compiler/rustc_const_eval/src
parentfa72f0763de6bc1596208fc1419883ce5aea0de4 (diff)
downloadrust-d0aedfbb900309bb633b3ba04bf008183cfdd9a7.tar.gz
rust-d0aedfbb900309bb633b3ba04bf008183cfdd9a7.zip
interpret, codegen: tweak some comments and checks regarding Box with custom allocator
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 2afdd02c880..ede6a51c712 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -438,14 +438,16 @@ where
         &self,
         src: &impl Readable<'tcx, M::Provenance>,
     ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
+        if src.layout().ty.is_box() {
+            // Derefer should have removed all Box derefs.
+            // Some `Box` are not immediates (if they have a custom allocator)
+            // so the code below would fail.
+            bug!("dereferencing {}", src.layout().ty);
+        }
+
         let val = self.read_immediate(src)?;
         trace!("deref to {} on {:?}", val.layout.ty, *val);
 
-        if val.layout.ty.is_box() {
-            // Derefer should have removed all Box derefs
-            bug!("dereferencing {}", val.layout.ty);
-        }
-
         let mplace = self.ref_to_mplace(&val)?;
         Ok(mplace)
     }