@@ -266,30 +266,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
266266 ) ;
267267 }
268268 }
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 {
285278 self . fail (
286279 location,
287280 format ! ( "{:?} have been lowered to field assignments" , rvalue) ,
288281 )
289282 }
290283 }
291284 Rvalue :: Ref ( _, BorrowKind :: Shallow , _) => {
292- if self . mir_phase > MirPhase :: DropLowering {
285+ if self . mir_phase >= MirPhase :: DropsLowered {
293286 self . fail (
294287 location,
295288 "`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> {
300293 }
301294 }
302295 StatementKind :: AscribeUserType ( ..) => {
303- if self . mir_phase > MirPhase :: DropLowering {
296+ if self . mir_phase >= MirPhase :: DropsLowered {
304297 self . fail (
305298 location,
306299 "`AscribeUserType` should have been removed after drop lowering phase" ,
307300 ) ;
308301 }
309302 }
310303 StatementKind :: FakeRead ( ..) => {
311- if self . mir_phase > MirPhase :: DropLowering {
304+ if self . mir_phase >= MirPhase :: DropsLowered {
312305 self . fail (
313306 location,
314307 "`FakeRead` should have been removed after drop lowering phase" ,
@@ -351,10 +344,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
351344 self . fail ( location, format ! ( "bad arg ({:?} != usize)" , op_cnt_ty) )
352345 }
353346 }
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 ( ..)
356358 | StatementKind :: StorageDead ( ..)
357- | StatementKind :: Retag ( _, _)
358359 | StatementKind :: Coverage ( _)
359360 | StatementKind :: Nop => { }
360361 }
@@ -424,10 +425,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
424425 }
425426 }
426427 TerminatorKind :: DropAndReplace { target, unwind, .. } => {
427- if self . mir_phase > MirPhase :: DropLowering {
428+ if self . mir_phase >= MirPhase :: DropsLowered {
428429 self . fail (
429430 location,
430- "`DropAndReplace` is not permitted to exist after drop elaboration" ,
431+ "`DropAndReplace` should have been removed during drop elaboration" ,
431432 ) ;
432433 }
433434 self . check_edge ( location, * target, EdgeKind :: Normal ) ;
@@ -494,7 +495,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
494495 }
495496 }
496497 TerminatorKind :: Yield { resume, drop, .. } => {
497- if self . mir_phase > MirPhase :: GeneratorLowering {
498+ if self . mir_phase >= MirPhase :: GeneratorsLowered {
498499 self . fail ( location, "`Yield` should have been replaced by generator lowering" ) ;
499500 }
500501 self . check_edge ( location, * resume, EdgeKind :: Normal ) ;
@@ -503,10 +504,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
503504 }
504505 }
505506 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+ }
506513 self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
507514 self . check_edge ( location, * imaginary_target, EdgeKind :: Normal ) ;
508515 }
509516 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+ }
510523 self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
511524 if let Some ( unwind) = unwind {
512525 self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
@@ -520,12 +533,19 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
520533 self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
521534 }
522535 }
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+ }
523544 // Nothing to validate for these.
524545 TerminatorKind :: Resume
525546 | TerminatorKind :: Abort
526547 | TerminatorKind :: Return
527- | TerminatorKind :: Unreachable
528- | TerminatorKind :: GeneratorDrop => { }
548+ | TerminatorKind :: Unreachable => { }
529549 }
530550
531551 self . super_terminator ( terminator, location) ;
0 commit comments