@@ -153,30 +153,6 @@ pub enum Operand<Tag = (), Id = AllocId> {
153
153
Indirect ( MemPlace < Tag , Id > ) ,
154
154
}
155
155
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
-
180
156
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
181
157
pub struct OpTy < ' tcx , Tag = ( ) > {
182
158
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> {
267
243
& self ,
268
244
op : OpTy < ' tcx , M :: PointerTag > ,
269
245
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
270
- match op. try_as_mplace ( ) {
246
+ match op. try_as_mplace ( self ) {
271
247
Ok ( mplace) => Ok ( self . force_mplace_ptr ( mplace) ?. into ( ) ) ,
272
248
Err ( imm) => Ok ( imm. into ( ) ) , // Nothing to cast/force
273
249
}
@@ -335,7 +311,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
335
311
& self ,
336
312
src : OpTy < ' tcx , M :: PointerTag > ,
337
313
) -> 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 ) {
339
315
Ok ( mplace) => {
340
316
if let Some ( val) = self . try_read_immediate_from_mplace ( mplace) ? {
341
317
Ok ( val)
@@ -383,7 +359,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
383
359
op : OpTy < ' tcx , M :: PointerTag > ,
384
360
field : u64 ,
385
361
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
386
- let base = match op. try_as_mplace ( ) {
362
+ let base = match op. try_as_mplace ( self ) {
387
363
Ok ( mplace) => {
388
364
// The easy case
389
365
let field = self . mplace_field ( mplace, field) ?;
@@ -420,7 +396,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
420
396
variant : VariantIdx ,
421
397
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
422
398
// Downcasts only change the layout
423
- Ok ( match op. try_as_mplace ( ) {
399
+ Ok ( match op. try_as_mplace ( self ) {
424
400
Ok ( mplace) => self . mplace_downcast ( mplace, variant) ?. into ( ) ,
425
401
Err ( ..) => {
426
402
let layout = op. layout . for_variant ( self , variant) ;
@@ -439,30 +415,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
439
415
Field ( field, _) => self . operand_field ( base, field. index ( ) as u64 ) ?,
440
416
Downcast ( _, variant) => self . operand_downcast ( base, variant) ?,
441
417
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
- }
462
418
Subslice { .. } | ConstantIndex { .. } | Index ( _) => {
463
419
// The rest should only occur as mplace, we do not use Immediates for types
464
420
// 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 ) ;
466
422
self . mplace_projection ( mplace, proj_elem) ?. into ( )
467
423
}
468
424
} )
0 commit comments