@@ -35,6 +35,9 @@ use rustc_middle::mir::*;
35
35
use rustc_middle:: ty:: { self , DebruijnIndex , TyS , TypeFlags } ;
36
36
use rustc_span:: { self , BytePos , Pos , Span , DUMMY_SP } ;
37
37
38
+ // All `TEMP_BLOCK` targets should be replaced before calling `to_body() -> mir::Body`.
39
+ const TEMP_BLOCK : BasicBlock = BasicBlock :: MAX ;
40
+
38
41
fn dummy_ty ( ) -> & ' static TyS < ' static > {
39
42
thread_local ! {
40
43
static DUMMY_TYS : & ' static TyS <' static > = Box :: leak( box TyS :: make_for_test(
@@ -123,7 +126,7 @@ impl<'tcx> MockBlocks<'tcx> {
123
126
if branch_index > branches. len ( ) {
124
127
branches. push ( ( branches. len ( ) as u128 , old_otherwise) ) ;
125
128
while branches. len ( ) < branch_index {
126
- branches. push ( ( branches. len ( ) as u128 , START_BLOCK ) ) ;
129
+ branches. push ( ( branches. len ( ) as u128 , TEMP_BLOCK ) ) ;
127
130
}
128
131
to_block
129
132
} else {
@@ -143,7 +146,7 @@ impl<'tcx> MockBlocks<'tcx> {
143
146
TerminatorKind :: Call {
144
147
func : Operand :: Copy ( self . dummy_place . clone ( ) ) ,
145
148
args : vec ! [ ] ,
146
- destination : Some ( ( self . dummy_place . clone ( ) , START_BLOCK ) ) ,
149
+ destination : Some ( ( self . dummy_place . clone ( ) , TEMP_BLOCK ) ) ,
147
150
cleanup : None ,
148
151
from_hir_call : false ,
149
152
fn_span : DUMMY_SP ,
@@ -152,16 +155,14 @@ impl<'tcx> MockBlocks<'tcx> {
152
155
}
153
156
154
157
fn goto ( & mut self , some_from_block : Option < BasicBlock > ) -> BasicBlock {
155
- self . add_block_from ( some_from_block, TerminatorKind :: Goto { target : START_BLOCK } )
158
+ self . add_block_from ( some_from_block, TerminatorKind :: Goto { target : TEMP_BLOCK } )
156
159
}
157
160
158
161
fn switchint ( & mut self , some_from_block : Option < BasicBlock > ) -> BasicBlock {
159
- let move_ = |place : Place < ' tcx > | Operand :: Move ( place) ;
160
- let discriminant = Place :: from ( self . new_temp ( ) ) ;
161
162
let switchint_kind = TerminatorKind :: SwitchInt {
162
- discr : move_ ( discriminant ) ,
163
+ discr : Operand :: Move ( Place :: from ( self . new_temp ( ) ) ) ,
163
164
switch_ty : dummy_ty ( ) ,
164
- targets : SwitchTargets :: static_if ( 0 , START_BLOCK , START_BLOCK ) ,
165
+ targets : SwitchTargets :: static_if ( 0 , TEMP_BLOCK , TEMP_BLOCK ) ,
165
166
} ;
166
167
self . add_block_from ( some_from_block, switchint_kind)
167
168
}
0 commit comments