@@ -1006,7 +1006,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10061006 match item. kind {
10071007 ItemKind :: TyAlias ( box TyAlias { ref generics, .. } )
10081008 | ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
1009- self . compute_num_lifetime_params ( item. id , generics) ;
10101009 self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
10111010 visit:: walk_item ( this, item)
10121011 } ) ;
@@ -1015,7 +1014,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10151014 ItemKind :: Enum ( _, ref generics)
10161015 | ItemKind :: Struct ( _, ref generics)
10171016 | ItemKind :: Union ( _, ref generics) => {
1018- self . compute_num_lifetime_params ( item. id , generics) ;
10191017 self . resolve_adt ( item, generics) ;
10201018 }
10211019
@@ -1026,12 +1024,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10261024 items : ref impl_items,
10271025 ..
10281026 } ) => {
1029- self . compute_num_lifetime_params ( item. id , generics) ;
10301027 self . resolve_implementation ( generics, of_trait, & self_ty, item. id , impl_items) ;
10311028 }
10321029
10331030 ItemKind :: Trait ( box Trait { ref generics, ref bounds, ref items, .. } ) => {
1034- self . compute_num_lifetime_params ( item. id , generics) ;
10351031 // Create a new rib for the trait-wide type parameters.
10361032 self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
10371033 let def = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
@@ -1083,7 +1079,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10831079 }
10841080
10851081 ItemKind :: TraitAlias ( ref generics, ref bounds) => {
1086- self . compute_num_lifetime_params ( item. id , generics) ;
10871082 // Create a new rib for the trait-wide type parameters.
10881083 self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
10891084 let def = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
@@ -2576,20 +2571,51 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
25762571 Some ( ( ident. name , ns) ) ,
25772572 )
25782573 }
2574+ }
25792575
2580- fn compute_num_lifetime_params ( & mut self , id : NodeId , generics : & Generics ) {
2581- let def_id = self . r . local_def_id ( id) ;
2582- let count = generics
2583- . params
2584- . iter ( )
2585- . filter ( |param| matches ! ( param. kind, ast:: GenericParamKind :: Lifetime { .. } ) )
2586- . count ( ) ;
2587- self . r . item_generics_num_lifetimes . insert ( def_id, count) ;
2576+ struct LifetimeCountVisitor < ' a , ' b > {
2577+ r : & ' b mut Resolver < ' a > ,
2578+ }
2579+
2580+ /// Walks the whole crate in DFS order, visiting each item, counting the declared number of
2581+ /// lifetime generic parameters.
2582+ impl < ' ast > Visitor < ' ast > for LifetimeCountVisitor < ' _ , ' _ > {
2583+ fn visit_item ( & mut self , item : & ' ast Item ) {
2584+ match & item. kind {
2585+ ItemKind :: TyAlias ( box TyAlias { ref generics, .. } )
2586+ | ItemKind :: Fn ( box Fn { ref generics, .. } )
2587+ | ItemKind :: Enum ( _, ref generics)
2588+ | ItemKind :: Struct ( _, ref generics)
2589+ | ItemKind :: Union ( _, ref generics)
2590+ | ItemKind :: Impl ( box Impl { ref generics, .. } )
2591+ | ItemKind :: Trait ( box Trait { ref generics, .. } )
2592+ | ItemKind :: TraitAlias ( ref generics, _) => {
2593+ let def_id = self . r . local_def_id ( item. id ) ;
2594+ let count = generics
2595+ . params
2596+ . iter ( )
2597+ . filter ( |param| matches ! ( param. kind, ast:: GenericParamKind :: Lifetime { .. } ) )
2598+ . count ( ) ;
2599+ self . r . item_generics_num_lifetimes . insert ( def_id, count) ;
2600+ }
2601+
2602+ ItemKind :: Mod ( ..)
2603+ | ItemKind :: ForeignMod ( ..)
2604+ | ItemKind :: Static ( ..)
2605+ | ItemKind :: Const ( ..)
2606+ | ItemKind :: Use ( ..)
2607+ | ItemKind :: ExternCrate ( ..)
2608+ | ItemKind :: MacroDef ( ..)
2609+ | ItemKind :: GlobalAsm ( ..)
2610+ | ItemKind :: MacCall ( ..) => { }
2611+ }
2612+ visit:: walk_item ( self , item)
25882613 }
25892614}
25902615
25912616impl < ' a > Resolver < ' a > {
25922617 pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
2618+ visit:: walk_crate ( & mut LifetimeCountVisitor { r : self } , krate) ;
25932619 let mut late_resolution_visitor = LateResolutionVisitor :: new ( self ) ;
25942620 visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
25952621 for ( id, span) in late_resolution_visitor. diagnostic_metadata . unused_labels . iter ( ) {
0 commit comments