11use crate :: utils:: SpanlessEq ;
22use crate :: utils:: {
3- is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, snippet , span_lint , span_lint_and_help ,
4- span_lint_and_sugg, walk_ptrs_ty,
3+ is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, run_lints , snippet , span_lint ,
4+ span_lint_and_help , span_lint_and_sugg, walk_ptrs_ty,
55} ;
66use if_chain:: if_chain;
77use rustc_ast:: ast:: { Crate as AstCrate , ItemKind , LitKind , Name , NodeId } ;
@@ -10,7 +10,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010use rustc_errors:: Applicability ;
1111use rustc_hir as hir;
1212use rustc_hir:: def:: { DefKind , Res } ;
13- use rustc_hir:: intravisit:: { walk_expr, NestedVisitorMap , Visitor } ;
13+ use rustc_hir:: hir_id:: CRATE_HIR_ID ;
14+ use rustc_hir:: intravisit:: { NestedVisitorMap , Visitor } ;
1415use rustc_hir:: { Crate , Expr , ExprKind , HirId , Item , MutTy , Mutability , Path , StmtKind , Ty , TyKind } ;
1516use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
1617use rustc_middle:: hir:: map:: Map ;
@@ -252,6 +253,10 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);
252253
253254impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for LintWithoutLintPass {
254255 fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item < ' _ > ) {
256+ if !run_lints ( cx, & [ DEFAULT_LINT ] , item. hir_id ) {
257+ return ;
258+ }
259+
255260 if let hir:: ItemKind :: Static ( ref ty, Mutability :: Not , body_id) = item. kind {
256261 if is_lint_ref_type ( cx, ty) {
257262 let expr = & cx. tcx . hir ( ) . body ( body_id) . value ;
@@ -306,6 +311,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
306311 }
307312
308313 fn check_crate_post ( & mut self , cx : & LateContext < ' a , ' tcx > , _: & ' tcx Crate < ' _ > ) {
314+ if !run_lints ( cx, & [ LINT_WITHOUT_LINT_PASS ] , CRATE_HIR_ID ) {
315+ return ;
316+ }
317+
309318 for ( lint_name, & lint_span) in & self . declared_lints {
310319 // When using the `declare_tool_lint!` macro, the original `lint_span`'s
311320 // file points to "<rustc macros>".
@@ -355,15 +364,12 @@ struct LintCollector<'a, 'tcx> {
355364impl < ' a , ' tcx > Visitor < ' tcx > for LintCollector < ' a , ' tcx > {
356365 type Map = Map < ' tcx > ;
357366
358- fn visit_expr ( & mut self , expr : & ' tcx Expr < ' _ > ) {
359- walk_expr ( self , expr) ;
360- }
361-
362367 fn visit_path ( & mut self , path : & ' tcx Path < ' _ > , _: HirId ) {
363368 if path. segments . len ( ) == 1 {
364369 self . output . insert ( path. segments [ 0 ] . ident . name ) ;
365370 }
366371 }
372+
367373 fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
368374 NestedVisitorMap :: All ( self . cx . tcx . hir ( ) )
369375 }
@@ -391,6 +397,10 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
391397
392398impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for CompilerLintFunctions {
393399 fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr < ' _ > ) {
400+ if !run_lints ( cx, & [ COMPILER_LINT_FUNCTIONS ] , expr. hir_id ) {
401+ return ;
402+ }
403+
394404 if_chain ! {
395405 if let ExprKind :: MethodCall ( ref path, _, ref args) = expr. kind;
396406 let fn_name = path. ident;
@@ -416,6 +426,10 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
416426
417427impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for OuterExpnDataPass {
418428 fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
429+ if !run_lints ( cx, & [ OUTER_EXPN_EXPN_DATA ] , expr. hir_id ) {
430+ return ;
431+ }
432+
419433 let ( method_names, arg_lists, spans) = method_calls ( expr, 2 ) ;
420434 let method_names: Vec < SymbolStr > = method_names. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
421435 let method_names: Vec < & str > = method_names. iter ( ) . map ( |s| & * * s) . collect ( ) ;
@@ -462,6 +476,10 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
462476
463477impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for CollapsibleCalls {
464478 fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
479+ if !run_lints ( cx, & [ COLLAPSIBLE_SPAN_LINT_CALLS ] , expr. hir_id ) {
480+ return ;
481+ }
482+
465483 if_chain ! {
466484 if let ExprKind :: Call ( ref func, ref and_then_args) = expr. kind;
467485 if let ExprKind :: Path ( ref path) = func. kind;
0 commit comments