@@ -959,7 +959,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
959
959
match item. kind {
960
960
ItemKind :: TyAlias ( box TyAlias { ref generics, .. } )
961
961
| ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
962
- self . compute_num_lifetime_params ( item. id , generics) ;
963
962
self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
964
963
visit:: walk_item ( this, item)
965
964
} ) ;
@@ -968,7 +967,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
968
967
ItemKind :: Enum ( _, ref generics)
969
968
| ItemKind :: Struct ( _, ref generics)
970
969
| ItemKind :: Union ( _, ref generics) => {
971
- self . compute_num_lifetime_params ( item. id , generics) ;
972
970
self . resolve_adt ( item, generics) ;
973
971
}
974
972
@@ -979,12 +977,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
979
977
items : ref impl_items,
980
978
..
981
979
} ) => {
982
- self . compute_num_lifetime_params ( item. id , generics) ;
983
980
self . resolve_implementation ( generics, of_trait, & self_ty, item. id , impl_items) ;
984
981
}
985
982
986
983
ItemKind :: Trait ( box Trait { ref generics, ref bounds, ref items, .. } ) => {
987
- self . compute_num_lifetime_params ( item. id , generics) ;
988
984
// Create a new rib for the trait-wide type parameters.
989
985
self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
990
986
let local_def_id = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
@@ -1036,7 +1032,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1036
1032
}
1037
1033
1038
1034
ItemKind :: TraitAlias ( ref generics, ref bounds) => {
1039
- self . compute_num_lifetime_params ( item. id , generics) ;
1040
1035
// Create a new rib for the trait-wide type parameters.
1041
1036
self . with_generic_param_rib ( generics, ItemRibKind ( HasGenericParams :: Yes ) , |this| {
1042
1037
let local_def_id = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
@@ -2501,20 +2496,51 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2501
2496
Some ( ( ident. name , ns) ) ,
2502
2497
)
2503
2498
}
2499
+ }
2504
2500
2505
- fn compute_num_lifetime_params ( & mut self , id : NodeId , generics : & Generics ) {
2506
- let def_id = self . r . local_def_id ( id) ;
2507
- let count = generics
2508
- . params
2509
- . iter ( )
2510
- . filter ( |param| matches ! ( param. kind, ast:: GenericParamKind :: Lifetime { .. } ) )
2511
- . count ( ) ;
2512
- self . r . item_generics_num_lifetimes . insert ( def_id, count) ;
2501
+ struct LifetimeCountVisitor < ' a , ' b > {
2502
+ r : & ' b mut Resolver < ' a > ,
2503
+ }
2504
+
2505
+ /// Walks the whole crate in DFS order, visiting each item, counting the declared number of
2506
+ /// lifetime generic parameters.
2507
+ impl < ' ast > Visitor < ' ast > for LifetimeCountVisitor < ' _ , ' _ > {
2508
+ fn visit_item ( & mut self , item : & ' ast Item ) {
2509
+ match & item. kind {
2510
+ ItemKind :: TyAlias ( box TyAlias { ref generics, .. } )
2511
+ | ItemKind :: Fn ( box Fn { ref generics, .. } )
2512
+ | ItemKind :: Enum ( _, ref generics)
2513
+ | ItemKind :: Struct ( _, ref generics)
2514
+ | ItemKind :: Union ( _, ref generics)
2515
+ | ItemKind :: Impl ( box Impl { ref generics, .. } )
2516
+ | ItemKind :: Trait ( box Trait { ref generics, .. } )
2517
+ | ItemKind :: TraitAlias ( ref generics, _) => {
2518
+ let def_id = self . r . local_def_id ( item. id ) ;
2519
+ let count = generics
2520
+ . params
2521
+ . iter ( )
2522
+ . filter ( |param| matches ! ( param. kind, ast:: GenericParamKind :: Lifetime { .. } ) )
2523
+ . count ( ) ;
2524
+ self . r . item_generics_num_lifetimes . insert ( def_id, count) ;
2525
+ }
2526
+
2527
+ ItemKind :: Mod ( ..)
2528
+ | ItemKind :: ForeignMod ( ..)
2529
+ | ItemKind :: Static ( ..)
2530
+ | ItemKind :: Const ( ..)
2531
+ | ItemKind :: Use ( ..)
2532
+ | ItemKind :: ExternCrate ( ..)
2533
+ | ItemKind :: MacroDef ( ..)
2534
+ | ItemKind :: GlobalAsm ( ..)
2535
+ | ItemKind :: MacCall ( ..) => { }
2536
+ }
2537
+ visit:: walk_item ( self , item)
2513
2538
}
2514
2539
}
2515
2540
2516
2541
impl < ' a > Resolver < ' a > {
2517
2542
pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
2543
+ visit:: walk_crate ( & mut LifetimeCountVisitor { r : self } , krate) ;
2518
2544
let mut late_resolution_visitor = LateResolutionVisitor :: new ( self ) ;
2519
2545
visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
2520
2546
for ( id, span) in late_resolution_visitor. diagnostic_metadata . unused_labels . iter ( ) {
0 commit comments