@@ -107,15 +107,15 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
107107 }
108108
109109 fn visit_local ( & mut self , local : & mut Local , _: PlaceContext , _: Location ) {
110- assert_ne ! ( * local, self_arg ( ) ) ;
110+ assert_ne ! ( * local, SELF_ARG ) ;
111111 }
112112
113113 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 {
115115 replace_base (
116116 place,
117117 Place {
118- local : self_arg ( ) ,
118+ local : SELF_ARG ,
119119 projection : self . tcx ( ) . intern_place_elems ( & [ ProjectionElem :: Deref ] ) ,
120120 } ,
121121 self . tcx ,
@@ -125,7 +125,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
125125
126126 for elem in place. projection . iter ( ) {
127127 if let PlaceElem :: Index ( local) = elem {
128- assert_ne ! ( * local, self_arg ( ) ) ;
128+ assert_ne ! ( * local, SELF_ARG ) ;
129129 }
130130 }
131131 }
@@ -143,15 +143,15 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
143143 }
144144
145145 fn visit_local ( & mut self , local : & mut Local , _: PlaceContext , _: Location ) {
146- assert_ne ! ( * local, self_arg ( ) ) ;
146+ assert_ne ! ( * local, SELF_ARG ) ;
147147 }
148148
149149 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 {
151151 replace_base (
152152 place,
153153 Place {
154- local : self_arg ( ) ,
154+ local : SELF_ARG ,
155155 projection : self . tcx ( ) . intern_place_elems ( & [ ProjectionElem :: Field (
156156 Field :: new ( 0 ) ,
157157 self . ref_gen_ty ,
@@ -164,7 +164,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
164164
165165 for elem in place. projection . iter ( ) {
166166 if let PlaceElem :: Index ( local) = elem {
167- assert_ne ! ( * local, self_arg ( ) ) ;
167+ assert_ne ! ( * local, SELF_ARG ) ;
168168 }
169169 }
170170 }
@@ -180,9 +180,7 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx
180180 place. projection = tcx. intern_place_elems ( & new_projection) ;
181181}
182182
183- fn self_arg ( ) -> Local {
184- Local :: new ( 1 )
185- }
183+ const SELF_ARG : Local = Local :: from_u32 ( 1 ) ;
186184
187185/// Generator has not been resumed yet.
188186const UNRESUMED : usize = GeneratorSubsts :: UNRESUMED ;
@@ -237,7 +235,7 @@ impl TransformVisitor<'tcx> {
237235
238236 // Create a Place referencing a generator struct field
239237 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 ) ;
241239 let base = self . tcx . mk_place_downcast_unnamed ( self_place, variant_index) ;
242240 let mut projection = base. projection . to_vec ( ) ;
243241 projection. push ( ProjectionElem :: Field ( Field :: new ( idx) , ty) ) ;
@@ -247,7 +245,7 @@ impl TransformVisitor<'tcx> {
247245
248246 // Create a statement which changes the discriminant
249247 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 ) ;
251249 Statement {
252250 source_info,
253251 kind : StatementKind :: SetDiscriminant {
@@ -263,7 +261,7 @@ impl TransformVisitor<'tcx> {
263261 let local_decls_len = body. local_decls . push ( temp_decl) ;
264262 let temp = Place :: from ( local_decls_len) ;
265263
266- let self_place = Place :: from ( self_arg ( ) ) ;
264+ let self_place = Place :: from ( SELF_ARG ) ;
267265 let assign = Statement {
268266 source_info : source_info ( body) ,
269267 kind : StatementKind :: Assign ( box ( temp, Rvalue :: Discriminant ( self_place) ) ) ,
@@ -540,7 +538,7 @@ fn locals_live_across_suspend_points(
540538 live_locals_here. intersect ( & liveness. outs [ block] ) ;
541539
542540 // The generator argument is ignored.
543- live_locals_here. remove ( self_arg ( ) ) ;
541+ live_locals_here. remove ( SELF_ARG ) ;
544542
545543 debug ! ( "loc = {:?}, live_locals_here = {:?}" , loc, live_locals_here) ;
546544
@@ -837,15 +835,14 @@ fn elaborate_generator_drops<'tcx>(
837835 // generator's resume function.
838836
839837 let param_env = tcx. param_env ( def_id) ;
840- let gen = self_arg ( ) ;
841838
842839 let mut elaborator = DropShimElaborator { body, patch : MirPatch :: new ( body) , tcx, param_env } ;
843840
844841 for ( block, block_data) in body. basic_blocks ( ) . iter_enumerated ( ) {
845842 let ( target, unwind, source_info) = match block_data. terminator ( ) {
846843 Terminator { source_info, kind : TerminatorKind :: Drop { location, target, unwind } } => {
847844 if let Some ( local) = location. as_local ( ) {
848- if local == gen {
845+ if local == SELF_ARG {
849846 ( target, unwind, source_info)
850847 } else {
851848 continue ;
@@ -864,7 +861,7 @@ fn elaborate_generator_drops<'tcx>(
864861 elaborate_drop (
865862 & mut elaborator,
866863 * source_info,
867- & Place :: from ( gen ) ,
864+ & Place :: from ( SELF_ARG ) ,
868865 ( ) ,
869866 * target,
870867 unwind,
@@ -918,7 +915,7 @@ fn create_generator_drop_shim<'tcx>(
918915 make_generator_state_argument_indirect ( tcx, def_id, & mut body) ;
919916
920917 // Change the generator argument from &mut to *mut
921- body. local_decls [ self_arg ( ) ] = LocalDecl {
918+ body. local_decls [ SELF_ARG ] = LocalDecl {
922919 mutability : Mutability :: Mut ,
923920 ty : tcx. mk_ptr ( ty:: TypeAndMut { ty : gen_ty, mutbl : hir:: Mutability :: Mut } ) ,
924921 user_ty : UserTypeProjections :: none ( ) ,
@@ -933,7 +930,7 @@ fn create_generator_drop_shim<'tcx>(
933930 0 ,
934931 Statement {
935932 source_info,
936- kind : StatementKind :: Retag ( RetagKind :: Raw , box Place :: from ( self_arg ( ) ) ) ,
933+ kind : StatementKind :: Retag ( RetagKind :: Raw , box Place :: from ( SELF_ARG ) ) ,
937934 } ,
938935 )
939936 }
@@ -1042,7 +1039,7 @@ fn insert_clean_drop(body: &mut BodyAndCache<'_>) -> BasicBlock {
10421039 // Create a block to destroy an unresumed generators. This can only destroy upvars.
10431040 let drop_clean = BasicBlock :: new ( body. basic_blocks ( ) . len ( ) ) ;
10441041 let term = TerminatorKind :: Drop {
1045- location : Place :: from ( self_arg ( ) ) ,
1042+ location : Place :: from ( SELF_ARG ) ,
10461043 target : return_block,
10471044 unwind : None ,
10481045 } ;
0 commit comments