@@ -678,6 +678,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
678
678
// `build_drop_trees` doesn't have access to our source_info, so we
679
679
// create a dummy terminator now. `TerminatorKind::UnwindResume` is used
680
680
// because MIR type checking will panic if it hasn't been overwritten.
681
+ // (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
681
682
self . cfg . terminate ( block, source_info, TerminatorKind :: UnwindResume ) ;
682
683
683
684
self . cfg . start_new_block ( ) . unit ( )
@@ -710,6 +711,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
710
711
// `build_drop_trees` doesn't have access to our source_info, so we
711
712
// create a dummy terminator now. `TerminatorKind::UnwindResume` is used
712
713
// because MIR type checking will panic if it hasn't been overwritten.
714
+ // (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
713
715
self . cfg . terminate ( block, source_info, TerminatorKind :: UnwindResume ) ;
714
716
}
715
717
@@ -1440,7 +1442,15 @@ impl<'tcx> DropTreeBuilder<'tcx> for ExitScopes {
1440
1442
cfg. start_new_block ( )
1441
1443
}
1442
1444
fn link_entry_point ( cfg : & mut CFG < ' tcx > , from : BasicBlock , to : BasicBlock ) {
1443
- cfg. block_data_mut ( from) . terminator_mut ( ) . kind = TerminatorKind :: Goto { target : to } ;
1445
+ // There should be an existing terminator with real source info and a
1446
+ // dummy TerminatorKind. Replace it with a proper goto.
1447
+ // (The dummy is added by `break_scope` and `break_for_else`.)
1448
+ let term = cfg. block_data_mut ( from) . terminator_mut ( ) ;
1449
+ if let TerminatorKind :: UnwindResume = term. kind {
1450
+ term. kind = TerminatorKind :: Goto { target : to } ;
1451
+ } else {
1452
+ span_bug ! ( term. source_info. span, "unexpected dummy terminator kind: {:?}" , term. kind) ;
1453
+ }
1444
1454
}
1445
1455
}
1446
1456
0 commit comments