@@ -977,6 +977,21 @@ impl Integrator<'_, '_> {
977977 trace ! ( "mapping block `{:?}` to `{:?}`" , block, new) ;
978978 new
979979 }
980+
981+ fn map_unwind ( & self , unwind : Option < BasicBlock > ) -> Option < BasicBlock > {
982+ if self . in_cleanup_block {
983+ if unwind. is_some ( ) {
984+ bug ! ( "cleanup on cleanup block" ) ;
985+ }
986+ return unwind;
987+ }
988+
989+ match unwind {
990+ Some ( target) => Some ( self . map_block ( target) ) ,
991+ // Add an unwind edge to the original call's cleanup block
992+ None => self . cleanup_block ,
993+ }
994+ }
980995}
981996
982997impl < ' tcx > MutVisitor < ' tcx > for Integrator < ' _ , ' tcx > {
@@ -1085,35 +1100,17 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
10851100 TerminatorKind :: Drop { ref mut target, ref mut unwind, .. }
10861101 | TerminatorKind :: DropAndReplace { ref mut target, ref mut unwind, .. } => {
10871102 * target = self . map_block ( * target) ;
1088- if let Some ( tgt) = * unwind {
1089- * unwind = Some ( self . map_block ( tgt) ) ;
1090- } else if !self . in_cleanup_block {
1091- // Unless this drop is in a cleanup block, add an unwind edge to
1092- // the original call's cleanup block
1093- * unwind = self . cleanup_block ;
1094- }
1103+ * unwind = self . map_unwind ( * unwind) ;
10951104 }
10961105 TerminatorKind :: Call { ref mut target, ref mut cleanup, .. } => {
10971106 if let Some ( ref mut tgt) = * target {
10981107 * tgt = self . map_block ( * tgt) ;
10991108 }
1100- if let Some ( tgt) = * cleanup {
1101- * cleanup = Some ( self . map_block ( tgt) ) ;
1102- } else if !self . in_cleanup_block {
1103- // Unless this call is in a cleanup block, add an unwind edge to
1104- // the original call's cleanup block
1105- * cleanup = self . cleanup_block ;
1106- }
1109+ * cleanup = self . map_unwind ( * cleanup) ;
11071110 }
11081111 TerminatorKind :: Assert { ref mut target, ref mut cleanup, .. } => {
11091112 * target = self . map_block ( * target) ;
1110- if let Some ( tgt) = * cleanup {
1111- * cleanup = Some ( self . map_block ( tgt) ) ;
1112- } else if !self . in_cleanup_block {
1113- // Unless this assert is in a cleanup block, add an unwind edge to
1114- // the original call's cleanup block
1115- * cleanup = self . cleanup_block ;
1116- }
1113+ * cleanup = self . map_unwind ( * cleanup) ;
11171114 }
11181115 TerminatorKind :: Return => {
11191116 terminator. kind = if let Some ( tgt) = self . callsite . target {
@@ -1141,11 +1138,8 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
11411138 TerminatorKind :: InlineAsm { ref mut destination, ref mut cleanup, .. } => {
11421139 if let Some ( ref mut tgt) = * destination {
11431140 * tgt = self . map_block ( * tgt) ;
1144- } else if !self . in_cleanup_block {
1145- // Unless this inline asm is in a cleanup block, add an unwind edge to
1146- // the original call's cleanup block
1147- * cleanup = self . cleanup_block ;
11481141 }
1142+ * cleanup = self . map_unwind ( * cleanup) ;
11491143 }
11501144 }
11511145 }
0 commit comments