about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-03-06 21:27:41 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-03-06 22:32:01 +1100
commit3bd8df96e12d22793cd8dc694f07becb1f6f4f3d (patch)
tree850d23b989e4c0ea607797c3c165074e01fc0226
parent30fa6a8b50f899d45f78c0596397d18b718782b0 (diff)
downloadrust-3bd8df96e12d22793cd8dc694f07becb1f6f4f3d.tar.gz
rust-3bd8df96e12d22793cd8dc694f07becb1f6f4f3d.zip
Assert that `link_entry_point` sees the expected dummy terminator
-rw-r--r--compiler/rustc_mir_build/src/build/scope.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs
index a27c43928eb..7ed493ec9c7 100644
--- a/compiler/rustc_mir_build/src/build/scope.rs
+++ b/compiler/rustc_mir_build/src/build/scope.rs
@@ -678,6 +678,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         // `build_drop_trees` doesn't have access to our source_info, so we
         // create a dummy terminator now. `TerminatorKind::UnwindResume` is used
         // because MIR type checking will panic if it hasn't been overwritten.
+        // (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
         self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
 
         self.cfg.start_new_block().unit()
@@ -710,6 +711,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         // `build_drop_trees` doesn't have access to our source_info, so we
         // create a dummy terminator now. `TerminatorKind::UnwindResume` is used
         // because MIR type checking will panic if it hasn't been overwritten.
+        // (See `<ExitScopes as DropTreeBuilder>::link_entry_point`.)
         self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
     }
 
@@ -1440,7 +1442,15 @@ impl<'tcx> DropTreeBuilder<'tcx> for ExitScopes {
         cfg.start_new_block()
     }
     fn link_entry_point(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
-        cfg.block_data_mut(from).terminator_mut().kind = TerminatorKind::Goto { target: to };
+        // There should be an existing terminator with real source info and a
+        // dummy TerminatorKind. Replace it with a proper goto.
+        // (The dummy is added by `break_scope` and `break_for_else`.)
+        let term = cfg.block_data_mut(from).terminator_mut();
+        if let TerminatorKind::UnwindResume = term.kind {
+            term.kind = TerminatorKind::Goto { target: to };
+        } else {
+            span_bug!(term.source_info.span, "unexpected dummy terminator kind: {:?}", term.kind);
+        }
     }
 }