@@ -444,13 +444,27 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
444444 Field ( field, _) => self . operand_field ( base, field. index ( ) as u64 ) ?,
445445 Downcast ( _, variant) => self . operand_downcast ( base, variant) ?,
446446 Deref => self . deref_operand ( base) ?. into ( ) ,
447- Subslice { .. } | ConstantIndex { .. } | Index ( _) => if base. layout . is_zst ( ) {
447+ ConstantIndex { .. } | Index ( _) if base. layout . is_zst ( ) => {
448448 OpTy {
449449 op : Operand :: Immediate ( Scalar :: zst ( ) . into ( ) ) ,
450450 // the actual index doesn't matter, so we just pick a convenient one like 0
451451 layout : base. layout . field ( self , 0 ) ?,
452452 }
453- } else {
453+ }
454+ Subslice { from, to, from_end } if base. layout . is_zst ( ) => {
455+ let elem_ty = if let ty:: Array ( elem_ty, _) = base. layout . ty . kind {
456+ elem_ty
457+ } else {
458+ bug ! ( "slices shouldn't be zero-sized" ) ;
459+ } ;
460+ assert ! ( !from_end, "arrays shouldn't be subsliced from the end" ) ;
461+
462+ OpTy {
463+ op : Operand :: Immediate ( Scalar :: zst ( ) . into ( ) ) ,
464+ layout : self . layout_of ( self . tcx . mk_array ( elem_ty, ( to - from) as u64 ) ) ?,
465+ }
466+ }
467+ Subslice { .. } | ConstantIndex { .. } | Index ( _) => {
454468 // The rest should only occur as mplace, we do not use Immediates for types
455469 // allowing such operations. This matches place_projection forcing an allocation.
456470 let mplace = base. assert_mem_place ( ) ;
0 commit comments