@@ -266,30 +266,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
266
266
) ;
267
267
}
268
268
}
269
- // The deaggregator currently does not deaggreagate arrays.
270
- // So for now, we ignore them here.
271
- Rvalue :: Aggregate ( box AggregateKind :: Array { .. } , _) => { }
272
- // All other aggregates must be gone after some phases.
273
- Rvalue :: Aggregate ( box kind, _) => {
274
- if self . mir_phase > MirPhase :: DropLowering
275
- && !matches ! ( kind, AggregateKind :: Generator ( ..) )
276
- {
277
- // Generators persist until the state machine transformation, but all
278
- // other aggregates must have been lowered.
279
- self . fail (
280
- location,
281
- format ! ( "{:?} have been lowered to field assignments" , rvalue) ,
282
- )
283
- } else if self . mir_phase > MirPhase :: GeneratorLowering {
284
- // No more aggregates after drop and generator lowering.
269
+ Rvalue :: Aggregate ( agg_kind, _) => {
270
+ let disallowed = match * * agg_kind {
271
+ AggregateKind :: Array ( ..) => false ,
272
+ AggregateKind :: Generator ( ..) => {
273
+ self . mir_phase >= MirPhase :: GeneratorsLowered
274
+ }
275
+ _ => self . mir_phase >= MirPhase :: Deaggregated ,
276
+ } ;
277
+ if disallowed {
285
278
self . fail (
286
279
location,
287
280
format ! ( "{:?} have been lowered to field assignments" , rvalue) ,
288
281
)
289
282
}
290
283
}
291
284
Rvalue :: Ref ( _, BorrowKind :: Shallow , _) => {
292
- if self . mir_phase > MirPhase :: DropLowering {
285
+ if self . mir_phase >= MirPhase :: DropsLowered {
293
286
self . fail (
294
287
location,
295
288
"`Assign` statement with a `Shallow` borrow should have been removed after drop lowering phase" ,
@@ -300,15 +293,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
300
293
}
301
294
}
302
295
StatementKind :: AscribeUserType ( ..) => {
303
- if self . mir_phase > MirPhase :: DropLowering {
296
+ if self . mir_phase >= MirPhase :: DropsLowered {
304
297
self . fail (
305
298
location,
306
299
"`AscribeUserType` should have been removed after drop lowering phase" ,
307
300
) ;
308
301
}
309
302
}
310
303
StatementKind :: FakeRead ( ..) => {
311
- if self . mir_phase > MirPhase :: DropLowering {
304
+ if self . mir_phase >= MirPhase :: DropsLowered {
312
305
self . fail (
313
306
location,
314
307
"`FakeRead` should have been removed after drop lowering phase" ,
@@ -351,10 +344,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
351
344
self . fail ( location, format ! ( "bad arg ({:?} != usize)" , op_cnt_ty) )
352
345
}
353
346
}
354
- StatementKind :: SetDiscriminant { .. }
355
- | StatementKind :: StorageLive ( ..)
347
+ StatementKind :: SetDiscriminant { .. } => {
348
+ if self . mir_phase < MirPhase :: DropsLowered {
349
+ self . fail ( location, "`SetDiscriminant` is not allowed until drop elaboration" ) ;
350
+ }
351
+ }
352
+ StatementKind :: Retag ( _, _) => {
353
+ // FIXME(JakobDegen) The validator should check that `self.mir_phase <
354
+ // DropsLowered`. However, this causes ICEs with generation of drop shims, which
355
+ // seem to fail to set their `MirPhase` correctly.
356
+ }
357
+ StatementKind :: StorageLive ( ..)
356
358
| StatementKind :: StorageDead ( ..)
357
- | StatementKind :: Retag ( _, _)
358
359
| StatementKind :: Coverage ( _)
359
360
| StatementKind :: Nop => { }
360
361
}
@@ -424,10 +425,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
424
425
}
425
426
}
426
427
TerminatorKind :: DropAndReplace { target, unwind, .. } => {
427
- if self . mir_phase > MirPhase :: DropLowering {
428
+ if self . mir_phase >= MirPhase :: DropsLowered {
428
429
self . fail (
429
430
location,
430
- "`DropAndReplace` is not permitted to exist after drop elaboration" ,
431
+ "`DropAndReplace` should have been removed during drop elaboration" ,
431
432
) ;
432
433
}
433
434
self . check_edge ( location, * target, EdgeKind :: Normal ) ;
@@ -494,7 +495,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
494
495
}
495
496
}
496
497
TerminatorKind :: Yield { resume, drop, .. } => {
497
- if self . mir_phase > MirPhase :: GeneratorLowering {
498
+ if self . mir_phase >= MirPhase :: GeneratorsLowered {
498
499
self . fail ( location, "`Yield` should have been replaced by generator lowering" ) ;
499
500
}
500
501
self . check_edge ( location, * resume, EdgeKind :: Normal ) ;
@@ -503,10 +504,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
503
504
}
504
505
}
505
506
TerminatorKind :: FalseEdge { real_target, imaginary_target } => {
507
+ if self . mir_phase >= MirPhase :: DropsLowered {
508
+ self . fail (
509
+ location,
510
+ "`FalseEdge` should have been removed after drop elaboration" ,
511
+ ) ;
512
+ }
506
513
self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
507
514
self . check_edge ( location, * imaginary_target, EdgeKind :: Normal ) ;
508
515
}
509
516
TerminatorKind :: FalseUnwind { real_target, unwind } => {
517
+ if self . mir_phase >= MirPhase :: DropsLowered {
518
+ self . fail (
519
+ location,
520
+ "`FalseUnwind` should have been removed after drop elaboration" ,
521
+ ) ;
522
+ }
510
523
self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
511
524
if let Some ( unwind) = unwind {
512
525
self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
@@ -520,12 +533,19 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
520
533
self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
521
534
}
522
535
}
536
+ TerminatorKind :: GeneratorDrop => {
537
+ if self . mir_phase >= MirPhase :: GeneratorsLowered {
538
+ self . fail (
539
+ location,
540
+ "`GeneratorDrop` should have been replaced by generator lowering" ,
541
+ ) ;
542
+ }
543
+ }
523
544
// Nothing to validate for these.
524
545
TerminatorKind :: Resume
525
546
| TerminatorKind :: Abort
526
547
| TerminatorKind :: Return
527
- | TerminatorKind :: Unreachable
528
- | TerminatorKind :: GeneratorDrop => { }
548
+ | TerminatorKind :: Unreachable => { }
529
549
}
530
550
531
551
self . super_terminator ( terminator, location) ;
0 commit comments