@@ -1141,6 +1141,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
11411141 & mut self . scopes . unwind_drops ,
11421142 self . fn_span ,
11431143 should_abort,
1144+ & mut None ,
11441145 ) ;
11451146 }
11461147 }
@@ -1161,8 +1162,9 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
11611162 }
11621163
11631164 // Build the drop tree for unwinding in the normal control flow paths.
1164- let resume_block =
1165- Self :: build_unwind_tree ( cfg, & mut self . scopes . unwind_drops , fn_span, should_abort) ;
1165+ let resume_block = & mut None ;
1166+ let unwind_drops = & mut self . scopes . unwind_drops ;
1167+ Self :: build_unwind_tree ( cfg, unwind_drops, fn_span, should_abort, resume_block) ;
11661168
11671169 // Build the drop tree for unwinding when dropping a suspended
11681170 // generator.
@@ -1176,39 +1178,28 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
11761178 drops. entry_points . push ( ( drop_data. 1 , blocks[ drop_idx] . unwrap ( ) ) ) ;
11771179 }
11781180 }
1179- let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1180- blocks[ ROOT_NODE ] = resume_block;
1181- drops. build_mir :: < Unwind > ( cfg, & mut blocks) ;
1182- if let ( None , Some ( new_resume_block) ) = ( resume_block, blocks[ ROOT_NODE ] ) {
1183- let terminator =
1184- if should_abort { TerminatorKind :: Abort } else { TerminatorKind :: Resume } ;
1185- cfg. terminate (
1186- new_resume_block,
1187- SourceInfo { scope : OUTERMOST_SOURCE_SCOPE , span : fn_span } ,
1188- terminator,
1189- ) ;
1190- }
1181+ Self :: build_unwind_tree ( cfg, drops, fn_span, should_abort, resume_block) ;
11911182 }
11921183
11931184 fn build_unwind_tree (
11941185 cfg : & mut CFG < ' tcx > ,
11951186 drops : & mut DropTree ,
11961187 fn_span : Span ,
11971188 should_abort : bool ,
1198- ) -> Option < BasicBlock > {
1189+ resume_block : & mut Option < BasicBlock > ,
1190+ ) {
11991191 let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1192+ blocks[ ROOT_NODE ] = * resume_block;
12001193 drops. build_mir :: < Unwind > ( cfg, & mut blocks) ;
1201- if let Some ( resume_block ) = blocks[ ROOT_NODE ] {
1194+ if let ( None , Some ( resume ) ) = ( * resume_block , blocks[ ROOT_NODE ] ) {
12021195 let terminator =
12031196 if should_abort { TerminatorKind :: Abort } else { TerminatorKind :: Resume } ;
12041197 cfg. terminate (
1205- resume_block ,
1198+ resume ,
12061199 SourceInfo { scope : OUTERMOST_SOURCE_SCOPE , span : fn_span } ,
12071200 terminator,
12081201 ) ;
1209- Some ( resume_block)
1210- } else {
1211- None
1202+ * resume_block = blocks[ ROOT_NODE ] ;
12121203 }
12131204 }
12141205}
0 commit comments