@@ -232,6 +232,24 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
232232 }
233233 }
234234
235+ fn check_unwind_edge ( & mut self , location : Location , unwind : UnwindAction ) {
236+ let is_cleanup = self . body . basic_blocks [ location. block ] . is_cleanup ;
237+ match unwind {
238+ UnwindAction :: Cleanup ( unwind) => {
239+ if is_cleanup {
240+ self . fail ( location, "unwind on cleanup block" ) ;
241+ }
242+ self . check_edge ( location, unwind, EdgeKind :: Unwind ) ;
243+ }
244+ UnwindAction :: Continue => {
245+ if is_cleanup {
246+ self . fail ( location, "unwind on cleanup block" ) ;
247+ }
248+ }
249+ UnwindAction :: Unreachable | UnwindAction :: Terminate => ( ) ,
250+ }
251+ }
252+
235253 /// Check if src can be assigned into dest.
236254 /// This is not precise, it will accept some incorrect assignments.
237255 fn mir_assign_valid_types ( & self , src : Ty < ' tcx > , dest : Ty < ' tcx > ) -> bool {
@@ -902,9 +920,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
902920 }
903921 TerminatorKind :: Drop { target, unwind, .. } => {
904922 self . check_edge ( location, * target, EdgeKind :: Normal ) ;
905- if let UnwindAction :: Cleanup ( unwind) = unwind {
906- self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
907- }
923+ self . check_unwind_edge ( location, * unwind) ;
908924 }
909925 TerminatorKind :: Call { func, args, destination, target, unwind, .. } => {
910926 let func_ty = func. ty ( & self . body . local_decls , self . tcx ) ;
@@ -918,9 +934,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
918934 if let Some ( target) = target {
919935 self . check_edge ( location, * target, EdgeKind :: Normal ) ;
920936 }
921- if let UnwindAction :: Cleanup ( cleanup) = unwind {
922- self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
923- }
937+ self . check_unwind_edge ( location, * unwind) ;
924938
925939 // The call destination place and Operand::Move place used as an argument might be
926940 // passed by a reference to the callee. Consequently they must be non-overlapping.
@@ -958,9 +972,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
958972 ) ;
959973 }
960974 self . check_edge ( location, * target, EdgeKind :: Normal ) ;
961- if let UnwindAction :: Cleanup ( cleanup) = unwind {
962- self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
963- }
975+ self . check_unwind_edge ( location, * unwind) ;
964976 }
965977 TerminatorKind :: Yield { resume, drop, .. } => {
966978 if self . body . generator . is_none ( ) {
@@ -992,17 +1004,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
9921004 ) ;
9931005 }
9941006 self . check_edge ( location, * real_target, EdgeKind :: Normal ) ;
995- if let UnwindAction :: Cleanup ( unwind) = unwind {
996- self . check_edge ( location, * unwind, EdgeKind :: Unwind ) ;
997- }
1007+ self . check_unwind_edge ( location, * unwind) ;
9981008 }
9991009 TerminatorKind :: InlineAsm { destination, unwind, .. } => {
10001010 if let Some ( destination) = destination {
10011011 self . check_edge ( location, * destination, EdgeKind :: Normal ) ;
10021012 }
1003- if let UnwindAction :: Cleanup ( cleanup) = unwind {
1004- self . check_edge ( location, * cleanup, EdgeKind :: Unwind ) ;
1005- }
1013+ self . check_unwind_edge ( location, * unwind) ;
10061014 }
10071015 TerminatorKind :: GeneratorDrop => {
10081016 if self . body . generator . is_none ( ) {
0 commit comments