@@ -52,7 +52,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor {
52
52
lvalue : & mut Lvalue < ' tcx > ,
53
53
context : LvalueContext < ' tcx > ,
54
54
location : Location ) {
55
- if * lvalue == Lvalue :: Local ( Local :: new ( 1 ) ) {
55
+ if * lvalue == Lvalue :: Local ( self_arg ( ) ) {
56
56
* lvalue = Lvalue :: Projection ( Box :: new ( Projection {
57
57
base : lvalue. clone ( ) ,
58
58
elem : ProjectionElem :: Deref ,
@@ -63,6 +63,10 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor {
63
63
}
64
64
}
65
65
66
+ fn self_arg ( ) -> Local {
67
+ Local :: new ( 1 )
68
+ }
69
+
66
70
struct TransformVisitor < ' a , ' tcx : ' a > {
67
71
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
68
72
state_adt_ref : & ' tcx AdtDef ,
@@ -97,7 +101,7 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
97
101
98
102
// Create a Lvalue referencing a generator struct field
99
103
fn make_field ( & self , idx : usize , ty : Ty < ' tcx > ) -> Lvalue < ' tcx > {
100
- let base = Lvalue :: Local ( Local :: new ( 1 ) ) ;
104
+ let base = Lvalue :: Local ( self_arg ( ) ) ;
101
105
let field = Projection {
102
106
base : base,
103
107
elem : ProjectionElem :: Field ( Field :: new ( idx) , ty) ,
@@ -256,7 +260,7 @@ fn locals_live_across_suspend_points<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
256
260
}
257
261
258
262
// The generator argument is ignored
259
- set. remove ( & Local :: new ( 1 ) ) ;
263
+ set. remove ( & self_arg ( ) ) ;
260
264
261
265
set
262
266
}
@@ -334,7 +338,7 @@ fn elaborate_generator_drops<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
334
338
use shim:: DropShimElaborator ;
335
339
336
340
let param_env = tcx. param_env ( def_id) ;
337
- let gen = Local :: new ( 1 ) ;
341
+ let gen = self_arg ( ) ;
338
342
339
343
for block in mir. basic_blocks ( ) . indices ( ) {
340
344
let ( target, unwind, source_info) = match mir. basic_blocks ( ) [ block] . terminator ( ) {
@@ -452,7 +456,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
452
456
make_generator_state_argument_indirect ( tcx, def_id, & mut mir) ;
453
457
454
458
// Change the generator argument from &mut to *mut
455
- mir. local_decls [ Local :: new ( 1 ) ] = LocalDecl {
459
+ mir. local_decls [ self_arg ( ) ] = LocalDecl {
456
460
mutability : Mutability :: Mut ,
457
461
ty : tcx. mk_ptr ( ty:: TypeAndMut {
458
462
ty : gen_ty,
@@ -604,7 +608,7 @@ fn insert_clean_drop<'a, 'tcx>(mir: &mut Mir<'tcx>) -> BasicBlock {
604
608
// Create a block to destroy an unresumed generators. This can only destroy upvars.
605
609
let drop_clean = BasicBlock :: new ( mir. basic_blocks ( ) . len ( ) ) ;
606
610
let term = TerminatorKind :: Drop {
607
- location : Lvalue :: Local ( Local :: new ( 1 ) ) ,
611
+ location : Lvalue :: Local ( self_arg ( ) ) ,
608
612
target : return_block,
609
613
unwind : None ,
610
614
} ;
0 commit comments