about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2025-03-04 20:30:42 +0100
committerTomasz Miąsko <tomasz.miasko@gmail.com>2025-03-06 15:13:56 +0100
commitc5b7a9c4b5b06cab36b0e3914854d6ee4a600d46 (patch)
tree0583c946e17ef22053ee1dfc9cfe89d774ea789f
parent30f168ef811aec63124eac677e14699baa9395bd (diff)
downloadrust-c5b7a9c4b5b06cab36b0e3914854d6ee4a600d46.tar.gz
rust-c5b7a9c4b5b06cab36b0e3914854d6ee4a600d46.zip
Factor out edge breaking code
-rw-r--r--compiler/rustc_mir_transform/src/add_call_guards.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/compiler/rustc_mir_transform/src/add_call_guards.rs b/compiler/rustc_mir_transform/src/add_call_guards.rs
index 55694cacd92..c64bb30fa21 100644
--- a/compiler/rustc_mir_transform/src/add_call_guards.rs
+++ b/compiler/rustc_mir_transform/src/add_call_guards.rs
@@ -40,6 +40,16 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
         let mut new_blocks = Vec::new();
 
         let cur_len = body.basic_blocks.len();
+        let mut new_block = |source_info: SourceInfo, is_cleanup: bool, target: BasicBlock| {
+            let block = BasicBlockData {
+                statements: vec![],
+                is_cleanup,
+                terminator: Some(Terminator { source_info, kind: TerminatorKind::Goto { target } }),
+            };
+            let idx = cur_len + new_blocks.len();
+            new_blocks.push(block);
+            BasicBlock::new(idx)
+        };
 
         for block in body.basic_blocks_mut() {
             match block.terminator {
@@ -53,19 +63,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
                     ) || self == &AllCallEdges) =>
                 {
                     // It's a critical edge, break it
-                    let call_guard = BasicBlockData {
-                        statements: vec![],
-                        is_cleanup: block.is_cleanup,
-                        terminator: Some(Terminator {
-                            source_info,
-                            kind: TerminatorKind::Goto { target: *destination },
-                        }),
-                    };
-
-                    // Get the index it will be when inserted into the MIR
-                    let idx = cur_len + new_blocks.len();
-                    new_blocks.push(call_guard);
-                    *destination = BasicBlock::new(idx);
+                    *destination = new_block(source_info, block.is_cleanup, *destination);
                 }
                 _ => {}
             }