@@ -340,7 +340,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
340
340
341
341
let field = field. try_into ( ) . unwrap ( ) ;
342
342
let field_layout = op. layout . field ( self , field) ?;
343
- if field_layout. size . bytes ( ) == 0 {
343
+ if field_layout. is_zst ( ) {
344
344
let val = Value :: Scalar ( Scalar :: zst ( ) . into ( ) ) ;
345
345
return Ok ( OpTy { op : Operand :: Immediate ( val) , layout : field_layout } ) ;
346
346
}
@@ -397,9 +397,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
397
397
Field ( field, _) => self . operand_field ( base, field. index ( ) as u64 ) ?,
398
398
Downcast ( _, variant) => self . operand_downcast ( base, variant) ?,
399
399
Deref => self . deref_operand ( base) ?. into ( ) ,
400
- // The rest should only occur as mplace, we do not use Immediates for types
401
- // allowing such operations. This matches place_projection forcing an allocation.
402
- Subslice { .. } | ConstantIndex { .. } | Index ( _) => {
400
+ Subslice { .. } | ConstantIndex { .. } | Index ( _) => if base. layout . is_zst ( ) {
401
+ OpTy {
402
+ op : Operand :: Immediate ( Value :: Scalar ( Scalar :: zst ( ) . into ( ) ) ) ,
403
+ // the actual index doesn't matter, so we just pick a convenient one like 0
404
+ layout : base. layout . field ( self , 0 ) ?,
405
+ }
406
+ } else {
407
+ // The rest should only occur as mplace, we do not use Immediates for types
408
+ // allowing such operations. This matches place_projection forcing an allocation.
403
409
let mplace = base. to_mem_place ( ) ;
404
410
self . mplace_projection ( mplace, proj_elem) ?. into ( )
405
411
}
0 commit comments