@@ -642,6 +642,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
642
642
}
643
643
}
644
644
TerminatorKind :: Yield { resume, drop, .. } => {
645
+ if self . body . generator . is_none ( ) {
646
+ self . fail ( location, "`Yield` cannot appear outside generator bodies" ) ;
647
+ }
645
648
if self . mir_phase >= MirPhase :: GeneratorsLowered {
646
649
self . fail ( location, "`Yield` should have been replaced by generator lowering" ) ;
647
650
}
@@ -681,18 +684,29 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
681
684
}
682
685
}
683
686
TerminatorKind :: GeneratorDrop => {
687
+ if self . body . generator . is_none ( ) {
688
+ self . fail ( location, "`GeneratorDrop` cannot appear outside generator bodies" ) ;
689
+ }
684
690
if self . mir_phase >= MirPhase :: GeneratorsLowered {
685
691
self . fail (
686
692
location,
687
693
"`GeneratorDrop` should have been replaced by generator lowering" ,
688
694
) ;
689
695
}
690
696
}
691
- // Nothing to validate for these.
692
- TerminatorKind :: Resume
693
- | TerminatorKind :: Abort
694
- | TerminatorKind :: Return
695
- | TerminatorKind :: Unreachable => { }
697
+ TerminatorKind :: Resume | TerminatorKind :: Abort => {
698
+ let bb = location. block ;
699
+ if !self . body . basic_blocks ( ) [ bb] . is_cleanup {
700
+ self . fail ( location, "Cannot `Resume` from non-cleanup basic block" )
701
+ }
702
+ }
703
+ TerminatorKind :: Return => {
704
+ let bb = location. block ;
705
+ if self . body . basic_blocks ( ) [ bb] . is_cleanup {
706
+ self . fail ( location, "Cannot `Return` from cleanup basic block" )
707
+ }
708
+ }
709
+ TerminatorKind :: Unreachable => { }
696
710
}
697
711
698
712
self . super_terminator ( terminator, location) ;
0 commit comments