@@ -1152,6 +1152,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1152
1152
& mut self . scopes . unwind_drops ,
1153
1153
self . fn_span ,
1154
1154
should_abort,
1155
+ & mut None ,
1155
1156
) ;
1156
1157
}
1157
1158
}
@@ -1175,12 +1176,9 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1175
1176
}
1176
1177
1177
1178
// Build the drop tree for unwinding in the normal control flow paths.
1178
- let resume_block = Self :: build_unwind_tree (
1179
- cfg,
1180
- & mut self . scopes . unwind_drops ,
1181
- fn_span,
1182
- should_abort,
1183
- ) ;
1179
+ let resume_block = & mut None ;
1180
+ let unwind_drops = & mut self . scopes . unwind_drops ;
1181
+ Self :: build_unwind_tree ( cfg, unwind_drops, fn_span, should_abort, resume_block) ;
1184
1182
1185
1183
// Build the drop tree for unwinding when dropping a suspended
1186
1184
// generator.
@@ -1194,51 +1192,34 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1194
1192
drops. entry_points . push ( ( drop_data. 1 , blocks[ drop_idx] . unwrap ( ) ) ) ;
1195
1193
}
1196
1194
}
1197
- let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1198
- blocks[ ROOT_NODE ] = resume_block;
1199
- drops. build_mir :: < Unwind > ( cfg, & mut blocks) ;
1200
- if let ( None , Some ( new_resume_block) ) = ( resume_block, blocks[ ROOT_NODE ] ) {
1201
- let terminator = if should_abort {
1202
- TerminatorKind :: Abort
1203
- } else {
1204
- TerminatorKind :: Resume
1205
- } ;
1206
- cfg. terminate (
1207
- new_resume_block,
1208
- SourceInfo {
1209
- scope : OUTERMOST_SOURCE_SCOPE ,
1210
- span : fn_span
1211
- } ,
1212
- terminator,
1213
- ) ;
1214
- }
1195
+ Self :: build_unwind_tree ( cfg, drops, fn_span, should_abort, resume_block) ;
1215
1196
}
1216
1197
1217
1198
fn build_unwind_tree (
1218
1199
cfg : & mut CFG < ' tcx > ,
1219
1200
drops : & mut DropTree ,
1220
1201
fn_span : Span ,
1221
1202
should_abort : bool ,
1222
- ) -> Option < BasicBlock > {
1203
+ resume_block : & mut Option < BasicBlock > ,
1204
+ ) {
1223
1205
let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1206
+ blocks[ ROOT_NODE ] = * resume_block;
1224
1207
drops. build_mir :: < Unwind > ( cfg, & mut blocks) ;
1225
- if let Some ( resume_block ) = blocks[ ROOT_NODE ] {
1208
+ if let ( None , Some ( resume ) ) = ( * resume_block , blocks[ ROOT_NODE ] ) {
1226
1209
let terminator = if should_abort {
1227
1210
TerminatorKind :: Abort
1228
1211
} else {
1229
1212
TerminatorKind :: Resume
1230
1213
} ;
1231
1214
cfg. terminate (
1232
- resume_block ,
1215
+ resume ,
1233
1216
SourceInfo {
1234
1217
scope : OUTERMOST_SOURCE_SCOPE ,
1235
1218
span : fn_span
1236
1219
} ,
1237
1220
terminator,
1238
1221
) ;
1239
- Some ( resume_block)
1240
- } else {
1241
- None
1222
+ * resume_block = blocks[ ROOT_NODE ] ;
1242
1223
}
1243
1224
}
1244
1225
}
0 commit comments