@@ -6,7 +6,7 @@ use rustc_hir::def_id::DefId;
66use rustc_middle:: ty:: GenericParamDefKind ;
77use rustc_middle:: { bug, ty} ;
88use rustc_span:: symbol:: kw;
9- use rustc_span:: { Ident , Span , Symbol } ;
9+ use rustc_span:: { Ident , Span , sym } ;
1010
1111use crate :: { LoweringContext , ResolverAstLoweringExt } ;
1212
@@ -115,9 +115,8 @@ impl<'hir> HirOrTyGenerics<'hir> {
115115 ctx : & mut LoweringContext < ' _ , ' hir , impl ResolverAstLoweringExt < ' hir > > ,
116116 span : Span ,
117117 ) -> & mut HirOrTyGenerics < ' hir > {
118- let rename_self = matches ! ( self . position( ) , GenericsPosition :: Child ) ;
119-
120118 if let HirOrTyGenerics :: Ty ( ty) = self {
119+ let rename_self = matches ! ( ty. pos, GenericsPosition :: Child ) ;
121120 let params = ctx. uplift_delegation_generic_params ( span, ty. generics , rename_self) ;
122121
123122 * self = HirOrTyGenerics :: Hir ( DelegationGenerics {
@@ -147,7 +146,7 @@ impl<'hir> HirOrTyGenerics<'hir> {
147146 bug ! ( "Attempting to get generic args before uplifting to HIR" )
148147 }
149148 HirOrTyGenerics :: Hir ( hir) => {
150- let add_lifetimes = matches ! ( self . position ( ) , GenericsPosition :: Parent ) ;
149+ let add_lifetimes = matches ! ( hir . pos , GenericsPosition :: Parent ) ;
151150 ctx. create_generics_args_from_params ( hir. generics . params , add_lifetimes, span)
152151 }
153152 }
@@ -159,13 +158,6 @@ impl<'hir> HirOrTyGenerics<'hir> {
159158 HirOrTyGenerics :: Hir ( hir) => hir. kind . args_propagation_details ( ) ,
160159 }
161160 }
162-
163- pub ( super ) fn position ( & self ) -> GenericsPosition {
164- match self {
165- HirOrTyGenerics :: Ty ( ty) => ty. pos ,
166- HirOrTyGenerics :: Hir ( hir) => hir. pos ,
167- }
168- }
169161}
170162
171163impl < ' hir > GenericsGenerationResult < ' hir > {
@@ -341,14 +333,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
341333 // applies to traits, `trait Trait<Self> {}` will be represented as
342334 // `trait Trait {}` in HIR and "unexpected keyword `Self` in generic parameters"
343335 // error will be emitted.
344- // Note that we do not rename `Self` to `This` after first reuse from Trait,
345- // in this case the Self should not be propagated
336+ // Note that we do not rename `Self` to `This` after non-recursive reuse
337+ // from Trait, in this case the `Self` should not be propagated
338+ // (we rely that implicit `Self` generic param of a trait is named "Self")
346339 // and it is OK to have Self generic param generated during lowering.
347- let param_name = if rename_self && p. name == kw:: SelfUpper {
348- Symbol :: intern ( & format ! ( "This" ) )
349- } else {
350- p. name
351- } ;
340+ let param_name =
341+ if rename_self && p. name == kw:: SelfUpper { sym:: This } else { p. name } ;
352342
353343 let param_ident = Ident :: new ( param_name, span) ;
354344 let def_name = Some ( param_ident. name ) ;
0 commit comments