@@ -81,7 +81,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
8181 generics : & DelegationGenerics < Generics > ,
8282 ) -> DelegationGenerics < & ' hir hir:: Generics < ' hir > > {
8383 let mut process_params = |generics : & Option < Generics > | {
84- generics. as_ref ( ) . map ( |g| self . process_generic_params ( item_id, span, g. params . clone ( ) ) )
84+ generics
85+ . as_ref ( )
86+ . map ( |g| self . lower_delegation_generic_params ( item_id, span, g. params . clone ( ) ) )
8587 } ;
8688
8789 match generics {
@@ -95,7 +97,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9597 }
9698 }
9799
98- fn process_generic_params (
100+ fn lower_delegation_generic_params (
99101 & mut self ,
100102 item_id : NodeId ,
101103 span : Span ,
@@ -357,43 +359,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
357359 add_self : bool ,
358360 user_specified : bool ,
359361 ) -> Option < Generics > {
360- id. map ( |id| {
361- let mut generics = if user_specified {
362- Some ( Generics :: default ( ) )
363- } else {
364- if let Some ( local_id) = id. as_local ( ) {
365- if let Some ( AstOwner :: Item ( item) ) = self . ast_accessor . get ( local_id)
366- && matches ! ( item. kind, ItemKind :: Trait ( ..) )
367- {
368- item. opt_generics ( ) . cloned ( )
369- } else {
370- None
371- }
362+ let id = if let Some ( id) = id { id } else { return None } ;
363+
364+ // If args are user-specified we still maybe need to add self
365+ let mut generics = if user_specified {
366+ None
367+ } else {
368+ if let Some ( local_id) = id. as_local ( ) {
369+ if let Some ( AstOwner :: Item ( item) ) = self . ast_accessor . get ( local_id)
370+ && matches ! ( item. kind, ItemKind :: Trait ( ..) )
371+ {
372+ item. opt_generics ( ) . cloned ( )
372373 } else {
373- self . get_external_generics ( id , true )
374+ None
374375 }
375- } ;
376-
377- if add_self {
378- generics = Some ( generics. unwrap_or ( Generics :: default ( ) ) ) ;
379-
380- generics. as_mut ( ) . unwrap ( ) . params . insert (
381- 0 ,
382- GenericParam {
383- id : self . next_node_id ( ) ,
384- ident : Ident :: new ( kw:: SelfUpper , DUMMY_SP ) ,
385- attrs : Default :: default ( ) ,
386- bounds : vec ! [ ] ,
387- is_placeholder : false ,
388- kind : GenericParamKind :: Type { default : None } ,
389- colon_span : None ,
390- } ,
391- ) ;
376+ } else {
377+ self . get_external_generics ( id, true )
392378 }
379+ } ;
393380
394- generics
395- } )
396- . flatten ( )
381+ if add_self {
382+ generics = Some ( generics. unwrap_or ( Generics :: default ( ) ) ) ;
383+
384+ generics. as_mut ( ) . unwrap ( ) . params . insert (
385+ 0 ,
386+ GenericParam {
387+ id : self . next_node_id ( ) ,
388+ ident : Ident :: new ( kw:: SelfUpper , DUMMY_SP ) ,
389+ attrs : Default :: default ( ) ,
390+ bounds : vec ! [ ] ,
391+ is_placeholder : false ,
392+ kind : GenericParamKind :: Type { default : None } ,
393+ colon_span : None ,
394+ } ,
395+ ) ;
396+ }
397+
398+ generics
397399 }
398400}
399401
@@ -405,13 +407,13 @@ pub(super) enum HirOrAstGenerics<'hir> {
405407impl < ' hir > HirOrAstGenerics < ' hir > {
406408 pub ( super ) fn into_hir_generics (
407409 & mut self ,
408- this : & mut LoweringContext < ' _ , ' hir > ,
410+ ctx : & mut LoweringContext < ' _ , ' hir > ,
409411 item_id : NodeId ,
410412 span : Span ,
411413 ) -> & mut Self {
412414 match self {
413415 HirOrAstGenerics :: Ast ( delegation_generics) => {
414- * self = Self :: Hir ( this . lower_ast_generics ( item_id, span, delegation_generics) ) ;
416+ * self = Self :: Hir ( ctx . lower_ast_generics ( item_id, span, delegation_generics) ) ;
415417 }
416418 HirOrAstGenerics :: Hir ( _) => { }
417419 }
@@ -434,20 +436,17 @@ impl<'hir> HirOrAstGenerics<'hir> {
434436
435437 pub ( super ) fn into_generic_args (
436438 & self ,
437- this : & mut LoweringContext < ' _ , ' hir > ,
439+ ctx : & mut LoweringContext < ' _ , ' hir > ,
438440 add_lifetimes : bool ,
439441 ) -> Option < & ' hir hir:: GenericArgs < ' hir > > {
440442 match self {
441443 HirOrAstGenerics :: Ast ( _) => None ,
442444 HirOrAstGenerics :: Hir ( hir_generics) => match hir_generics {
443445 DelegationGenerics :: UserSpecified => None ,
444446 DelegationGenerics :: Default ( generics)
445- | DelegationGenerics :: SelfAndUserSpecified ( generics) => match generics {
446- Some ( generics) => {
447- Some ( this. create_generics_args_from_params ( generics. params , add_lifetimes) )
448- }
449- None => None ,
450- } ,
447+ | DelegationGenerics :: SelfAndUserSpecified ( generics) => generics. map ( |generics| {
448+ ctx. create_generics_args_from_params ( generics. params , add_lifetimes)
449+ } ) ,
451450 } ,
452451 }
453452 }
@@ -481,19 +480,19 @@ impl<'hir> GenericsGenerationResults<'hir> {
481480 & mut self ,
482481 item_id : NodeId ,
483482 span : Span ,
484- this : & mut LoweringContext < ' _ , ' hir > ,
483+ ctx : & mut LoweringContext < ' _ , ' hir > ,
485484 ) -> impl Iterator < Item = hir:: GenericParam < ' hir > > {
486485 let parent = self
487486 . parent
488487 . generics
489- . into_hir_generics ( this , item_id, span)
488+ . into_hir_generics ( ctx , item_id, span)
490489 . hir_generics_or_empty ( )
491490 . params ;
492491
493492 let child = self
494493 . child
495494 . generics
496- . into_hir_generics ( this , item_id, span)
495+ . into_hir_generics ( ctx , item_id, span)
497496 . hir_generics_or_empty ( )
498497 . params ;
499498
0 commit comments