1
1
use crate :: utils:: SpanlessEq ;
2
2
use 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,
5
5
} ;
6
6
use if_chain:: if_chain;
7
7
use rustc_ast:: ast:: { Crate as AstCrate , ItemKind , LitKind , Name , NodeId } ;
@@ -10,7 +10,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10
10
use rustc_errors:: Applicability ;
11
11
use rustc_hir as hir;
12
12
use 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 } ;
14
15
use rustc_hir:: { Crate , Expr , ExprKind , HirId , Item , MutTy , Mutability , Path , StmtKind , Ty , TyKind } ;
15
16
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
16
17
use rustc_middle:: hir:: map:: Map ;
@@ -252,6 +253,10 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);
252
253
253
254
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for LintWithoutLintPass {
254
255
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
+
255
260
if let hir:: ItemKind :: Static ( ref ty, Mutability :: Not , body_id) = item. kind {
256
261
if is_lint_ref_type ( cx, ty) {
257
262
let expr = & cx. tcx . hir ( ) . body ( body_id) . value ;
@@ -306,6 +311,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
306
311
}
307
312
308
313
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
+
309
318
for ( lint_name, & lint_span) in & self . declared_lints {
310
319
// When using the `declare_tool_lint!` macro, the original `lint_span`'s
311
320
// file points to "<rustc macros>".
@@ -355,15 +364,12 @@ struct LintCollector<'a, 'tcx> {
355
364
impl < ' a , ' tcx > Visitor < ' tcx > for LintCollector < ' a , ' tcx > {
356
365
type Map = Map < ' tcx > ;
357
366
358
- fn visit_expr ( & mut self , expr : & ' tcx Expr < ' _ > ) {
359
- walk_expr ( self , expr) ;
360
- }
361
-
362
367
fn visit_path ( & mut self , path : & ' tcx Path < ' _ > , _: HirId ) {
363
368
if path. segments . len ( ) == 1 {
364
369
self . output . insert ( path. segments [ 0 ] . ident . name ) ;
365
370
}
366
371
}
372
+
367
373
fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
368
374
NestedVisitorMap :: All ( self . cx . tcx . hir ( ) )
369
375
}
@@ -391,6 +397,10 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
391
397
392
398
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for CompilerLintFunctions {
393
399
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
+
394
404
if_chain ! {
395
405
if let ExprKind :: MethodCall ( ref path, _, ref args) = expr. kind;
396
406
let fn_name = path. ident;
@@ -416,6 +426,10 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
416
426
417
427
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for OuterExpnDataPass {
418
428
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
+
419
433
let ( method_names, arg_lists, spans) = method_calls ( expr, 2 ) ;
420
434
let method_names: Vec < SymbolStr > = method_names. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
421
435
let method_names: Vec < & str > = method_names. iter ( ) . map ( |s| & * * s) . collect ( ) ;
@@ -462,6 +476,10 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
462
476
463
477
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for CollapsibleCalls {
464
478
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
+
465
483
if_chain ! {
466
484
if let ExprKind :: Call ( ref func, ref and_then_args) = expr. kind;
467
485
if let ExprKind :: Path ( ref path) = func. kind;
0 commit comments