@@ -107,15 +107,15 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
107
107
}
108
108
109
109
fn visit_local ( & mut self , local : & mut Local , _: PlaceContext , _: Location ) {
110
- assert_ne ! ( * local, self_arg ( ) ) ;
110
+ assert_ne ! ( * local, SELF_ARG ) ;
111
111
}
112
112
113
113
fn visit_place ( & mut self , place : & mut Place < ' tcx > , context : PlaceContext , location : Location ) {
114
- if place. local == self_arg ( ) {
114
+ if place. local == SELF_ARG {
115
115
replace_base (
116
116
place,
117
117
Place {
118
- local : self_arg ( ) ,
118
+ local : SELF_ARG ,
119
119
projection : self . tcx ( ) . intern_place_elems ( & [ ProjectionElem :: Deref ] ) ,
120
120
} ,
121
121
self . tcx ,
@@ -125,7 +125,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
125
125
126
126
for elem in place. projection . iter ( ) {
127
127
if let PlaceElem :: Index ( local) = elem {
128
- assert_ne ! ( * local, self_arg ( ) ) ;
128
+ assert_ne ! ( * local, SELF_ARG ) ;
129
129
}
130
130
}
131
131
}
@@ -143,15 +143,15 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
143
143
}
144
144
145
145
fn visit_local ( & mut self , local : & mut Local , _: PlaceContext , _: Location ) {
146
- assert_ne ! ( * local, self_arg ( ) ) ;
146
+ assert_ne ! ( * local, SELF_ARG ) ;
147
147
}
148
148
149
149
fn visit_place ( & mut self , place : & mut Place < ' tcx > , context : PlaceContext , location : Location ) {
150
- if place. local == self_arg ( ) {
150
+ if place. local == SELF_ARG {
151
151
replace_base (
152
152
place,
153
153
Place {
154
- local : self_arg ( ) ,
154
+ local : SELF_ARG ,
155
155
projection : self . tcx ( ) . intern_place_elems ( & [ ProjectionElem :: Field (
156
156
Field :: new ( 0 ) ,
157
157
self . ref_gen_ty ,
@@ -164,7 +164,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
164
164
165
165
for elem in place. projection . iter ( ) {
166
166
if let PlaceElem :: Index ( local) = elem {
167
- assert_ne ! ( * local, self_arg ( ) ) ;
167
+ assert_ne ! ( * local, SELF_ARG ) ;
168
168
}
169
169
}
170
170
}
@@ -180,9 +180,7 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx
180
180
place. projection = tcx. intern_place_elems ( & new_projection) ;
181
181
}
182
182
183
- fn self_arg ( ) -> Local {
184
- Local :: new ( 1 )
185
- }
183
+ const SELF_ARG : Local = Local :: from_u32 ( 1 ) ;
186
184
187
185
/// Generator has not been resumed yet.
188
186
const UNRESUMED : usize = GeneratorSubsts :: UNRESUMED ;
@@ -237,7 +235,7 @@ impl TransformVisitor<'tcx> {
237
235
238
236
// Create a Place referencing a generator struct field
239
237
fn make_field ( & self , variant_index : VariantIdx , idx : usize , ty : Ty < ' tcx > ) -> Place < ' tcx > {
240
- let self_place = Place :: from ( self_arg ( ) ) ;
238
+ let self_place = Place :: from ( SELF_ARG ) ;
241
239
let base = self . tcx . mk_place_downcast_unnamed ( self_place, variant_index) ;
242
240
let mut projection = base. projection . to_vec ( ) ;
243
241
projection. push ( ProjectionElem :: Field ( Field :: new ( idx) , ty) ) ;
@@ -247,7 +245,7 @@ impl TransformVisitor<'tcx> {
247
245
248
246
// Create a statement which changes the discriminant
249
247
fn set_discr ( & self , state_disc : VariantIdx , source_info : SourceInfo ) -> Statement < ' tcx > {
250
- let self_place = Place :: from ( self_arg ( ) ) ;
248
+ let self_place = Place :: from ( SELF_ARG ) ;
251
249
Statement {
252
250
source_info,
253
251
kind : StatementKind :: SetDiscriminant {
@@ -263,7 +261,7 @@ impl TransformVisitor<'tcx> {
263
261
let local_decls_len = body. local_decls . push ( temp_decl) ;
264
262
let temp = Place :: from ( local_decls_len) ;
265
263
266
- let self_place = Place :: from ( self_arg ( ) ) ;
264
+ let self_place = Place :: from ( SELF_ARG ) ;
267
265
let assign = Statement {
268
266
source_info : source_info ( body) ,
269
267
kind : StatementKind :: Assign ( box ( temp, Rvalue :: Discriminant ( self_place) ) ) ,
@@ -540,7 +538,7 @@ fn locals_live_across_suspend_points(
540
538
live_locals_here. intersect ( & liveness. outs [ block] ) ;
541
539
542
540
// The generator argument is ignored.
543
- live_locals_here. remove ( self_arg ( ) ) ;
541
+ live_locals_here. remove ( SELF_ARG ) ;
544
542
545
543
debug ! ( "loc = {:?}, live_locals_here = {:?}" , loc, live_locals_here) ;
546
544
@@ -837,15 +835,14 @@ fn elaborate_generator_drops<'tcx>(
837
835
// generator's resume function.
838
836
839
837
let param_env = tcx. param_env ( def_id) ;
840
- let gen = self_arg ( ) ;
841
838
842
839
let mut elaborator = DropShimElaborator { body, patch : MirPatch :: new ( body) , tcx, param_env } ;
843
840
844
841
for ( block, block_data) in body. basic_blocks ( ) . iter_enumerated ( ) {
845
842
let ( target, unwind, source_info) = match block_data. terminator ( ) {
846
843
Terminator { source_info, kind : TerminatorKind :: Drop { location, target, unwind } } => {
847
844
if let Some ( local) = location. as_local ( ) {
848
- if local == gen {
845
+ if local == SELF_ARG {
849
846
( target, unwind, source_info)
850
847
} else {
851
848
continue ;
@@ -864,7 +861,7 @@ fn elaborate_generator_drops<'tcx>(
864
861
elaborate_drop (
865
862
& mut elaborator,
866
863
* source_info,
867
- & Place :: from ( gen ) ,
864
+ & Place :: from ( SELF_ARG ) ,
868
865
( ) ,
869
866
* target,
870
867
unwind,
@@ -918,7 +915,7 @@ fn create_generator_drop_shim<'tcx>(
918
915
make_generator_state_argument_indirect ( tcx, def_id, & mut body) ;
919
916
920
917
// Change the generator argument from &mut to *mut
921
- body. local_decls [ self_arg ( ) ] = LocalDecl {
918
+ body. local_decls [ SELF_ARG ] = LocalDecl {
922
919
mutability : Mutability :: Mut ,
923
920
ty : tcx. mk_ptr ( ty:: TypeAndMut { ty : gen_ty, mutbl : hir:: Mutability :: Mut } ) ,
924
921
user_ty : UserTypeProjections :: none ( ) ,
@@ -933,7 +930,7 @@ fn create_generator_drop_shim<'tcx>(
933
930
0 ,
934
931
Statement {
935
932
source_info,
936
- kind : StatementKind :: Retag ( RetagKind :: Raw , box Place :: from ( self_arg ( ) ) ) ,
933
+ kind : StatementKind :: Retag ( RetagKind :: Raw , box Place :: from ( SELF_ARG ) ) ,
937
934
} ,
938
935
)
939
936
}
@@ -1042,7 +1039,7 @@ fn insert_clean_drop(body: &mut BodyAndCache<'_>) -> BasicBlock {
1042
1039
// Create a block to destroy an unresumed generators. This can only destroy upvars.
1043
1040
let drop_clean = BasicBlock :: new ( body. basic_blocks ( ) . len ( ) ) ;
1044
1041
let term = TerminatorKind :: Drop {
1045
- location : Place :: from ( self_arg ( ) ) ,
1042
+ location : Place :: from ( SELF_ARG ) ,
1046
1043
target : return_block,
1047
1044
unwind : None ,
1048
1045
} ;
0 commit comments