about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/step.rs
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-04-12 10:43:51 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2024-04-21 11:08:37 -0700
commitbb8d6f790b63797a816a4007e8ab002ed2906de7 (patch)
tree58b8d1ba28efe67eb2bf39ffe18d7a585d46dac1 /compiler/rustc_const_eval/src/interpret/step.rs
parent5e1d16ca5515ae2134b69c68e7b05f6fead90f06 (diff)
downloadrust-bb8d6f790b63797a816a4007e8ab002ed2906de7.tar.gz
rust-bb8d6f790b63797a816a4007e8ab002ed2906de7.zip
Address PR feedback
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/step.rs')
-rw-r--r--compiler/rustc_const_eval/src/interpret/step.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs
index 460cd377c8f..b29034e991e 100644
--- a/compiler/rustc_const_eval/src/interpret/step.rs
+++ b/compiler/rustc_const_eval/src/interpret/step.rs
@@ -9,7 +9,9 @@ use rustc_middle::mir;
 use rustc_middle::ty::layout::LayoutOf;
 use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
 
-use super::{ImmTy, Immediate, InterpCx, InterpResult, Machine, PlaceTy, Projectable, Scalar};
+use super::{
+    ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy, Projectable, Scalar,
+};
 use crate::util;
 
 impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
@@ -304,15 +306,21 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                 (variant_index, variant_dest, active_field_index)
             }
             mir::AggregateKind::RawPtr(..) => {
-                // Trying to `project_field` into pointers tends not to work,
-                // so build the `Immediate` from the parts directly.
+                // Pointers don't have "fields" in the normal sense, so the
+                // projection-based code below would either fail in projection
+                // or in type mismatches. Instead, build an `Immediate` from
+                // the parts and write that to the destination.
                 let [data, meta] = &operands.raw else {
                     bug!("{kind:?} should have 2 operands, had {operands:?}");
                 };
                 let data = self.eval_operand(data, None)?;
                 let data = self.read_pointer(&data)?;
                 let meta = self.eval_operand(meta, None)?;
-                let meta = self.read_mem_place_meta(&meta)?;
+                let meta = if meta.layout.is_zst() {
+                    MemPlaceMeta::None
+                } else {
+                    MemPlaceMeta::Meta(self.read_scalar(&meta)?)
+                };
                 let ptr_imm = Immediate::new_pointer_with_meta(data, meta, self);
                 let ptr = ImmTy::from_immediate(ptr_imm, dest.layout);
                 self.copy_op(&ptr, dest)?;