@@ -40,6 +40,16 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
40
40
let mut new_blocks = Vec :: new ( ) ;
41
41
42
42
let cur_len = body. basic_blocks . len ( ) ;
43
+ let mut new_block = |source_info : SourceInfo , is_cleanup : bool , target : BasicBlock | {
44
+ let block = BasicBlockData {
45
+ statements : vec ! [ ] ,
46
+ is_cleanup,
47
+ terminator : Some ( Terminator { source_info, kind : TerminatorKind :: Goto { target } } ) ,
48
+ } ;
49
+ let idx = cur_len + new_blocks. len ( ) ;
50
+ new_blocks. push ( block) ;
51
+ BasicBlock :: new ( idx)
52
+ } ;
43
53
44
54
for block in body. basic_blocks_mut ( ) {
45
55
match block. terminator {
@@ -53,19 +63,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
53
63
) || self == & AllCallEdges ) =>
54
64
{
55
65
// It's a critical edge, break it
56
- let call_guard = BasicBlockData {
57
- statements : vec ! [ ] ,
58
- is_cleanup : block. is_cleanup ,
59
- terminator : Some ( Terminator {
60
- source_info,
61
- kind : TerminatorKind :: Goto { target : * destination } ,
62
- } ) ,
63
- } ;
64
-
65
- // Get the index it will be when inserted into the MIR
66
- let idx = cur_len + new_blocks. len ( ) ;
67
- new_blocks. push ( call_guard) ;
68
- * destination = BasicBlock :: new ( idx) ;
66
+ * destination = new_block ( source_info, block. is_cleanup , * destination) ;
69
67
}
70
68
_ => { }
71
69
}
0 commit comments