@@ -40,6 +40,16 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
4040 let mut new_blocks = Vec :: new ( ) ;
4141
4242 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+ } ;
4353
4454 for block in body. basic_blocks_mut ( ) {
4555 match block. terminator {
@@ -53,19 +63,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
5363 ) || self == & AllCallEdges ) =>
5464 {
5565 // 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) ;
6967 }
7068 _ => { }
7169 }
0 commit comments