@@ -352,6 +352,9 @@ pub struct LateContext<'a, 'tcx: 'a> {
352
352
lint_sess : LintSession < ' tcx , LateLintPassObject > ,
353
353
354
354
last_ast_node_with_lint_attrs : ast:: NodeId ,
355
+
356
+ /// Generic type parameters in scope for the item we are in.
357
+ pub generics : Option < & ' tcx hir:: Generics > ,
355
358
}
356
359
357
360
/// Context for lint checking of the AST, after expansion, before lowering to
@@ -646,13 +649,16 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
646
649
}
647
650
648
651
fn visit_item ( & mut self , it : & ' tcx hir:: Item ) {
652
+ let generics = self . generics . take ( ) ;
653
+ self . generics = it. node . generics ( ) ;
649
654
self . with_lint_attrs ( it. id , & it. attrs , |cx| {
650
655
cx. with_param_env ( it. id , |cx| {
651
656
run_lints ! ( cx, check_item, late_passes, it) ;
652
657
hir_visit:: walk_item ( cx, it) ;
653
658
run_lints ! ( cx, check_item_post, late_passes, it) ;
654
659
} ) ;
655
- } )
660
+ } ) ;
661
+ self . generics = generics;
656
662
}
657
663
658
664
fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem ) {
@@ -774,23 +780,29 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
774
780
}
775
781
776
782
fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem ) {
783
+ let generics = self . generics . take ( ) ;
784
+ self . generics = Some ( & trait_item. generics ) ;
777
785
self . with_lint_attrs ( trait_item. id , & trait_item. attrs , |cx| {
778
786
cx. with_param_env ( trait_item. id , |cx| {
779
787
run_lints ! ( cx, check_trait_item, late_passes, trait_item) ;
780
788
hir_visit:: walk_trait_item ( cx, trait_item) ;
781
789
run_lints ! ( cx, check_trait_item_post, late_passes, trait_item) ;
782
790
} ) ;
783
791
} ) ;
792
+ self . generics = generics;
784
793
}
785
794
786
795
fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem ) {
796
+ let generics = self . generics . take ( ) ;
797
+ self . generics = Some ( & impl_item. generics ) ;
787
798
self . with_lint_attrs ( impl_item. id , & impl_item. attrs , |cx| {
788
799
cx. with_param_env ( impl_item. id , |cx| {
789
800
run_lints ! ( cx, check_impl_item, late_passes, impl_item) ;
790
801
hir_visit:: walk_impl_item ( cx, impl_item) ;
791
802
run_lints ! ( cx, check_impl_item_post, late_passes, impl_item) ;
792
803
} ) ;
793
804
} ) ;
805
+ self . generics = generics;
794
806
}
795
807
796
808
fn visit_lifetime ( & mut self , lt : & ' tcx hir:: Lifetime ) {
@@ -991,6 +1003,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
991
1003
access_levels,
992
1004
lint_sess : LintSession :: new ( & tcx. sess . lint_store ) ,
993
1005
last_ast_node_with_lint_attrs : ast:: CRATE_NODE_ID ,
1006
+ generics : None ,
994
1007
} ;
995
1008
996
1009
// Visit the whole crate.
0 commit comments