Skip to content

Commit 753c396

Browse files
committed
Use lint pass macros
Fixes #3917.
1 parent 24bb633 commit 753c396

File tree

131 files changed

+593
-2101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+593
-2101
lines changed

Diff for: clippy_lints/src/approx_const.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_tool_lint, lint_array};
4+
use rustc::{declare_lint_pass, declare_tool_lint};
55
use std::f64::consts as f64;
66
use syntax::ast::{FloatTy, Lit, LitKind};
77
use syntax::symbol;
@@ -53,20 +53,9 @@ const KNOWN_CONSTS: &[(f64, &str, usize)] = &[
5353
(f64::SQRT_2, "SQRT_2", 5),
5454
];
5555

56-
#[derive(Copy, Clone)]
57-
pub struct Pass;
56+
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
5857

59-
impl LintPass for Pass {
60-
fn get_lints(&self) -> LintArray {
61-
lint_array!(APPROX_CONSTANT)
62-
}
63-
64-
fn name(&self) -> &'static str {
65-
"ApproxConstant"
66-
}
67-
}
68-
69-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
58+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
7059
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
7160
if let ExprKind::Lit(lit) = &e.node {
7261
check_lit(cx, lit, e);

Diff for: clippy_lints/src/arithmetic.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::consts::constant_simple;
22
use crate::utils::span_lint;
33
use rustc::hir;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5-
use rustc::{declare_tool_lint, lint_array};
5+
use rustc::{declare_tool_lint, impl_lint_pass};
66
use syntax::source_map::Span;
77

88
declare_clippy_lint! {
@@ -48,15 +48,7 @@ pub struct Arithmetic {
4848
const_span: Option<Span>,
4949
}
5050

51-
impl LintPass for Arithmetic {
52-
fn get_lints(&self) -> LintArray {
53-
lint_array!(INTEGER_ARITHMETIC, FLOAT_ARITHMETIC)
54-
}
55-
56-
fn name(&self) -> &'static str {
57-
"Arithmetic"
58-
}
59-
}
51+
impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
6052

6153
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
6254
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {

Diff for: clippy_lints/src/assertions_on_constants.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use if_chain::if_chain;
22
use rustc::hir::{Expr, ExprKind};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_tool_lint, lint_array};
4+
use rustc::{declare_lint_pass, declare_tool_lint};
55

66
use crate::consts::{constant, Constant};
77
use crate::syntax::ast::LitKind;
@@ -29,17 +29,7 @@ declare_clippy_lint! {
2929
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`"
3030
}
3131

32-
pub struct AssertionsOnConstants;
33-
34-
impl LintPass for AssertionsOnConstants {
35-
fn get_lints(&self) -> LintArray {
36-
lint_array![ASSERTIONS_ON_CONSTANTS]
37-
}
38-
39-
fn name(&self) -> &'static str {
40-
"AssertionsOnConstants"
41-
}
42-
}
32+
declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
4333

4434
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4535
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

Diff for: clippy_lints/src/assign_ops.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use if_chain::if_chain;
22
use rustc::hir;
33
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5-
use rustc::{declare_tool_lint, lint_array};
5+
use rustc::{declare_lint_pass, declare_tool_lint};
66
use rustc_errors::Applicability;
77

88
use crate::utils::{
@@ -53,18 +53,7 @@ declare_clippy_lint! {
5353
"having a variable on both sides of an assign op"
5454
}
5555

56-
#[derive(Copy, Clone, Default)]
57-
pub struct AssignOps;
58-
59-
impl LintPass for AssignOps {
60-
fn get_lints(&self) -> LintArray {
61-
lint_array!(ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP)
62-
}
63-
64-
fn name(&self) -> &'static str {
65-
"AssignOps"
66-
}
67-
}
56+
declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
6857

6958
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7059
#[allow(clippy::too_many_lines)]

Diff for: clippy_lints/src/attrs.rs

+11-33
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::lint::{
1212
LintContext, LintPass,
1313
};
1414
use rustc::ty;
15-
use rustc::{declare_tool_lint, lint_array};
15+
use rustc::{declare_lint_pass, declare_tool_lint};
1616
use rustc_errors::Applicability;
1717
use semver::Version;
1818
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
@@ -187,26 +187,15 @@ declare_clippy_lint! {
187187
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
188188
}
189189

190-
#[derive(Copy, Clone)]
191-
pub struct AttrPass;
190+
declare_lint_pass!(Attributes => [
191+
INLINE_ALWAYS,
192+
DEPRECATED_SEMVER,
193+
USELESS_ATTRIBUTE,
194+
EMPTY_LINE_AFTER_OUTER_ATTR,
195+
UNKNOWN_CLIPPY_LINTS,
196+
]);
192197

193-
impl LintPass for AttrPass {
194-
fn get_lints(&self) -> LintArray {
195-
lint_array!(
196-
INLINE_ALWAYS,
197-
DEPRECATED_SEMVER,
198-
USELESS_ATTRIBUTE,
199-
EMPTY_LINE_AFTER_OUTER_ATTR,
200-
UNKNOWN_CLIPPY_LINTS,
201-
)
202-
}
203-
204-
fn name(&self) -> &'static str {
205-
"Attributes"
206-
}
207-
}
208-
209-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
198+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
210199
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
211200
if let Some(items) = &attr.meta_item_list() {
212201
if let Some(ident) = attr.ident() {
@@ -506,20 +495,9 @@ fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool {
506495
true
507496
}
508497

509-
#[derive(Copy, Clone)]
510-
pub struct CfgAttrPass;
511-
512-
impl LintPass for CfgAttrPass {
513-
fn get_lints(&self) -> LintArray {
514-
lint_array!(DEPRECATED_CFG_ATTR,)
515-
}
516-
517-
fn name(&self) -> &'static str {
518-
"DeprecatedCfgAttribute"
519-
}
520-
}
498+
declare_lint_pass!(DeprecatedCfgAttribute => [DEPRECATED_CFG_ATTR]);
521499

522-
impl EarlyLintPass for CfgAttrPass {
500+
impl EarlyLintPass for DeprecatedCfgAttribute {
523501
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
524502
if_chain! {
525503
// check cfg_attr

Diff for: clippy_lints/src/bit_mask.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::{span_lint, span_lint_and_then};
44
use if_chain::if_chain;
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
7-
use rustc::{declare_tool_lint, lint_array};
7+
use rustc::{declare_tool_lint, impl_lint_pass};
88
use rustc_errors::Applicability;
99
use syntax::ast::LitKind;
1010
use syntax::source_map::Span;
@@ -107,14 +107,7 @@ impl BitMask {
107107
}
108108
}
109109

110-
impl LintPass for BitMask {
111-
fn get_lints(&self) -> LintArray {
112-
lint_array!(BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK)
113-
}
114-
fn name(&self) -> &'static str {
115-
"BitMask"
116-
}
117-
}
110+
impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]);
118111

119112
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
120113
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

Diff for: clippy_lints/src/blacklisted_name.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_tool_lint, lint_array};
4+
use rustc::{declare_tool_lint, impl_lint_pass};
55
use rustc_data_structures::fx::FxHashSet;
66

77
declare_clippy_lint! {
@@ -23,26 +23,19 @@ declare_clippy_lint! {
2323
}
2424

2525
#[derive(Clone, Debug)]
26-
pub struct BlackListedName {
26+
pub struct BlacklistedName {
2727
blacklist: FxHashSet<String>,
2828
}
2929

30-
impl BlackListedName {
30+
impl BlacklistedName {
3131
pub fn new(blacklist: FxHashSet<String>) -> Self {
3232
Self { blacklist }
3333
}
3434
}
3535

36-
impl LintPass for BlackListedName {
37-
fn get_lints(&self) -> LintArray {
38-
lint_array!(BLACKLISTED_NAME)
39-
}
40-
fn name(&self) -> &'static str {
41-
"BlacklistedName"
42-
}
43-
}
36+
impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
4437

45-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
38+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
4639
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
4740
if let PatKind::Binding(.., ident, _) = pat.node {
4841
if self.blacklist.contains(&ident.name.to_string()) {

Diff for: clippy_lints/src/block_in_if_condition.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use matches::matches;
33
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
44
use rustc::hir::*;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
6-
use rustc::{declare_tool_lint, lint_array};
6+
use rustc::{declare_lint_pass, declare_tool_lint};
77

88
declare_clippy_lint! {
99
/// **What it does:** Checks for `if` conditions that use blocks to contain an
@@ -42,18 +42,7 @@ declare_clippy_lint! {
4242
"complex blocks in conditions, e.g., `if { let x = true; x } ...`"
4343
}
4444

45-
#[derive(Copy, Clone)]
46-
pub struct BlockInIfCondition;
47-
48-
impl LintPass for BlockInIfCondition {
49-
fn get_lints(&self) -> LintArray {
50-
lint_array!(BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT)
51-
}
52-
53-
fn name(&self) -> &'static str {
54-
"BlockInIfCondition"
55-
}
56-
}
45+
declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]);
5746

5847
struct ExVisitor<'a, 'tcx: 'a> {
5948
found_block: Option<&'tcx Expr>,

Diff for: clippy_lints/src/booleans.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::{
44
use rustc::hir::intravisit::*;
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
7-
use rustc::{declare_tool_lint, lint_array};
7+
use rustc::{declare_lint_pass, declare_tool_lint};
88
use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::Applicability;
1010
use syntax::ast::LitKind;
@@ -51,18 +51,7 @@ declare_clippy_lint! {
5151
// For each pairs, both orders are considered.
5252
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];
5353

54-
#[derive(Copy, Clone)]
55-
pub struct NonminimalBool;
56-
57-
impl LintPass for NonminimalBool {
58-
fn get_lints(&self) -> LintArray {
59-
lint_array!(NONMINIMAL_BOOL, LOGIC_BUG)
60-
}
61-
62-
fn name(&self) -> &'static str {
63-
"NonminimalBool"
64-
}
65-
}
54+
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
6655

6756
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
6857
fn check_fn(

Diff for: clippy_lints/src/bytecount.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use if_chain::if_chain;
66
use rustc::hir::*;
77
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
88
use rustc::ty;
9-
use rustc::{declare_tool_lint, lint_array};
9+
use rustc::{declare_lint_pass, declare_tool_lint};
1010
use rustc_errors::Applicability;
1111
use syntax::ast::{Name, UintTy};
1212

@@ -31,18 +31,7 @@ declare_clippy_lint! {
3131
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"
3232
}
3333

34-
#[derive(Copy, Clone)]
35-
pub struct ByteCount;
36-
37-
impl LintPass for ByteCount {
38-
fn get_lints(&self) -> LintArray {
39-
lint_array!(NAIVE_BYTECOUNT)
40-
}
41-
42-
fn name(&self) -> &'static str {
43-
"ByteCount"
44-
}
45-
}
34+
declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
4635

4736
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
4837
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {

Diff for: clippy_lints/src/cargo_common_metadata.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::utils::span_lint;
44
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
5-
use rustc::{declare_tool_lint, lint_array};
5+
use rustc::{declare_lint_pass, declare_tool_lint};
66
use syntax::{ast::*, source_map::DUMMY_SP};
77

88
use cargo_metadata;
@@ -56,19 +56,9 @@ fn is_empty_vec(value: &[String]) -> bool {
5656
value.iter().all(std::string::String::is_empty)
5757
}
5858

59-
pub struct Pass;
59+
declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
6060

61-
impl LintPass for Pass {
62-
fn get_lints(&self) -> LintArray {
63-
lint_array!(CARGO_COMMON_METADATA)
64-
}
65-
66-
fn name(&self) -> &'static str {
67-
"CargoCommonMetadata"
68-
}
69-
}
70-
71-
impl EarlyLintPass for Pass {
61+
impl EarlyLintPass for CargoCommonMetadata {
7262
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
7363
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
7464
metadata

Diff for: clippy_lints/src/cognitive_complexity.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
77
use rustc::ty;
8-
use rustc::{declare_tool_lint, lint_array};
8+
use rustc::{declare_tool_lint, impl_lint_pass};
99
use syntax::ast::Attribute;
1010
use syntax::source_map::Span;
1111

@@ -38,15 +38,7 @@ impl CognitiveComplexity {
3838
}
3939
}
4040

41-
impl LintPass for CognitiveComplexity {
42-
fn get_lints(&self) -> LintArray {
43-
lint_array!(COGNITIVE_COMPLEXITY)
44-
}
45-
46-
fn name(&self) -> &'static str {
47-
"CognitiveComplexity"
48-
}
49-
}
41+
impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]);
5042

5143
impl CognitiveComplexity {
5244
fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {

0 commit comments

Comments
 (0)