@@ -1006,7 +1006,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1006
1006
match item. kind {
1007
1007
ItemKind :: TyAlias ( box TyAlias { ref generics, .. } )
1008
1008
| ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
1009
- self . compute_num_lifetime_params ( item. id , generics) ;
1010
1009
self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
1011
1010
visit:: walk_item ( this, item)
1012
1011
} ) ;
@@ -1015,7 +1014,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1015
1014
ItemKind :: Enum ( _, ref generics)
1016
1015
| ItemKind :: Struct ( _, ref generics)
1017
1016
| ItemKind :: Union ( _, ref generics) => {
1018
- self . compute_num_lifetime_params ( item. id , generics) ;
1019
1017
self . resolve_adt ( item, generics) ;
1020
1018
}
1021
1019
@@ -1026,12 +1024,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1026
1024
items : ref impl_items,
1027
1025
..
1028
1026
} ) => {
1029
- self . compute_num_lifetime_params ( item. id , generics) ;
1030
1027
self . resolve_implementation ( generics, of_trait, & self_ty, item. id , impl_items) ;
1031
1028
}
1032
1029
1033
1030
ItemKind :: Trait ( box Trait { ref generics, ref bounds, ref items, .. } ) => {
1034
- self . compute_num_lifetime_params ( item. id , generics) ;
1035
1031
// Create a new rib for the trait-wide type parameters.
1036
1032
self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
1037
1033
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> {
1083
1079
}
1084
1080
1085
1081
ItemKind :: TraitAlias ( ref generics, ref bounds) => {
1086
- self . compute_num_lifetime_params ( item. id , generics) ;
1087
1082
// Create a new rib for the trait-wide type parameters.
1088
1083
self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
1089
1084
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> {
2576
2571
Some ( ( ident. name , ns) ) ,
2577
2572
)
2578
2573
}
2574
+ }
2579
2575
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)
2588
2613
}
2589
2614
}
2590
2615
2591
2616
impl < ' a > Resolver < ' a > {
2592
2617
pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
2618
+ visit:: walk_crate ( & mut LifetimeCountVisitor { r : self } , krate) ;
2593
2619
let mut late_resolution_visitor = LateResolutionVisitor :: new ( self ) ;
2594
2620
visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
2595
2621
for ( id, span) in late_resolution_visitor. diagnostic_metadata . unused_labels . iter ( ) {
0 commit comments