Skip to content

Commit 3bd8df9

Browse files
committed
Assert that link_entry_point sees the expected dummy terminator
1 parent 30fa6a8 commit 3bd8df9

File tree

1 file changed

+11
-1
lines changed
  • compiler/rustc_mir_build/src/build

1 file changed

+11
-1
lines changed

compiler/rustc_mir_build/src/build/scope.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
678678
// `build_drop_trees` doesn't have access to our source_info, so we
679679
// create a dummy terminator now. `TerminatorKind::UnwindResume` is used
680680
// because MIR type checking will panic if it hasn't been overwritten.
681+
// (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
681682
self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
682683

683684
self.cfg.start_new_block().unit()
@@ -710,6 +711,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
710711
// `build_drop_trees` doesn't have access to our source_info, so we
711712
// create a dummy terminator now. `TerminatorKind::UnwindResume` is used
712713
// because MIR type checking will panic if it hasn't been overwritten.
714+
// (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
713715
self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
714716
}
715717

@@ -1440,7 +1442,15 @@ impl<'tcx> DropTreeBuilder<'tcx> for ExitScopes {
14401442
cfg.start_new_block()
14411443
}
14421444
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+
}
14441454
}
14451455
}
14461456

0 commit comments

Comments
 (0)