@@ -153,30 +153,6 @@ pub enum Operand<Tag = (), Id = AllocId> {
153153 Indirect ( MemPlace < Tag , Id > ) ,
154154}
155155
156- impl < Tag > Operand < Tag > {
157- #[ inline]
158- pub fn assert_mem_place ( self ) -> MemPlace < Tag >
159- where
160- Tag : :: std:: fmt:: Debug ,
161- {
162- match self {
163- Operand :: Indirect ( mplace) => mplace,
164- _ => bug ! ( "assert_mem_place: expected Operand::Indirect, got {:?}" , self ) ,
165- }
166- }
167-
168- #[ inline]
169- pub fn assert_immediate ( self ) -> Immediate < Tag >
170- where
171- Tag : :: std:: fmt:: Debug ,
172- {
173- match self {
174- Operand :: Immediate ( imm) => imm,
175- _ => bug ! ( "assert_immediate: expected Operand::Immediate, got {:?}" , self ) ,
176- }
177- }
178- }
179-
180156#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
181157pub struct OpTy < ' tcx , Tag = ( ) > {
182158 op : Operand < Tag > , // Keep this private; it helps enforce invariants.
@@ -267,7 +243,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
267243 & self ,
268244 op : OpTy < ' tcx , M :: PointerTag > ,
269245 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
270- match op. try_as_mplace ( ) {
246+ match op. try_as_mplace ( self ) {
271247 Ok ( mplace) => Ok ( self . force_mplace_ptr ( mplace) ?. into ( ) ) ,
272248 Err ( imm) => Ok ( imm. into ( ) ) , // Nothing to cast/force
273249 }
@@ -335,7 +311,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
335311 & self ,
336312 src : OpTy < ' tcx , M :: PointerTag > ,
337313 ) -> InterpResult < ' tcx , Result < ImmTy < ' tcx , M :: PointerTag > , MPlaceTy < ' tcx , M :: PointerTag > > > {
338- Ok ( match src. try_as_mplace ( ) {
314+ Ok ( match src. try_as_mplace ( self ) {
339315 Ok ( mplace) => {
340316 if let Some ( val) = self . try_read_immediate_from_mplace ( mplace) ? {
341317 Ok ( val)
@@ -383,7 +359,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
383359 op : OpTy < ' tcx , M :: PointerTag > ,
384360 field : u64 ,
385361 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
386- let base = match op. try_as_mplace ( ) {
362+ let base = match op. try_as_mplace ( self ) {
387363 Ok ( mplace) => {
388364 // The easy case
389365 let field = self . mplace_field ( mplace, field) ?;
@@ -420,7 +396,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
420396 variant : VariantIdx ,
421397 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
422398 // Downcasts only change the layout
423- Ok ( match op. try_as_mplace ( ) {
399+ Ok ( match op. try_as_mplace ( self ) {
424400 Ok ( mplace) => self . mplace_downcast ( mplace, variant) ?. into ( ) ,
425401 Err ( ..) => {
426402 let layout = op. layout . for_variant ( self , variant) ;
@@ -439,30 +415,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
439415 Field ( field, _) => self . operand_field ( base, field. index ( ) as u64 ) ?,
440416 Downcast ( _, variant) => self . operand_downcast ( base, variant) ?,
441417 Deref => self . deref_operand ( base) ?. into ( ) ,
442- ConstantIndex { .. } | Index ( _) if base. layout . is_zst ( ) => {
443- OpTy {
444- op : Operand :: Immediate ( Scalar :: zst ( ) . into ( ) ) ,
445- // the actual index doesn't matter, so we just pick a convenient one like 0
446- layout : base. layout . field ( self , 0 ) ?,
447- }
448- }
449- Subslice { from, to, from_end } if base. layout . is_zst ( ) => {
450- let elem_ty = if let ty:: Array ( elem_ty, _) = base. layout . ty . kind {
451- elem_ty
452- } else {
453- bug ! ( "slices shouldn't be zero-sized" ) ;
454- } ;
455- assert ! ( !from_end, "arrays shouldn't be subsliced from the end" ) ;
456-
457- OpTy {
458- op : Operand :: Immediate ( Scalar :: zst ( ) . into ( ) ) ,
459- layout : self . layout_of ( self . tcx . mk_array ( elem_ty, ( to - from) as u64 ) ) ?,
460- }
461- }
462418 Subslice { .. } | ConstantIndex { .. } | Index ( _) => {
463419 // The rest should only occur as mplace, we do not use Immediates for types
464420 // allowing such operations. This matches place_projection forcing an allocation.
465- let mplace = base. assert_mem_place ( ) ;
421+ let mplace = base. assert_mem_place ( self ) ;
466422 self . mplace_projection ( mplace, proj_elem) ?. into ( )
467423 }
468424 } )
0 commit comments