@@ -45,7 +45,6 @@ use syntax_pos::Span;
45
45
use errors:: DiagnosticBuilder ;
46
46
use hir;
47
47
use hir:: intravisit as hir_visit;
48
- use hir:: intravisit:: { IdVisitor , IdVisitingOperation } ;
49
48
use syntax:: visit as ast_visit;
50
49
51
50
/// Information about the registered lints.
@@ -663,9 +662,11 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
663
662
}
664
663
665
664
fn visit_ids < F > ( & mut self , f : F )
666
- where F : FnOnce ( & mut IdVisitor < LateContext > )
665
+ where F : FnOnce ( & mut IdVisitor )
667
666
{
668
- let mut v = IdVisitor :: new ( self ) ;
667
+ let mut v = IdVisitor {
668
+ cx : self
669
+ } ;
669
670
f ( & mut v) ;
670
671
}
671
672
}
@@ -779,7 +780,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
779
780
fn visit_fn ( & mut self , fk : hir_visit:: FnKind < ' v > , decl : & ' v hir:: FnDecl ,
780
781
body : & ' v hir:: Block , span : Span , id : ast:: NodeId ) {
781
782
run_lints ! ( self , check_fn, late_passes, fk, decl, body, span, id) ;
782
- hir_visit:: walk_fn ( self , fk, decl, body, span) ;
783
+ hir_visit:: walk_fn ( self , fk, decl, body, span, id ) ;
783
784
run_lints ! ( self , check_fn_post, late_passes, fk, decl, body, span, id) ;
784
785
}
785
786
@@ -820,7 +821,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
820
821
821
822
fn visit_mod ( & mut self , m : & hir:: Mod , s : Span , n : ast:: NodeId ) {
822
823
run_lints ! ( self , check_mod, late_passes, m, s, n) ;
823
- hir_visit:: walk_mod ( self , m) ;
824
+ hir_visit:: walk_mod ( self , m, n ) ;
824
825
run_lints ! ( self , check_mod_post, late_passes, m, s, n) ;
825
826
}
826
827
@@ -859,7 +860,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
859
860
fn visit_trait_item ( & mut self , trait_item : & hir:: TraitItem ) {
860
861
self . with_lint_attrs ( & trait_item. attrs , |cx| {
861
862
run_lints ! ( cx, check_trait_item, late_passes, trait_item) ;
862
- cx. visit_ids ( |v| v . visit_trait_item ( trait_item) ) ;
863
+ cx. visit_ids ( |v| hir_visit :: walk_trait_item ( v , trait_item) ) ;
863
864
hir_visit:: walk_trait_item ( cx, trait_item) ;
864
865
run_lints ! ( cx, check_trait_item_post, late_passes, trait_item) ;
865
866
} ) ;
@@ -868,7 +869,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
868
869
fn visit_impl_item ( & mut self , impl_item : & hir:: ImplItem ) {
869
870
self . with_lint_attrs ( & impl_item. attrs , |cx| {
870
871
run_lints ! ( cx, check_impl_item, late_passes, impl_item) ;
871
- cx. visit_ids ( |v| v . visit_impl_item ( impl_item) ) ;
872
+ cx. visit_ids ( |v| hir_visit :: walk_impl_item ( v , impl_item) ) ;
872
873
hir_visit:: walk_impl_item ( cx, impl_item) ;
873
874
run_lints ! ( cx, check_impl_item_post, late_passes, impl_item) ;
874
875
} ) ;
@@ -1046,16 +1047,30 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
1046
1047
}
1047
1048
}
1048
1049
1050
+ struct IdVisitor < ' a , ' b : ' a , ' tcx : ' a +' b > {
1051
+ cx : & ' a mut LateContext < ' b , ' tcx >
1052
+ }
1053
+
1049
1054
// Output any lints that were previously added to the session.
1050
- impl < ' a , ' tcx > IdVisitingOperation for LateContext < ' a , ' tcx > {
1055
+ impl < ' a , ' b , ' tcx , ' v > hir_visit:: Visitor < ' v > for IdVisitor < ' a , ' b , ' tcx > {
1056
+
1051
1057
fn visit_id ( & mut self , id : ast:: NodeId ) {
1052
- if let Some ( lints) = self . sess ( ) . lints . borrow_mut ( ) . remove ( & id) {
1058
+ if let Some ( lints) = self . cx . sess ( ) . lints . borrow_mut ( ) . remove ( & id) {
1053
1059
debug ! ( "LateContext::visit_id: id={:?} lints={:?}" , id, lints) ;
1054
1060
for ( lint_id, span, msg) in lints {
1055
- self . span_lint ( lint_id. lint , span, & msg[ ..] )
1061
+ self . cx . span_lint ( lint_id. lint , span, & msg[ ..] )
1056
1062
}
1057
1063
}
1058
1064
}
1065
+
1066
+ fn visit_trait_item ( & mut self , _ti : & hir:: TraitItem ) {
1067
+ // Do not recurse into trait or impl items automatically. These are
1068
+ // processed separately by calling hir_visit::walk_trait_item()
1069
+ }
1070
+
1071
+ fn visit_impl_item ( & mut self , _ii : & hir:: ImplItem ) {
1072
+ // See visit_trait_item()
1073
+ }
1059
1074
}
1060
1075
1061
1076
enum CheckLintNameResult {
@@ -1172,7 +1187,6 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1172
1187
1173
1188
// Visit the whole crate.
1174
1189
cx. with_lint_attrs ( & krate. attrs , |cx| {
1175
- cx. visit_id ( ast:: CRATE_NODE_ID ) ;
1176
1190
cx. visit_ids ( |v| {
1177
1191
hir_visit:: walk_crate ( v, krate) ;
1178
1192
} ) ;
0 commit comments