@@ -9,7 +9,9 @@ use rustc_middle::mir;
99use rustc_middle:: ty:: layout:: LayoutOf ;
1010use rustc_target:: abi:: { FieldIdx , FIRST_VARIANT } ;
1111
12- use super :: { ImmTy , Immediate , InterpCx , InterpResult , Machine , PlaceTy , Projectable , Scalar } ;
12+ use super :: {
13+ ImmTy , Immediate , InterpCx , InterpResult , Machine , MemPlaceMeta , PlaceTy , Projectable , Scalar ,
14+ } ;
1315use crate :: util;
1416
1517impl < ' 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> {
304306 ( variant_index, variant_dest, active_field_index)
305307 }
306308 mir:: AggregateKind :: RawPtr ( ..) => {
307- // Trying to `project_field` into pointers tends not to work,
308- // so build the `Immediate` from the parts directly.
309+ // Pointers don't have "fields" in the normal sense, so the
310+ // projection-based code below would either fail in projection
311+ // or in type mismatches. Instead, build an `Immediate` from
312+ // the parts and write that to the destination.
309313 let [ data, meta] = & operands. raw else {
310314 bug ! ( "{kind:?} should have 2 operands, had {operands:?}" ) ;
311315 } ;
312316 let data = self . eval_operand ( data, None ) ?;
313317 let data = self . read_pointer ( & data) ?;
314318 let meta = self . eval_operand ( meta, None ) ?;
315- let meta = self . read_mem_place_meta ( & meta) ?;
319+ let meta = if meta. layout . is_zst ( ) {
320+ MemPlaceMeta :: None
321+ } else {
322+ MemPlaceMeta :: Meta ( self . read_scalar ( & meta) ?)
323+ } ;
316324 let ptr_imm = Immediate :: new_pointer_with_meta ( data, meta, self ) ;
317325 let ptr = ImmTy :: from_immediate ( ptr_imm, dest. layout ) ;
318326 self . copy_op ( & ptr, dest) ?;
0 commit comments