From ce8705177928c5225501f43c14664438c677b98f Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 5 Apr 2019 22:21:19 +0200 Subject: [PATCH 1/4] Fix lint_without_lint_pass internal lint --- clippy_lints/src/utils/internal_lints.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 69d026272824..b71d5000c6b2 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -150,7 +150,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { output: &mut self.registered_lints, cx, }; - let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.hir_id); + let body_id = cx.tcx.hir().body_owned_by( + impl_item_refs + .iter() + .find(|iiref| iiref.ident.as_str() == "get_lints") + .expect("LintPass needs to implement get_lints") + .id.hir_id + ); collector.visit_expr(&cx.tcx.hir().body(body_id).value); } } From 24bb63383a84aa4383e71da3b973769310bf609a Mon Sep 17 00:00:00 2001 From: Matthew Kraai Date: Sun, 7 Apr 2019 23:40:59 -0700 Subject: [PATCH 2/4] Document `declare_lint_pass!` --- doc/adding_lints.md | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/doc/adding_lints.md b/doc/adding_lints.md index d78e9c28e77a..5781ab7f9999 100644 --- a/doc/adding_lints.md +++ b/doc/adding_lints.md @@ -116,7 +116,7 @@ where all the lint code is. We are going to call the file ```rust use rustc::lint::{LintArray, LintPass, EarlyLintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; ``` The next step is to provide a lint declaration. Lints are declared using the @@ -147,22 +147,9 @@ lint pass: // .. imports and lint declaration .. -#[derive(Copy, Clone)] -pub struct FooFunctionsPass; - -impl LintPass for FooFunctionsPass { - fn get_lints(&self) -> LintArray { - lint_array!( - FOO_FUNCTIONS, - ) - } - - fn name(&self) -> &'static str { - "FooFunctions" - } -} +declare_lint_pass!(FooFunctions => [FOO_FUNCTIONS]); -impl EarlyLintPass for FooFunctionsPass {} +impl EarlyLintPass for FooFunctions {} ``` Don't worry about the `name` method here. As long as it includes the name of the @@ -176,7 +163,7 @@ will have to register our lint pass manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: ```rust -reg.register_early_lint_pass(box foo_functions::FooFunctionsPass); +reg.register_early_lint_pass(box foo_functions::FooFunctions); ``` This should fix the `unknown clippy lint: clippy::foo_functions` error that we @@ -211,10 +198,10 @@ use rustc::{declare_tool_lint, lint_array}; With UI tests and the lint declaration in place, we can start working on the implementation of the lint logic. -Let's start by implementing the `EarlyLintPass` for our `FooFunctionsPass`: +Let's start by implementing the `EarlyLintPass` for our `FooFunctions`: ```rust -impl EarlyLintPass for FooFunctionsPass { +impl EarlyLintPass for FooFunctions { fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) { // TODO: Emit lint here } @@ -236,7 +223,7 @@ provide an extra help message and we can't really suggest a better name automatically. This is how it looks: ```rust -impl EarlyLintPass for Pass { +impl EarlyLintPass for FooFunctions { fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) { span_help_and_lint( cx, @@ -263,7 +250,7 @@ Both provide access to the name of the function/method via an [`Ident`][ident]. With that we can expand our `check_fn` method to: ```rust -impl EarlyLintPass for Pass { +impl EarlyLintPass for FooFunctions { fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) { if is_foo_fn(fn_kind) { span_help_and_lint( @@ -304,16 +291,6 @@ running `cargo test` should produce the expected output. Remember to run `cargo test` (as opposed to `cargo uitest`) will also ensure that our lint implementation is not violating any Clippy lints itself. -If you are still following the example, you will see that `FooFunctionsPass` -violates a Clippy lint. So we are going to rename that struct to just `Pass`: - -```rust -#[derive(Copy, Clone)] -pub struct Pass; - -impl LintPass for Pass { /* .. */ } -``` - That should be it for the lint implementation. Running `cargo test` should now pass. From 753c39672ec091c55e83ee80a8b86a0725492903 Mon Sep 17 00:00:00 2001 From: Matthew Kraai Date: Mon, 8 Apr 2019 13:43:55 -0700 Subject: [PATCH 3/4] Use lint pass macros Fixes #3917. --- clippy_lints/src/approx_const.rs | 17 +- clippy_lints/src/arithmetic.rs | 12 +- clippy_lints/src/assertions_on_constants.rs | 14 +- clippy_lints/src/assign_ops.rs | 15 +- clippy_lints/src/attrs.rs | 44 ++--- clippy_lints/src/bit_mask.rs | 11 +- clippy_lints/src/blacklisted_name.rs | 17 +- clippy_lints/src/block_in_if_condition.rs | 15 +- clippy_lints/src/booleans.rs | 15 +- clippy_lints/src/bytecount.rs | 15 +- clippy_lints/src/cargo_common_metadata.rs | 16 +- clippy_lints/src/cognitive_complexity.rs | 12 +- clippy_lints/src/collapsible_if.rs | 15 +- clippy_lints/src/const_static_lifetime.rs | 14 +- clippy_lints/src/copies.rs | 15 +- clippy_lints/src/copy_iterator.rs | 14 +- clippy_lints/src/dbg_macro.rs | 17 +- clippy_lints/src/default_trait_access.rs | 15 +- clippy_lints/src/derive.rs | 14 +- clippy_lints/src/doc.rs | 19 +- clippy_lints/src/double_comparison.rs | 20 +-- clippy_lints/src/double_parens.rs | 15 +- clippy_lints/src/drop_bounds.rs | 16 +- clippy_lints/src/drop_forget_ref.rs | 16 +- clippy_lints/src/duration_subsec.rs | 15 +- clippy_lints/src/else_if_without_else.rs | 15 +- clippy_lints/src/empty_enum.rs | 15 +- clippy_lints/src/entry.rs | 17 +- clippy_lints/src/enum_clike.rs | 14 +- clippy_lints/src/enum_glob_use.rs | 16 +- clippy_lints/src/enum_variants.rs | 22 +-- clippy_lints/src/eq_op.rs | 15 +- clippy_lints/src/erasing_op.rs | 15 +- clippy_lints/src/escape.rs | 17 +- clippy_lints/src/eta_reduction.rs | 16 +- clippy_lints/src/eval_order_dependence.rs | 15 +- clippy_lints/src/excessive_precision.rs | 16 +- clippy_lints/src/explicit_write.rs | 17 +- clippy_lints/src/fallible_impl_from.rs | 14 +- clippy_lints/src/format.rs | 17 +- clippy_lints/src/formatting.rs | 23 +-- clippy_lints/src/functions.rs | 12 +- clippy_lints/src/identity_conversion.rs | 12 +- clippy_lints/src/identity_op.rs | 15 +- clippy_lints/src/if_not_else.rs | 14 +- clippy_lints/src/implicit_return.rs | 18 +- clippy_lints/src/indexing_slicing.rs | 15 +- .../src/infallible_destructuring_match.rs | 17 +- clippy_lints/src/infinite_iter.rs | 17 +- clippy_lints/src/inherent_impl.rs | 27 +-- clippy_lints/src/inline_fn_without_body.rs | 17 +- clippy_lints/src/int_plus_one.rs | 22 +-- clippy_lints/src/invalid_ref.rs | 14 +- clippy_lints/src/items_after_statements.rs | 14 +- clippy_lints/src/large_enum_variant.rs | 12 +- clippy_lints/src/len_zero.rs | 15 +- clippy_lints/src/let_if_seq.rs | 15 +- clippy_lints/src/lib.rs | 126 ++++++------- clippy_lints/src/lifetimes.rs | 17 +- clippy_lints/src/literal_representation.rs | 42 ++--- clippy_lints/src/loops.rs | 57 +++--- clippy_lints/src/map_clone.rs | 17 +- clippy_lints/src/map_unit_fn.rs | 17 +- clippy_lints/src/matches.rs | 37 ++-- clippy_lints/src/mem_discriminant.rs | 14 +- clippy_lints/src/mem_forget.rs | 14 +- clippy_lints/src/mem_replace.rs | 14 +- clippy_lints/src/methods/mod.rs | 89 ++++------ clippy_lints/src/minmax.rs | 14 +- clippy_lints/src/misc.rs | 41 ++--- clippy_lints/src/misc_early.rs | 37 ++-- clippy_lints/src/missing_const_for_fn.rs | 15 +- clippy_lints/src/missing_doc.rs | 12 +- clippy_lints/src/missing_inline.rs | 14 +- clippy_lints/src/multiple_crate_versions.rs | 16 +- clippy_lints/src/mut_mut.rs | 15 +- clippy_lints/src/mut_reference.rs | 15 +- clippy_lints/src/mutex_atomic.rs | 16 +- clippy_lints/src/needless_bool.rs | 28 +-- clippy_lints/src/needless_borrow.rs | 12 +- clippy_lints/src/needless_borrowed_ref.rs | 15 +- clippy_lints/src/needless_continue.rs | 15 +- clippy_lints/src/needless_pass_by_value.rs | 14 +- clippy_lints/src/needless_update.rs | 17 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 14 +- clippy_lints/src/neg_multiply.rs | 15 +- clippy_lints/src/new_without_default.rs | 12 +- clippy_lints/src/no_effect.rs | 17 +- clippy_lints/src/non_copy_const.rs | 14 +- clippy_lints/src/non_expressive_names.rs | 13 +- clippy_lints/src/ok_if_let.rs | 17 +- clippy_lints/src/open_options.rs | 17 +- .../src/overflow_check_conditional.rs | 15 +- clippy_lints/src/panic_unimplemented.rs | 16 +- clippy_lints/src/partialeq_ne_impl.rs | 17 +- clippy_lints/src/precedence.rs | 15 +- clippy_lints/src/ptr.rs | 17 +- clippy_lints/src/ptr_offset_with_cast.rs | 46 ++--- clippy_lints/src/question_mark.rs | 19 +- clippy_lints/src/ranges.rs | 27 +-- clippy_lints/src/redundant_clone.rs | 14 +- clippy_lints/src/redundant_field_names.rs | 14 +- .../src/redundant_pattern_matching.rs | 17 +- clippy_lints/src/reference.rs | 30 +--- clippy_lints/src/regex.rs | 16 +- clippy_lints/src/replace_consts.rs | 14 +- clippy_lints/src/returns.rs | 19 +- clippy_lints/src/serde_api.rs | 17 +- clippy_lints/src/shadow.rs | 17 +- .../src/slow_vector_initialization.rs | 19 +- clippy_lints/src/strings.rs | 28 +-- clippy_lints/src/suspicious_trait_impl.rs | 15 +- clippy_lints/src/swap.rs | 15 +- clippy_lints/src/temporary_assignment.rs | 17 +- clippy_lints/src/transmute.rs | 34 ++-- clippy_lints/src/transmuting_null.rs | 17 +- .../src/trivially_copy_pass_by_ref.rs | 12 +- clippy_lints/src/types.rs | 167 +++--------------- clippy_lints/src/unicode.rs | 15 +- clippy_lints/src/unsafe_removed_from_name.rs | 14 +- clippy_lints/src/unused_io_amount.rs | 14 +- clippy_lints/src/unused_label.rs | 14 +- clippy_lints/src/unwrap.rs | 16 +- clippy_lints/src/use_self.rs | 15 +- clippy_lints/src/utils/author.rs | 16 +- clippy_lints/src/utils/inspector.rs | 16 +- clippy_lints/src/utils/internal_lints.rs | 49 +---- clippy_lints/src/vec.rs | 17 +- clippy_lints/src/wildcard_dependencies.rs | 16 +- clippy_lints/src/write.rs | 35 ++-- clippy_lints/src/zero_div_zero.rs | 16 +- 131 files changed, 593 insertions(+), 2101 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index fa586ad45c23..62650b5cbb78 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -1,7 +1,7 @@ use crate::utils::span_lint; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use std::f64::consts as f64; use syntax::ast::{FloatTy, Lit, LitKind}; use syntax::symbol; @@ -53,20 +53,9 @@ const KNOWN_CONSTS: &[(f64, &str, usize)] = &[ (f64::SQRT_2, "SQRT_2", 5), ]; -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(APPROX_CONSTANT) - } - - fn name(&self) -> &'static str { - "ApproxConstant" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { if let ExprKind::Lit(lit) = &e.node { check_lit(cx, lit, e); diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 416ec656e12a..d94cd668bddc 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -2,7 +2,7 @@ use crate::consts::constant_simple; use crate::utils::span_lint; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use syntax::source_map::Span; declare_clippy_lint! { @@ -48,15 +48,7 @@ pub struct Arithmetic { const_span: Option, } -impl LintPass for Arithmetic { - fn get_lints(&self) -> LintArray { - lint_array!(INTEGER_ARITHMETIC, FLOAT_ARITHMETIC) - } - - fn name(&self) -> &'static str { - "Arithmetic" - } -} +impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 9e2a8c451ee1..ceea913233ee 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use crate::consts::{constant, Constant}; use crate::syntax::ast::LitKind; @@ -29,17 +29,7 @@ declare_clippy_lint! { "`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`" } -pub struct AssertionsOnConstants; - -impl LintPass for AssertionsOnConstants { - fn get_lints(&self) -> LintArray { - lint_array![ASSERTIONS_ON_CONSTANTS] - } - - fn name(&self) -> &'static str { - "AssertionsOnConstants" - } -} +declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index a39685f85ff8..98020303d37e 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -2,7 +2,7 @@ use if_chain::if_chain; use rustc::hir; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use crate::utils::{ @@ -53,18 +53,7 @@ declare_clippy_lint! { "having a variable on both sides of an assign op" } -#[derive(Copy, Clone, Default)] -pub struct AssignOps; - -impl LintPass for AssignOps { - fn get_lints(&self) -> LintArray { - lint_array!(ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP) - } - - fn name(&self) -> &'static str { - "AssignOps" - } -} +declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { #[allow(clippy::too_many_lines)] diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index d56e1e88fcef..45250e1eca62 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -12,7 +12,7 @@ use rustc::lint::{ LintContext, LintPass, }; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use semver::Version; use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; @@ -187,26 +187,15 @@ declare_clippy_lint! { "usage of `cfg_attr(rustfmt)` instead of `tool_attributes`" } -#[derive(Copy, Clone)] -pub struct AttrPass; +declare_lint_pass!(Attributes => [ + INLINE_ALWAYS, + DEPRECATED_SEMVER, + USELESS_ATTRIBUTE, + EMPTY_LINE_AFTER_OUTER_ATTR, + UNKNOWN_CLIPPY_LINTS, +]); -impl LintPass for AttrPass { - fn get_lints(&self) -> LintArray { - lint_array!( - INLINE_ALWAYS, - DEPRECATED_SEMVER, - USELESS_ATTRIBUTE, - EMPTY_LINE_AFTER_OUTER_ATTR, - UNKNOWN_CLIPPY_LINTS, - ) - } - - fn name(&self) -> &'static str { - "Attributes" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) { if let Some(items) = &attr.meta_item_list() { if let Some(ident) = attr.ident() { @@ -506,20 +495,9 @@ fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool { true } -#[derive(Copy, Clone)] -pub struct CfgAttrPass; - -impl LintPass for CfgAttrPass { - fn get_lints(&self) -> LintArray { - lint_array!(DEPRECATED_CFG_ATTR,) - } - - fn name(&self) -> &'static str { - "DeprecatedCfgAttribute" - } -} +declare_lint_pass!(DeprecatedCfgAttribute => [DEPRECATED_CFG_ATTR]); -impl EarlyLintPass for CfgAttrPass { +impl EarlyLintPass for DeprecatedCfgAttribute { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { if_chain! { // check cfg_attr diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 76314a610b16..71075500528e 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -4,7 +4,7 @@ use crate::utils::{span_lint, span_lint_and_then}; use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax::source_map::Span; @@ -107,14 +107,7 @@ impl BitMask { } } -impl LintPass for BitMask { - fn get_lints(&self) -> LintArray { - lint_array!(BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK) - } - fn name(&self) -> &'static str { - "BitMask" - } -} +impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index c1ee4d528854..33463df14529 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -1,7 +1,7 @@ use crate::utils::span_lint; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashSet; declare_clippy_lint! { @@ -23,26 +23,19 @@ declare_clippy_lint! { } #[derive(Clone, Debug)] -pub struct BlackListedName { +pub struct BlacklistedName { blacklist: FxHashSet, } -impl BlackListedName { +impl BlacklistedName { pub fn new(blacklist: FxHashSet) -> Self { Self { blacklist } } } -impl LintPass for BlackListedName { - fn get_lints(&self) -> LintArray { - lint_array!(BLACKLISTED_NAME) - } - fn name(&self) -> &'static str { - "BlacklistedName" - } -} +impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName { fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { if let PatKind::Binding(.., ident, _) = pat.node { if self.blacklist.contains(&ident.name.to_string()) { diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index f16631a5eff6..1f20f5c41fcc 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -3,7 +3,7 @@ use matches::matches; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for `if` conditions that use blocks to contain an @@ -42,18 +42,7 @@ declare_clippy_lint! { "complex blocks in conditions, e.g., `if { let x = true; x } ...`" } -#[derive(Copy, Clone)] -pub struct BlockInIfCondition; - -impl LintPass for BlockInIfCondition { - fn get_lints(&self) -> LintArray { - lint_array!(BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT) - } - - fn name(&self) -> &'static str { - "BlockInIfCondition" - } -} +declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]); struct ExVisitor<'a, 'tcx: 'a> { found_block: Option<&'tcx Expr>, diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index f7e0157746f4..779cb3cf90f8 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -4,7 +4,7 @@ use crate::utils::{ use rustc::hir::intravisit::*; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::thin_vec::ThinVec; use rustc_errors::Applicability; use syntax::ast::LitKind; @@ -51,18 +51,7 @@ declare_clippy_lint! { // For each pairs, both orders are considered. const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")]; -#[derive(Copy, Clone)] -pub struct NonminimalBool; - -impl LintPass for NonminimalBool { - fn get_lints(&self) -> LintArray { - lint_array!(NONMINIMAL_BOOL, LOGIC_BUG) - } - - fn name(&self) -> &'static str { - "NonminimalBool" - } -} +declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool { fn check_fn( diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 9fd82ae5946b..2ededb778643 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::{Name, UintTy}; @@ -31,18 +31,7 @@ declare_clippy_lint! { "use of naive `.filter(|&x| x == y).count()` to count byte values" } -#[derive(Copy, Clone)] -pub struct ByteCount; - -impl LintPass for ByteCount { - fn get_lints(&self) -> LintArray { - lint_array!(NAIVE_BYTECOUNT) - } - - fn name(&self) -> &'static str { - "ByteCount" - } -} +declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index 57bdce4cf3a9..23532c4b0474 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -2,7 +2,7 @@ use crate::utils::span_lint; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::{ast::*, source_map::DUMMY_SP}; use cargo_metadata; @@ -56,19 +56,9 @@ fn is_empty_vec(value: &[String]) -> bool { value.iter().all(std::string::String::is_empty) } -pub struct Pass; +declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(CARGO_COMMON_METADATA) - } - - fn name(&self) -> &'static str { - "CargoCommonMetadata" - } -} - -impl EarlyLintPass for Pass { +impl EarlyLintPass for CargoCommonMetadata { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() { metadata diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index d44784843e73..ccf6d1830062 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -5,7 +5,7 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use syntax::ast::Attribute; use syntax::source_map::Span; @@ -38,15 +38,7 @@ impl CognitiveComplexity { } } -impl LintPass for CognitiveComplexity { - fn get_lints(&self) -> LintArray { - lint_array!(COGNITIVE_COMPLEXITY) - } - - fn name(&self) -> &'static str { - "CognitiveComplexity" - } -} +impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]); impl CognitiveComplexity { fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) { diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 00e0787a927d..c1d39716083e 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -14,7 +14,7 @@ use if_chain::if_chain; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast; use crate::utils::sugg::Sugg; @@ -71,18 +71,7 @@ declare_clippy_lint! { "`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)" } -#[derive(Copy, Clone)] -pub struct CollapsibleIf; - -impl LintPass for CollapsibleIf { - fn get_lints(&self) -> LintArray { - lint_array!(COLLAPSIBLE_IF) - } - - fn name(&self) -> &'static str { - "CollapsibleIf" - } -} +declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]); impl EarlyLintPass for CollapsibleIf { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { diff --git a/clippy_lints/src/const_static_lifetime.rs b/clippy_lints/src/const_static_lifetime.rs index 1e369044d246..50e1781d2cb5 100644 --- a/clippy_lints/src/const_static_lifetime.rs +++ b/clippy_lints/src/const_static_lifetime.rs @@ -1,6 +1,6 @@ use crate::utils::{in_macro, snippet, span_lint_and_then}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::*; @@ -26,17 +26,7 @@ declare_clippy_lint! { "Using explicit `'static` lifetime for constants when elision rules would allow omitting them." } -pub struct StaticConst; - -impl LintPass for StaticConst { - fn get_lints(&self) -> LintArray { - lint_array!(CONST_STATIC_LIFETIME) - } - - fn name(&self) -> &'static str { - "StaticConst" - } -} +declare_lint_pass!(StaticConst => [CONST_STATIC_LIFETIME]); impl StaticConst { // Recursively visit types diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 39fc10258078..d1163e102790 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -3,7 +3,7 @@ use crate::utils::{SpanlessEq, SpanlessHash}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::Ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashMap; use smallvec::SmallVec; use std::collections::hash_map::Entry; @@ -103,18 +103,7 @@ declare_clippy_lint! { "`match` with identical arm bodies" } -#[derive(Copy, Clone, Debug)] -pub struct CopyAndPaste; - -impl LintPass for CopyAndPaste { - fn get_lints(&self) -> LintArray { - lint_array![IFS_SAME_COND, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS] - } - - fn name(&self) -> &'static str { - "CopyAndPaste" - } -} +declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 5c8d6def210f..79e30f1a7d8a 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -1,7 +1,7 @@ use crate::utils::{is_copy, match_path, paths, span_note_and_lint}; use rustc::hir::{Item, ItemKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for types that implement `Copy` as well as @@ -29,17 +29,7 @@ declare_clippy_lint! { "implementing `Iterator` on a `Copy` type" } -pub struct CopyIterator; - -impl LintPass for CopyIterator { - fn get_lints(&self) -> LintArray { - lint_array![COPY_ITERATOR] - } - - fn name(&self) -> &'static str { - "CopyIterator" - } -} +declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index 8b71123ca55b..c54bafae56a1 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -1,6 +1,6 @@ use crate::utils::{snippet_opt, span_help_and_lint, span_lint_and_sugg}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast; use syntax::source_map::Span; @@ -27,20 +27,9 @@ declare_clippy_lint! { "`dbg!` macro is intended as a debugging tool" } -#[derive(Copy, Clone, Debug)] -pub struct Pass; +declare_lint_pass!(DbgMacro => [DBG_MACRO]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(DBG_MACRO) - } - - fn name(&self) -> &'static str { - "DbgMacro" - } -} - -impl EarlyLintPass for Pass { +impl EarlyLintPass for DbgMacro { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) { if mac.node.path == "dbg" { if let Some(sugg) = tts_span(mac.node.tts.clone()).and_then(|span| snippet_opt(cx, span)) { diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 2f80e37ab29f..3e3663d6d0ae 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -2,7 +2,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use crate::utils::{any_parent_is_automatically_derived, paths, span_lint_and_sugg}; @@ -28,18 +28,7 @@ declare_clippy_lint! { "checks for literal calls to Default::default()" } -#[derive(Copy, Clone)] -pub struct DefaultTraitAccess; - -impl LintPass for DefaultTraitAccess { - fn get_lints(&self) -> LintArray { - lint_array!(DEFAULT_TRAIT_ACCESS) - } - - fn name(&self) -> &'static str { - "DefaultTraitAccess" - } -} +declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 2c77f8d37fac..bf2845af1336 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::source_map::Span; declare_clippy_lint! { @@ -62,17 +62,7 @@ declare_clippy_lint! { "implementing `Clone` explicitly on `Copy` types" } -pub struct Derive; - -impl LintPass for Derive { - fn get_lints(&self) -> LintArray { - lint_array!(EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ) - } - - fn name(&self) -> &'static str { - "Derive" - } -} +declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 413645a091ff..4ad6554a213c 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -2,7 +2,7 @@ use crate::utils::span_lint; use itertools::Itertools; use pulldown_cmark; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashSet; use syntax::ast; use syntax::source_map::{BytePos, Span}; @@ -33,28 +33,21 @@ declare_clippy_lint! { "presence of `_`, `::` or camel-case outside backticks in documentation" } +#[allow(clippy::module_name_repetitions)] #[derive(Clone)] -pub struct Doc { +pub struct DocMarkdown { valid_idents: FxHashSet, } -impl Doc { +impl DocMarkdown { pub fn new(valid_idents: FxHashSet) -> Self { Self { valid_idents } } } -impl LintPass for Doc { - fn get_lints(&self) -> LintArray { - lint_array![DOC_MARKDOWN] - } - - fn name(&self) -> &'static str { - "DocMarkdown" - } -} +impl_lint_pass!(DocMarkdown => [DOC_MARKDOWN]); -impl EarlyLintPass for Doc { +impl EarlyLintPass for DocMarkdown { fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) { check_attrs(cx, &self.valid_idents, &krate.attrs); } diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index be6124e45536..d64939d01298 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -2,7 +2,7 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Span; @@ -31,21 +31,11 @@ declare_clippy_lint! { "unnecessary double comparisons that can be simplified" } -pub struct Pass; +declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(DOUBLE_COMPARISONS) - } - - fn name(&self) -> &'static str { - "DoubleComparisons" - } -} - -impl<'a, 'tcx> Pass { +impl<'a, 'tcx> DoubleComparisons { #[allow(clippy::similar_names)] - fn check_binop(&self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) { + fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) { let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (lhs.node.clone(), rhs.node.clone()) { (ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => { (lb.node, llhs, lrhs, rb.node, rlhs, rrhs) @@ -91,7 +81,7 @@ impl<'a, 'tcx> Pass { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.node { self.check_binop(cx, kind.node, lhs, rhs, expr.span); diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index 5b5639371a18..12f67b84ca28 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -1,6 +1,6 @@ use crate::utils::{in_macro, span_lint}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; declare_clippy_lint! { @@ -22,18 +22,7 @@ declare_clippy_lint! { "Warn on unnecessary double parentheses" } -#[derive(Copy, Clone)] -pub struct DoubleParens; - -impl LintPass for DoubleParens { - fn get_lints(&self) -> LintArray { - lint_array!(DOUBLE_PARENS) - } - - fn name(&self) -> &'static str { - "DoubleParens" - } -} +declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]); impl EarlyLintPass for DoubleParens { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { diff --git a/clippy_lints/src/drop_bounds.rs b/clippy_lints/src/drop_bounds.rs index 37a4f5d7c5fa..4c7c866fc635 100644 --- a/clippy_lints/src/drop_bounds.rs +++ b/clippy_lints/src/drop_bounds.rs @@ -2,7 +2,7 @@ use crate::utils::{paths, span_lint}; use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for generics with `std::ops::Drop` as bounds. @@ -35,19 +35,9 @@ declare_clippy_lint! { const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \ Use `std::mem::needs_drop` to detect if a type has drop glue."; -pub struct Pass; +declare_lint_pass!(DropBounds => [DROP_BOUNDS]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(DROP_BOUNDS) - } - - fn name(&self) -> &'static str { - "DropBounds" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds { fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam) { for bound in &p.bounds { lint_bound(cx, bound); diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 240f4425a6b0..44853cd79903 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for calls to `std::mem::drop` with a reference @@ -106,19 +106,9 @@ const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that imp const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements Copy. \ Forgetting a copy leaves the original intact."; -pub struct Pass; +declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY) - } - - fn name(&self) -> &'static str { - "DropForgetRef" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if_chain! { if let ExprKind::Call(ref path, ref args) = expr.node; diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index df0ea31470c6..60470ede5419 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Spanned; @@ -29,18 +29,7 @@ declare_clippy_lint! { "checks for calculation of subsecond microseconds or milliseconds" } -#[derive(Copy, Clone)] -pub struct DurationSubsec; - -impl LintPass for DurationSubsec { - fn get_lints(&self) -> LintArray { - lint_array!(DURATION_SUBSEC) - } - - fn name(&self) -> &'static str { - "DurationSubsec" - } -} +declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index 01380fd96807..25a1cde6e5ee 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -1,7 +1,7 @@ //! Lint on if expressions with an else if, but without a final else branch. use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; use crate::utils::span_help_and_lint; @@ -39,18 +39,7 @@ declare_clippy_lint! { "if expression with an `else if`, but without a final `else` branch" } -#[derive(Copy, Clone)] -pub struct ElseIfWithoutElse; - -impl LintPass for ElseIfWithoutElse { - fn get_lints(&self) -> LintArray { - lint_array!(ELSE_IF_WITHOUT_ELSE) - } - - fn name(&self) -> &'static str { - "ElseIfWithoutElse" - } -} +declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]); impl EarlyLintPass for ElseIfWithoutElse { fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) { diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 9075cdc10c8b..e8d25384ee6a 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -3,7 +3,7 @@ use crate::utils::span_lint_and_then; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for `enum`s with no variants. @@ -23,18 +23,7 @@ declare_clippy_lint! { "enum with no variants" } -#[derive(Copy, Clone)] -pub struct EmptyEnum; - -impl LintPass for EmptyEnum { - fn get_lints(&self) -> LintArray { - lint_array!(EMPTY_ENUM) - } - - fn name(&self) -> &'static str { - "EmptyEnum" - } -} +declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 0dc970fcafe2..c74232a906e1 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Span; @@ -37,20 +37,9 @@ declare_clippy_lint! { "use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`" } -#[derive(Copy, Clone)] -pub struct HashMapLint; +declare_lint_pass!(HashMapPass => [MAP_ENTRY]); -impl LintPass for HashMapLint { - fn get_lints(&self) -> LintArray { - lint_array!(MAP_ENTRY) - } - - fn name(&self) -> &'static str { - "HashMap" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.node { if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node { diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 8e844f9c3988..90cb78ae0366 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -9,7 +9,7 @@ use rustc::mir::interpret::GlobalId; use rustc::ty; use rustc::ty::subst::InternalSubsts; use rustc::ty::util::IntTypeExt; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::{IntTy, UintTy}; declare_clippy_lint! { @@ -34,17 +34,7 @@ declare_clippy_lint! { "C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`" } -pub struct UnportableVariant; - -impl LintPass for UnportableVariant { - fn get_lints(&self) -> LintArray { - lint_array!(ENUM_CLIKE_UNPORTABLE_VARIANT) - } - - fn name(&self) -> &'static str { - "UnportableVariant" - } -} +declare_lint_pass!(UnportableVariant => [ENUM_CLIKE_UNPORTABLE_VARIANT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)] diff --git a/clippy_lints/src/enum_glob_use.rs b/clippy_lints/src/enum_glob_use.rs index afdf27376d80..673f471b83c0 100644 --- a/clippy_lints/src/enum_glob_use.rs +++ b/clippy_lints/src/enum_glob_use.rs @@ -4,7 +4,7 @@ use crate::utils::span_lint; use rustc::hir::def::Def; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::source_map::Span; declare_clippy_lint! { @@ -25,17 +25,7 @@ declare_clippy_lint! { "use items that import all variants of an enum" } -pub struct EnumGlobUse; - -impl LintPass for EnumGlobUse { - fn get_lints(&self) -> LintArray { - lint_array!(ENUM_GLOB_USE) - } - - fn name(&self) -> &'static str { - "EnumGlobUse" - } -} +declare_lint_pass!(EnumGlobUse => [ENUM_GLOB_USE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse { fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) { @@ -48,7 +38,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse { } impl EnumGlobUse { - fn lint_item(&self, cx: &LateContext<'_, '_>, item: &Item) { + fn lint_item(self, cx: &LateContext<'_, '_>, item: &Item) { if item.vis.node.is_pub() { return; // re-exports are fine } diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 707fe93bd0c3..20cd747dfc4e 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -3,7 +3,7 @@ use crate::utils::{camel_case, in_macro}; use crate::utils::{span_help_and_lint, span_lint}; use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use syntax::ast::*; use syntax::source_map::Span; use syntax::symbol::{InternedString, LocalInternedString}; @@ -115,20 +115,12 @@ impl EnumVariantNames { } } -impl LintPass for EnumVariantNames { - fn get_lints(&self) -> LintArray { - lint_array!( - ENUM_VARIANT_NAMES, - PUB_ENUM_VARIANT_NAMES, - MODULE_NAME_REPETITIONS, - MODULE_INCEPTION - ) - } - - fn name(&self) -> &'static str { - "EnumVariantNames" - } -} +impl_lint_pass!(EnumVariantNames => [ + ENUM_VARIANT_NAMES, + PUB_ENUM_VARIANT_NAMES, + MODULE_NAME_REPETITIONS, + MODULE_INCEPTION +]); fn var2str(var: &Variant) -> LocalInternedString { var.node.ident.as_str() diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 1f42a06fbcd3..ea09f82642f7 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -3,7 +3,7 @@ use crate::utils::{ }; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -46,18 +46,7 @@ declare_clippy_lint! { "taking a reference to satisfy the type constraints on `==`" } -#[derive(Copy, Clone)] -pub struct EqOp; - -impl LintPass for EqOp { - fn get_lints(&self) -> LintArray { - lint_array!(EQ_OP, OP_REF) - } - - fn name(&self) -> &'static str { - "EqOp" - } -} +declare_lint_pass!(EqOp => [EQ_OP, OP_REF]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { #[allow(clippy::similar_names, clippy::too_many_lines)] diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index 07909ef587fe..7f3549be64bb 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -1,6 +1,6 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::source_map::Span; use crate::consts::{constant_simple, Constant}; @@ -27,18 +27,7 @@ declare_clippy_lint! { "using erasing operations, e.g., `x * 0` or `y & 0`" } -#[derive(Copy, Clone)] -pub struct ErasingOp; - -impl LintPass for ErasingOp { - fn get_lints(&self) -> LintArray { - lint_array!(ERASING_OP) - } - - fn name(&self) -> &'static str { - "ErasingOp" - } -} +declare_lint_pass!(ErasingOp => [ERASING_OP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 59ca2563cda6..8870b3f3b0ce 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -6,12 +6,13 @@ use rustc::middle::mem_categorization::{cmt_, Categorization}; use rustc::ty::layout::LayoutOf; use rustc::ty::{self, Ty}; use rustc::util::nodemap::HirIdSet; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use syntax::source_map::Span; use crate::utils::span_lint; -pub struct Pass { +#[derive(Copy, Clone)] +pub struct BoxedLocal { pub too_large_for_stack: u64, } @@ -48,17 +49,9 @@ struct EscapeDelegate<'a, 'tcx: 'a> { too_large_for_stack: u64, } -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(BOXED_LOCAL) - } - - fn name(&self) -> &'static str { - "BoxedLocal" - } -} +impl_lint_pass!(BoxedLocal => [BOXED_LOCAL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal { fn check_fn( &mut self, cx: &LateContext<'a, 'tcx>, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index d67381660e51..63abe47b4428 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -2,13 +2,11 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function}; -pub struct EtaPass; - declare_clippy_lint! { /// **What it does:** Checks for closures which just call another function where /// the function can be called directly. `unsafe` functions or calls where types @@ -33,17 +31,9 @@ declare_clippy_lint! { "redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)" } -impl LintPass for EtaPass { - fn get_lints(&self) -> LintArray { - lint_array!(REDUNDANT_CLOSURE) - } - - fn name(&self) -> &'static str { - "EtaReduction" - } -} +declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaPass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if in_external_macro(cx.sess(), expr.span) { return; diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 2a4d404ccc7f..a62bb3cda9b6 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -4,7 +4,7 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for a read and a write to the same variable where @@ -53,18 +53,7 @@ declare_clippy_lint! { "whether an expression contains a diverging sub expression" } -#[derive(Copy, Clone)] -pub struct EvalOrderDependence; - -impl LintPass for EvalOrderDependence { - fn get_lints(&self) -> LintArray { - lint_array!(EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION) - } - - fn name(&self) -> &'static str { - "EvalOrderDependence" - } -} +declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/excessive_precision.rs b/clippy_lints/src/excessive_precision.rs index ff28866e3a7b..5f631237885c 100644 --- a/clippy_lints/src/excessive_precision.rs +++ b/clippy_lints/src/excessive_precision.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::f32; use std::f64; @@ -35,17 +35,7 @@ declare_clippy_lint! { "excessive precision for float literal" } -pub struct ExcessivePrecision; - -impl LintPass for ExcessivePrecision { - fn get_lints(&self) -> LintArray { - lint_array!(EXCESSIVE_PRECISION) - } - - fn name(&self) -> &'static str { - "ExcessivePrecision" - } -} +declare_lint_pass!(ExcessivePrecision => [EXCESSIVE_PRECISION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { @@ -72,7 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision { impl ExcessivePrecision { // None if nothing to lint, Some(suggestion) if lint necessary - fn check(&self, sym: Symbol, fty: FloatTy) -> Option { + fn check(self, sym: Symbol, fty: FloatTy) -> Option { let max = max_digits(fty); let sym_str = sym.as_str(); if dot_zero_exclusion(&sym_str) { diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 223c0022a669..a29b1380006c 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -2,7 +2,7 @@ use crate::utils::{is_expn_of, resolve_node, span_lint, span_lint_and_sugg}; use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::LitKind; @@ -24,20 +24,9 @@ declare_clippy_lint! { "using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work" } -#[derive(Copy, Clone, Debug)] -pub struct Pass; +declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(EXPLICIT_WRITE) - } - - fn name(&self) -> &'static str { - "ExplicitWrite" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if_chain! { // match call to unwrap diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 05ec59fabe41..1cbe9d218bdf 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax_pos::Span; declare_clippy_lint! { @@ -28,17 +28,7 @@ declare_clippy_lint! { "Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`" } -pub struct FallibleImplFrom; - -impl LintPass for FallibleImplFrom { - fn get_lints(&self) -> LintArray { - lint_array!(FALLIBLE_IMPL_FROM) - } - - fn name(&self) -> &'static str { - "FallibleImpleFrom" - } -} +declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 2a88c28536fe..95389fa3c81e 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax::source_map::Span; @@ -33,20 +33,9 @@ declare_clippy_lint! { "useless use of `format!`" } -#[derive(Copy, Clone, Debug)] -pub struct Pass; +declare_lint_pass!(UselessFormat => [USELESS_FORMAT]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array![USELESS_FORMAT] - } - - fn name(&self) -> &'static str { - "UselessFormat" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let Some(span) = is_expn_of(expr.span, "format") { if in_macro(span) { diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 542392c8b29b..e29a8c3702b1 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -1,7 +1,7 @@ use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint}; use if_chain::if_chain; use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast; use syntax::ptr::P; @@ -79,22 +79,11 @@ declare_clippy_lint! { "possible missing comma in array" } -#[derive(Copy, Clone)] -pub struct Formatting; - -impl LintPass for Formatting { - fn get_lints(&self) -> LintArray { - lint_array!( - SUSPICIOUS_ASSIGNMENT_FORMATTING, - SUSPICIOUS_ELSE_FORMATTING, - POSSIBLE_MISSING_COMMA - ) - } - - fn name(&self) -> &'static str { - "Formatting" - } -} +declare_lint_pass!(Formatting => [ + SUSPICIOUS_ASSIGNMENT_FORMATTING, + SUSPICIOUS_ELSE_FORMATTING, + POSSIBLE_MISSING_COMMA +]); impl EarlyLintPass for Formatting { fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) { diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index d657bb6a0b4e..b3e0eb8a6704 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -5,7 +5,7 @@ use rustc::hir::def::Def; use rustc::hir::intravisit; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashSet; use rustc_target::spec::abi::Abi; use syntax::source_map::Span; @@ -93,15 +93,7 @@ impl Functions { } } -impl LintPass for Functions { - fn get_lints(&self) -> LintArray { - lint_array!(TOO_MANY_ARGUMENTS, TOO_MANY_LINES, NOT_UNSAFE_PTR_ARG_DEREF) - } - - fn name(&self) -> &'static str { - "Functions" - } -} +impl_lint_pass!(Functions => [TOO_MANY_ARGUMENTS, TOO_MANY_LINES, NOT_UNSAFE_PTR_ARG_DEREF]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { fn check_fn( diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index 5fa685682261..0941ed513fc4 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -2,7 +2,7 @@ use crate::utils::{in_macro, match_trait_method, same_tys, snippet, snippet_with use crate::utils::{paths, resolve_node}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -27,15 +27,7 @@ pub struct IdentityConversion { try_desugar_arm: Vec, } -impl LintPass for IdentityConversion { - fn get_lints(&self) -> LintArray { - lint_array!(IDENTITY_CONVERSION) - } - - fn name(&self) -> &'static str { - "IdentityConversion" - } -} +impl_lint_pass!(IdentityConversion => [IDENTITY_CONVERSION]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 6d15e37454c4..cc023a5a4598 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -1,7 +1,7 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::source_map::Span; use crate::consts::{constant_simple, Constant}; @@ -24,18 +24,7 @@ declare_clippy_lint! { "using identity operations, e.g., `x + 0` or `y / 1`" } -#[derive(Copy, Clone)] -pub struct IdentityOp; - -impl LintPass for IdentityOp { - fn get_lints(&self) -> LintArray { - lint_array!(IDENTITY_OP) - } - - fn name(&self) -> &'static str { - "IdentityOp" - } -} +declare_lint_pass!(IdentityOp => [IDENTITY_OP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index 5ce29597cab7..385ba9f16c89 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -2,7 +2,7 @@ //! on the condition use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; use crate::utils::span_help_and_lint; @@ -38,17 +38,7 @@ declare_clippy_lint! { "`if` branches that could be swapped so no negation operation is necessary on the condition" } -pub struct IfNotElse; - -impl LintPass for IfNotElse { - fn get_lints(&self) -> LintArray { - lint_array!(IF_NOT_ELSE) - } - - fn name(&self) -> &'static str { - "IfNotElse" - } -} +declare_lint_pass!(IfNotElse => [IF_NOT_ELSE]); impl EarlyLintPass for IfNotElse { fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) { diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index a82a57fe6ff3..559b0942d2b5 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -1,7 +1,7 @@ use crate::utils::{in_macro, is_expn_of, snippet_opt, span_lint_and_then}; use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Span; @@ -33,9 +33,9 @@ declare_clippy_lint! { "use a return statement like `return expr` instead of an expression" } -pub struct Pass; +declare_lint_pass!(ImplicitReturn => [IMPLICIT_RETURN]); -impl Pass { +impl ImplicitReturn { fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) { span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| { if let Some(snippet) = snippet_opt(cx, inner_span) { @@ -110,17 +110,7 @@ impl Pass { } } -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(IMPLICIT_RETURN) - } - - fn name(&self) -> &'static str { - "ImplicitReturn" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn { fn check_fn( &mut self, cx: &LateContext<'a, 'tcx>, diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 07fcec858637..d0a9bb729a45 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -7,7 +7,7 @@ use crate::utils::higher::Range; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::RangeLimits; declare_clippy_lint! { @@ -85,18 +85,7 @@ declare_clippy_lint! { "indexing/slicing usage" } -#[derive(Copy, Clone)] -pub struct IndexingSlicing; - -impl LintPass for IndexingSlicing { - fn get_lints(&self) -> LintArray { - lint_array!(INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING) - } - - fn name(&self) -> &'static str { - "IndexSlicing" - } -} +declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/infallible_destructuring_match.rs b/clippy_lints/src/infallible_destructuring_match.rs index 762d3b17c926..a977a827321d 100644 --- a/clippy_lints/src/infallible_destructuring_match.rs +++ b/clippy_lints/src/infallible_destructuring_match.rs @@ -2,7 +2,7 @@ use super::utils::{get_arg_name, match_var, remove_blocks, snippet_with_applicab use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -40,20 +40,9 @@ declare_clippy_lint! { "a match statement with a single infallible arm instead of a `let`" } -#[derive(Copy, Clone, Default)] -pub struct Pass; +declare_lint_pass!(InfallibleDestructingMatch => [INFALLIBLE_DESTRUCTURING_MATCH]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(INFALLIBLE_DESTRUCTURING_MATCH) - } - - fn name(&self) -> &'static str { - "InfallibleDestructingMatch" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch { fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) { if_chain! { if let Some(ref expr) = local.init; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 689cd8fd3b05..29e0396c09e3 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,6 +1,6 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, match_type, paths, span_lint}; @@ -41,20 +41,9 @@ declare_clippy_lint! { "possible infinite iteration" } -#[derive(Copy, Clone)] -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(INFINITE_ITER, MAYBE_INFINITE_ITER) - } - - fn name(&self) -> &'static str { - "InfiniteIter" - } -} +declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfiniteIter { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { let (lint, msg) = match complete_infinite_iter(cx, expr) { Infinite => (INFINITE_ITER, "infinite iteration detected"), diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 51d6c310cf62..bde784f81de8 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -3,9 +3,8 @@ use crate::utils::span_lint_and_then; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashMap; -use std::default::Default; use syntax_pos::Span; declare_clippy_lint! { @@ -40,29 +39,15 @@ declare_clippy_lint! { "Multiple inherent impl that could be grouped" } -pub struct Pass { +#[allow(clippy::module_name_repetitions)] +#[derive(Default)] +pub struct MultipleInherentImpl { impls: FxHashMap, } -impl Default for Pass { - fn default() -> Self { - Self { - impls: FxHashMap::default(), - } - } -} - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(MULTIPLE_INHERENT_IMPL) - } - - fn name(&self) -> &'static str { - "MultipleInherientImpl" - } -} +impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl { fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node { // Remember for each inherent implementation encoutered its span and generics diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 3e13d0073fe8..5242b22c7908 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -4,7 +4,7 @@ use crate::utils::span_lint_and_then; use crate::utils::sugg::DiagnosticBuilderExt; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::{Attribute, Name}; @@ -28,20 +28,9 @@ declare_clippy_lint! { "use of `#[inline]` on trait methods without bodies" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(INLINE_FN_WITHOUT_BODY) - } - - fn name(&self) -> &'static str { - "InlineFnWithoutBody" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody { fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) { if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node { check_attrs(cx, item.ident.name, &item.attrs); diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index bab7374916da..b59179618a6d 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -1,7 +1,7 @@ //! lint on blocks unnecessarily using >= with a + 1 or - 1 use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::*; @@ -30,17 +30,7 @@ declare_clippy_lint! { "instead of using x >= y + 1, use x > y" } -pub struct IntPlusOne; - -impl LintPass for IntPlusOne { - fn get_lints(&self) -> LintArray { - lint_array!(INT_PLUS_ONE) - } - - fn name(&self) -> &'static str { - "IntPlusOne" - } -} +declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]); // cases: // BinOpKind::Ge @@ -59,14 +49,14 @@ enum Side { impl IntPlusOne { #[allow(clippy::cast_sign_loss)] - fn check_lit(&self, lit: &Lit, target_value: i128) -> bool { + fn check_lit(self, lit: &Lit, target_value: i128) -> bool { if let LitKind::Int(value, ..) = lit.node { return value == (target_value as u128); } false } - fn check_binop(&self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option { + fn check_binop(self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option { match (binop, &lhs.node, &rhs.node) { // case where `x - 1 >= ...` or `-1 + x >= ...` (BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => { @@ -131,7 +121,7 @@ impl IntPlusOne { } fn generate_recommendation( - &self, + self, cx: &EarlyContext<'_>, binop: BinOpKind, node: &Expr, @@ -155,7 +145,7 @@ impl IntPlusOne { None } - fn emit_warning(&self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) { + fn emit_warning(self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) { span_lint_and_then( cx, INT_PLUS_ONE, diff --git a/clippy_lints/src/invalid_ref.rs b/clippy_lints/src/invalid_ref.rs index 2e5ebeda24ab..40a11cde4459 100644 --- a/clippy_lints/src/invalid_ref.rs +++ b/clippy_lints/src/invalid_ref.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for creation of references to zeroed or uninitialized memory. @@ -26,17 +26,7 @@ const UNINIT_REF_SUMMARY: &str = "reference to uninitialized memory"; const HELP: &str = "Creation of a null reference is undefined behavior; \ see https://doc.rust-lang.org/reference/behavior-considered-undefined.html"; -pub struct InvalidRef; - -impl LintPass for InvalidRef { - fn get_lints(&self) -> LintArray { - lint_array!(INVALID_REF) - } - - fn name(&self) -> &'static str { - "InvalidRef" - } -} +declare_lint_pass!(InvalidRef => [INVALID_REF]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index f93f515d0239..779bac30e0fa 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -3,7 +3,7 @@ use crate::utils::{in_macro, span_lint}; use matches::matches; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; declare_clippy_lint! { @@ -34,17 +34,7 @@ declare_clippy_lint! { "blocks where an item comes after a statement" } -pub struct ItemsAfterStatements; - -impl LintPass for ItemsAfterStatements { - fn get_lints(&self) -> LintArray { - lint_array!(ITEMS_AFTER_STATEMENTS) - } - - fn name(&self) -> &'static str { - "ItemsAfterStatements" - } -} +declare_lint_pass!(ItemsAfterStatements => [ITEMS_AFTER_STATEMENTS]); impl EarlyLintPass for ItemsAfterStatements { fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) { diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 2e38fcf03672..e447be82b03d 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -4,7 +4,7 @@ use crate::utils::{snippet_opt, span_lint_and_then}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::layout::LayoutOf; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -42,15 +42,7 @@ impl LargeEnumVariant { } } -impl LintPass for LargeEnumVariant { - fn get_lints(&self) -> LintArray { - lint_array!(LARGE_ENUM_VARIANT) - } - - fn name(&self) -> &'static str { - "LargeEnumVariant" - } -} +impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 177c85adde58..191d27a1b8cf 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -3,7 +3,7 @@ use rustc::hir::def_id::DefId; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use syntax::ast::{Lit, LitKind, Name}; @@ -69,18 +69,7 @@ declare_clippy_lint! { "traits or impls with a public `len` method but no corresponding `is_empty` method" } -#[derive(Copy, Clone)] -pub struct LenZero; - -impl LintPass for LenZero { - fn get_lints(&self) -> LintArray { - lint_array!(LEN_ZERO, LEN_WITHOUT_IS_EMPTY) - } - - fn name(&self) -> &'static str { - "LenZero" - } -} +declare_lint_pass!(LenZero => [LEN_ZERO, LEN_WITHOUT_IS_EMPTY]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 1f454c4983a9..f5da2d7803e3 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -4,7 +4,7 @@ use rustc::hir; use rustc::hir::def::Def; use rustc::hir::BindingAnnotation; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -52,18 +52,7 @@ declare_clippy_lint! { "unidiomatic `let mut` declaration followed by initialization in `if`" } -#[derive(Copy, Clone)] -pub struct LetIfSeq; - -impl LintPass for LetIfSeq { - fn get_lints(&self) -> LintArray { - lint_array!(USELESS_LET_IF_SEQ) - } - - fn name(&self) -> &'static str { - "LetIfSeq" - } -} +declare_lint_pass!(LetIfSeq => [USELESS_LET_IF_SEQ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) { diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 824058a08cb3..6d051cb19c03 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -290,7 +290,7 @@ pub fn register_pre_expansion_lints( store: &mut rustc::lint::LintStore, conf: &Conf, ) { - store.register_pre_expansion_pass(Some(session), true, false, box write::Pass); + store.register_pre_expansion_pass(Some(session), true, false, box write::Write); store.register_pre_expansion_pass( Some(session), true, @@ -305,8 +305,8 @@ pub fn register_pre_expansion_lints( single_char_binding_names_threshold: conf.single_char_binding_names_threshold, }, ); - store.register_pre_expansion_pass(Some(session), true, false, box attrs::CfgAttrPass); - store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::Pass); + store.register_pre_expansion_pass(Some(session), true, false, box attrs::DeprecatedCfgAttribute); + store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::DbgMacro); } #[doc(hidden)] @@ -421,13 +421,13 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` - reg.register_late_lint_pass(box serde_api::Serde); - reg.register_early_lint_pass(box utils::internal_lints::Clippy); + reg.register_late_lint_pass(box serde_api::SerdeAPI); + reg.register_early_lint_pass(box utils::internal_lints::ClippyLintsInternal); reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new()); reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default()); - reg.register_late_lint_pass(box utils::inspector::Pass); - reg.register_late_lint_pass(box utils::author::Pass); - reg.register_late_lint_pass(box types::TypePass); + reg.register_late_lint_pass(box utils::inspector::DeepCodeInspector); + reg.register_late_lint_pass(box utils::author::Author); + reg.register_late_lint_pass(box types::Types); reg.register_late_lint_pass(box booleans::NonminimalBool); reg.register_late_lint_pass(box eq_op::EqOp); reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold)); @@ -435,68 +435,68 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box enum_clike::UnportableVariant); reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision); reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold)); - reg.register_late_lint_pass(box ptr::PointerPass); + reg.register_late_lint_pass(box ptr::Ptr); reg.register_late_lint_pass(box needless_bool::NeedlessBool); reg.register_late_lint_pass(box needless_bool::BoolComparison); - reg.register_late_lint_pass(box approx_const::Pass); - reg.register_late_lint_pass(box misc::Pass); + reg.register_late_lint_pass(box approx_const::ApproxConstant); + reg.register_late_lint_pass(box misc::MiscLints); reg.register_early_lint_pass(box precedence::Precedence); reg.register_early_lint_pass(box needless_continue::NeedlessContinue); - reg.register_late_lint_pass(box eta_reduction::EtaPass); + reg.register_late_lint_pass(box eta_reduction::EtaReduction); reg.register_late_lint_pass(box identity_op::IdentityOp); reg.register_late_lint_pass(box erasing_op::ErasingOp); reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements); reg.register_late_lint_pass(box mut_mut::MutMut); reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed); reg.register_late_lint_pass(box len_zero::LenZero); - reg.register_late_lint_pass(box attrs::AttrPass); + reg.register_late_lint_pass(box attrs::Attributes); reg.register_early_lint_pass(box collapsible_if::CollapsibleIf); reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition); reg.register_late_lint_pass(box unicode::Unicode); reg.register_late_lint_pass(box strings::StringAdd); - reg.register_early_lint_pass(box returns::ReturnPass); - reg.register_late_lint_pass(box implicit_return::Pass); - reg.register_late_lint_pass(box methods::Pass); - reg.register_late_lint_pass(box map_clone::Pass); - reg.register_late_lint_pass(box shadow::Pass); - reg.register_late_lint_pass(box types::LetPass); + reg.register_early_lint_pass(box returns::Return); + reg.register_late_lint_pass(box implicit_return::ImplicitReturn); + reg.register_late_lint_pass(box methods::Methods); + reg.register_late_lint_pass(box map_clone::MapClone); + reg.register_late_lint_pass(box shadow::Shadow); + reg.register_late_lint_pass(box types::LetUnitValue); reg.register_late_lint_pass(box types::UnitCmp); - reg.register_late_lint_pass(box loops::Pass); - reg.register_late_lint_pass(box lifetimes::LifetimePass); - reg.register_late_lint_pass(box entry::HashMapLint); - reg.register_late_lint_pass(box ranges::Pass); - reg.register_late_lint_pass(box types::CastPass); - reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold)); - reg.register_late_lint_pass(box matches::MatchPass); + reg.register_late_lint_pass(box loops::Loops); + reg.register_late_lint_pass(box lifetimes::Lifetimes); + reg.register_late_lint_pass(box entry::HashMapPass); + reg.register_late_lint_pass(box ranges::Ranges); + reg.register_late_lint_pass(box types::Casts); + reg.register_late_lint_pass(box types::TypeComplexity::new(conf.type_complexity_threshold)); + reg.register_late_lint_pass(box matches::Matches); reg.register_late_lint_pass(box minmax::MinMaxPass); - reg.register_late_lint_pass(box open_options::NonSensical); - reg.register_late_lint_pass(box zero_div_zero::Pass); - reg.register_late_lint_pass(box mutex_atomic::MutexAtomic); - reg.register_late_lint_pass(box needless_update::Pass); + reg.register_late_lint_pass(box open_options::OpenOptions); + reg.register_late_lint_pass(box zero_div_zero::ZeroDiv); + reg.register_late_lint_pass(box mutex_atomic::Mutex); + reg.register_late_lint_pass(box needless_update::NeedlessUpdate); reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow::default()); reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef); - reg.register_late_lint_pass(box no_effect::Pass); - reg.register_late_lint_pass(box temporary_assignment::Pass); + reg.register_late_lint_pass(box no_effect::NoEffect); + reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignment); reg.register_late_lint_pass(box transmute::Transmute); reg.register_late_lint_pass( box cognitive_complexity::CognitiveComplexity::new(conf.cognitive_complexity_threshold) ); - reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack}); - reg.register_early_lint_pass(box misc_early::MiscEarly); - reg.register_late_lint_pass(box panic_unimplemented::Pass); + reg.register_late_lint_pass(box escape::BoxedLocal{too_large_for_stack: conf.too_large_for_stack}); + reg.register_early_lint_pass(box misc_early::MiscEarlyLints); + reg.register_late_lint_pass(box panic_unimplemented::PanicUnimplemented); reg.register_late_lint_pass(box strings::StringLitAsBytes); reg.register_late_lint_pass(box derive::Derive); reg.register_late_lint_pass(box types::CharLitAsU8); - reg.register_late_lint_pass(box vec::Pass); - reg.register_late_lint_pass(box drop_bounds::Pass); - reg.register_late_lint_pass(box drop_forget_ref::Pass); + reg.register_late_lint_pass(box vec::UselessVec); + reg.register_late_lint_pass(box drop_bounds::DropBounds); + reg.register_late_lint_pass(box drop_forget_ref::DropForgetRef); reg.register_late_lint_pass(box empty_enum::EmptyEnum); reg.register_late_lint_pass(box types::AbsurdExtremeComparisons); reg.register_late_lint_pass(box types::InvalidUpcastComparisons); - reg.register_late_lint_pass(box regex::Pass::default()); + reg.register_late_lint_pass(box regex::Regex::default()); reg.register_late_lint_pass(box copies::CopyAndPaste); reg.register_late_lint_pass(box copy_iterator::CopyIterator); - reg.register_late_lint_pass(box format::Pass); + reg.register_late_lint_pass(box format::UselessFormat); reg.register_early_lint_pass(box formatting::Formatting); reg.register_late_lint_pass(box swap::Swap); reg.register_early_lint_pass(box if_not_else::IfNotElse); @@ -505,11 +505,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional); reg.register_late_lint_pass(box unused_label::UnusedLabel); reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default()); - reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new( + reg.register_late_lint_pass(box blacklisted_name::BlacklistedName::new( conf.blacklisted_names.iter().cloned().collect() )); reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold, conf.too_many_lines_threshold)); - reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect())); + reg.register_early_lint_pass(box doc::DocMarkdown::new(conf.doc_valid_idents.iter().cloned().collect())); reg.register_late_lint_pass(box neg_multiply::NegMultiply); reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval); reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant); @@ -521,28 +521,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box eval_order_dependence::EvalOrderDependence); reg.register_late_lint_pass(box missing_doc::MissingDoc::new()); reg.register_late_lint_pass(box missing_inline::MissingInline); - reg.register_late_lint_pass(box ok_if_let::Pass); - reg.register_late_lint_pass(box redundant_pattern_matching::Pass); - reg.register_late_lint_pass(box partialeq_ne_impl::Pass); - reg.register_early_lint_pass(box reference::Pass); - reg.register_early_lint_pass(box reference::DerefPass); + reg.register_late_lint_pass(box ok_if_let::OkIfLet); + reg.register_late_lint_pass(box redundant_pattern_matching::RedundantPatternMatching); + reg.register_late_lint_pass(box partialeq_ne_impl::PartialEqNeImpl); + reg.register_early_lint_pass(box reference::DerefAddrOf); + reg.register_early_lint_pass(box reference::RefInDeref); reg.register_early_lint_pass(box double_parens::DoubleParens); reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount); reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold)); - reg.register_late_lint_pass(box explicit_write::Pass); + reg.register_late_lint_pass(box explicit_write::ExplicitWrite); reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue); reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new( conf.trivial_copy_size_limit, ®.sess.target, )); reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping); - reg.register_early_lint_pass(box literal_representation::LiteralRepresentation::new( + reg.register_early_lint_pass(box literal_representation::DecimalLiteralRepresentation::new( conf.literal_representation_threshold )); reg.register_late_lint_pass(box use_self::UseSelf); reg.register_late_lint_pass(box bytecount::ByteCount); - reg.register_late_lint_pass(box infinite_iter::Pass); - reg.register_late_lint_pass(box inline_fn_without_body::Pass); + reg.register_late_lint_pass(box infinite_iter::InfiniteIter); + reg.register_late_lint_pass(box inline_fn_without_body::InlineFnWithoutBody); reg.register_late_lint_pass(box invalid_ref::InvalidRef); reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default()); reg.register_late_lint_pass(box types::ImplicitHasher); @@ -550,28 +550,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom); reg.register_late_lint_pass(box replace_consts::ReplaceConsts); reg.register_late_lint_pass(box types::UnitArg); - reg.register_late_lint_pass(box double_comparison::Pass); - reg.register_late_lint_pass(box question_mark::Pass); + reg.register_late_lint_pass(box double_comparison::DoubleComparisons); + reg.register_late_lint_pass(box question_mark::QuestionMark); reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl); - reg.register_early_lint_pass(box cargo_common_metadata::Pass); - reg.register_early_lint_pass(box multiple_crate_versions::Pass); - reg.register_early_lint_pass(box wildcard_dependencies::Pass); - reg.register_late_lint_pass(box map_unit_fn::Pass); - reg.register_late_lint_pass(box infallible_destructuring_match::Pass); - reg.register_late_lint_pass(box inherent_impl::Pass::default()); + reg.register_early_lint_pass(box cargo_common_metadata::CargoCommonMetadata); + reg.register_early_lint_pass(box multiple_crate_versions::MultipleCrateVersions); + reg.register_early_lint_pass(box wildcard_dependencies::WildcardDependencies); + reg.register_late_lint_pass(box map_unit_fn::MapUnit); + reg.register_late_lint_pass(box infallible_destructuring_match::InfallibleDestructingMatch); + reg.register_late_lint_pass(box inherent_impl::MultipleInherentImpl::default()); reg.register_late_lint_pass(box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd); - reg.register_late_lint_pass(box unwrap::Pass); + reg.register_late_lint_pass(box unwrap::Unwrap); reg.register_late_lint_pass(box duration_subsec::DurationSubsec); reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess); reg.register_late_lint_pass(box indexing_slicing::IndexingSlicing); reg.register_late_lint_pass(box non_copy_const::NonCopyConst); - reg.register_late_lint_pass(box ptr_offset_with_cast::Pass); + reg.register_late_lint_pass(box ptr_offset_with_cast::PtrOffsetWithCast); reg.register_late_lint_pass(box redundant_clone::RedundantClone); - reg.register_late_lint_pass(box slow_vector_initialization::Pass); + reg.register_late_lint_pass(box slow_vector_initialization::SlowVectorInit); reg.register_late_lint_pass(box types::RefToMut); reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants); reg.register_late_lint_pass(box missing_const_for_fn::MissingConstForFn); - reg.register_late_lint_pass(box transmuting_null::Pass); + reg.register_late_lint_pass(box transmuting_null::TransmutingNull); reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![ arithmetic::FLOAT_ARITHMETIC, diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index cd717e586e71..60b243784ee6 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -3,7 +3,7 @@ use rustc::hir::def::Def; use rustc::hir::intravisit::*; use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use syntax::source_map::Span; use syntax::symbol::keywords; @@ -55,20 +55,9 @@ declare_clippy_lint! { "unused lifetimes in function definitions" } -#[derive(Copy, Clone)] -pub struct LifetimePass; +declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]); -impl LintPass for LifetimePass { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES) - } - - fn name(&self) -> &'static str { - "LifeTimes" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LifetimePass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Fn(ref decl, _, ref generics, id) = item.node { check_fn_inner(cx, decl, Some(id), generics, item.span); diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index e97845314f9d..004e9f14b580 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -4,7 +4,7 @@ use crate::utils::{snippet_opt, span_lint_and_sugg}; use if_chain::if_chain; use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; use syntax::ast::*; use syntax_pos; @@ -334,23 +334,12 @@ impl WarningType { } } -#[derive(Copy, Clone)] -pub struct LiteralDigitGrouping; - -impl LintPass for LiteralDigitGrouping { - fn get_lints(&self) -> LintArray { - lint_array!( - UNREADABLE_LITERAL, - INCONSISTENT_DIGIT_GROUPING, - LARGE_DIGIT_GROUPS, - MISTYPED_LITERAL_SUFFIXES, - ) - } - - fn name(&self) -> &'static str { - "LiteralDigitGrouping" - } -} +declare_lint_pass!(LiteralDigitGrouping => [ + UNREADABLE_LITERAL, + INCONSISTENT_DIGIT_GROUPING, + LARGE_DIGIT_GROUPS, + MISTYPED_LITERAL_SUFFIXES, +]); impl EarlyLintPass for LiteralDigitGrouping { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { @@ -488,22 +477,15 @@ impl LiteralDigitGrouping { } } +#[allow(clippy::module_name_repetitions)] #[derive(Copy, Clone)] -pub struct LiteralRepresentation { +pub struct DecimalLiteralRepresentation { threshold: u64, } -impl LintPass for LiteralRepresentation { - fn get_lints(&self) -> LintArray { - lint_array!(DECIMAL_LITERAL_REPRESENTATION) - } - - fn name(&self) -> &'static str { - "DecimalLiteralRepresentation" - } -} +impl_lint_pass!(DecimalLiteralRepresentation => [DECIMAL_LITERAL_REPRESENTATION]); -impl EarlyLintPass for LiteralRepresentation { +impl EarlyLintPass for DecimalLiteralRepresentation { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { if in_external_macro(cx.sess(), expr.span) { return; @@ -515,7 +497,7 @@ impl EarlyLintPass for LiteralRepresentation { } } -impl LiteralRepresentation { +impl DecimalLiteralRepresentation { pub fn new(threshold: u64) -> Self { Self { threshold } } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index e2d648e1ffdb..bf92cf5aebc5 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -7,7 +7,7 @@ use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedV use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::middle::region; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; // use rustc::middle::region::CodeExtent; use crate::consts::{constant, Constant}; use crate::utils::usage::mutated_variables; @@ -439,39 +439,28 @@ declare_clippy_lint! { "variables used within while expression are not mutated in the body" } -#[derive(Copy, Clone)] -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!( - MANUAL_MEMCPY, - NEEDLESS_RANGE_LOOP, - EXPLICIT_ITER_LOOP, - EXPLICIT_INTO_ITER_LOOP, - ITER_NEXT_LOOP, - FOR_LOOP_OVER_RESULT, - FOR_LOOP_OVER_OPTION, - WHILE_LET_LOOP, - UNUSED_COLLECT, - NEEDLESS_COLLECT, - REVERSE_RANGE_LOOP, - EXPLICIT_COUNTER_LOOP, - EMPTY_LOOP, - WHILE_LET_ON_ITERATOR, - FOR_KV_MAP, - NEVER_LOOP, - MUT_RANGE_BOUND, - WHILE_IMMUTABLE_CONDITION, - ) - } - - fn name(&self) -> &'static str { - "Loops" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +declare_lint_pass!(Loops => [ + MANUAL_MEMCPY, + NEEDLESS_RANGE_LOOP, + EXPLICIT_ITER_LOOP, + EXPLICIT_INTO_ITER_LOOP, + ITER_NEXT_LOOP, + FOR_LOOP_OVER_RESULT, + FOR_LOOP_OVER_OPTION, + WHILE_LET_LOOP, + UNUSED_COLLECT, + NEEDLESS_COLLECT, + REVERSE_RANGE_LOOP, + EXPLICIT_COUNTER_LOOP, + EMPTY_LOOP, + WHILE_LET_ON_ITERATOR, + FOR_KV_MAP, + NEVER_LOOP, + MUT_RANGE_BOUND, + WHILE_IMMUTABLE_CONDITION, +]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { #[allow(clippy::too_many_lines)] fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { // we don't want to check expanded macros diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 1a9334ae4889..4743dec9d5c2 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -6,14 +6,11 @@ use if_chain::if_chain; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::Ident; use syntax::source_map::Span; -#[derive(Clone)] -pub struct Pass; - declare_clippy_lint! { /// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests /// `iterator.cloned()` instead @@ -42,17 +39,9 @@ declare_clippy_lint! { "using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types" } -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(MAP_CLONE) - } - - fn name(&self) -> &'static str { - "MapClone" - } -} +declare_lint_pass!(MapClone => [MAP_CLONE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) { if in_macro(e.span) { return; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 22c336b8c478..eae43cfa8240 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -4,13 +4,10 @@ use if_chain::if_chain; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Span; -#[derive(Clone)] -pub struct Pass; - declare_clippy_lint! { /// **What it does:** Checks for usage of `option.map(f)` where f is a function /// or closure that returns the unit type. @@ -77,15 +74,7 @@ declare_clippy_lint! { "using `result.map(f)`, where f is a function or closure that returns ()" } -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN) - } - - fn name(&self) -> &'static str { - "MapUnit" - } -} +declare_lint_pass!(MapUnit => [OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN]); fn is_unit_type(ty: Ty<'_>) -> bool { match ty.sty { @@ -249,7 +238,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapUnit { fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) { if in_macro(stmt.span) { return; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 97f69f87497c..bcd3119b7bc5 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -10,7 +10,7 @@ use rustc::hir::def::CtorKind; use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::cmp::Ordering; use std::collections::Bound; @@ -215,29 +215,18 @@ declare_clippy_lint! { "a wildcard enum match arm using `_`" } -#[allow(missing_copy_implementations)] -pub struct MatchPass; - -impl LintPass for MatchPass { - fn get_lints(&self) -> LintArray { - lint_array!( - SINGLE_MATCH, - MATCH_REF_PATS, - MATCH_BOOL, - SINGLE_MATCH_ELSE, - MATCH_OVERLAPPING_ARM, - MATCH_WILD_ERR_ARM, - MATCH_AS_REF, - WILDCARD_ENUM_MATCH_ARM - ) - } - - fn name(&self) -> &'static str { - "Matches" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchPass { +declare_lint_pass!(Matches => [ + SINGLE_MATCH, + MATCH_REF_PATS, + MATCH_BOOL, + SINGLE_MATCH_ELSE, + MATCH_OVERLAPPING_ARM, + MATCH_WILD_ERR_ARM, + MATCH_AS_REF, + WILDCARD_ENUM_MATCH_ARM +]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if in_external_macro(cx.sess(), expr.span) { return; diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 14266da1a108..002892903873 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -2,7 +2,7 @@ use crate::utils::{paths, snippet, span_lint_and_then, walk_ptrs_ty_depth}; use if_chain::if_chain; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::iter; @@ -27,17 +27,7 @@ declare_clippy_lint! { "calling mem::descriminant on non-enum type" } -pub struct MemDiscriminant; - -impl LintPass for MemDiscriminant { - fn get_lints(&self) -> LintArray { - lint_array![MEM_DISCRIMINANT_NON_ENUM] - } - - fn name(&self) -> &'static str { - "MemDiscriminant" - } -} +declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index 6f94580a0649..4fabfac0ab65 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -1,7 +1,7 @@ use crate::utils::{paths, span_lint}; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is @@ -21,17 +21,7 @@ declare_clippy_lint! { "`mem::forget` usage on `Drop` types, likely to cause memory leaks" } -pub struct MemForget; - -impl LintPass for MemForget { - fn get_lints(&self) -> LintArray { - lint_array![MEM_FORGET] - } - - fn name(&self) -> &'static str { - "MemForget" - } -} +declare_lint_pass!(MemForget => [MEM_FORGET]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 855de165540c..49d0a6de229a 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -2,7 +2,7 @@ use crate::utils::{match_qpath, paths, snippet_with_applicability, span_lint_and use if_chain::if_chain; use rustc::hir::{Expr, ExprKind, MutMutable, QPath}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -32,17 +32,7 @@ declare_clippy_lint! { "replacing an `Option` with `None` instead of `take()`" } -pub struct MemReplace; - -impl LintPass for MemReplace { - fn get_lints(&self) -> LintArray { - lint_array![MEM_REPLACE_OPTION_WITH_NONE] - } - - fn name(&self) -> &'static str { - "MemReplace" - } -} +declare_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 28b779416864..b7580b37279c 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -11,7 +11,7 @@ use rustc::hir; use rustc::hir::def::Def; use rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass}; use rustc::ty::{self, Predicate, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast; use syntax::source_map::{BytePos, Span}; @@ -27,9 +27,6 @@ use crate::utils::{ span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq, }; -#[derive(Clone)] -pub struct Pass; - declare_clippy_lint! { /// **What it does:** Checks for `.unwrap()` calls on `Option`s. /// @@ -777,52 +774,44 @@ declare_clippy_lint! { "using `.into_iter()` on a reference" } -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!( - OPTION_UNWRAP_USED, - RESULT_UNWRAP_USED, - SHOULD_IMPLEMENT_TRAIT, - WRONG_SELF_CONVENTION, - WRONG_PUB_SELF_CONVENTION, - OK_EXPECT, - OPTION_MAP_UNWRAP_OR, - OPTION_MAP_UNWRAP_OR_ELSE, - RESULT_MAP_UNWRAP_OR_ELSE, - OPTION_MAP_OR_NONE, - OR_FUN_CALL, - EXPECT_FUN_CALL, - CHARS_NEXT_CMP, - CHARS_LAST_CMP, - CLONE_ON_COPY, - CLONE_ON_REF_PTR, - CLONE_DOUBLE_REF, - NEW_RET_NO_SELF, - SINGLE_CHAR_PATTERN, - SEARCH_IS_SOME, - TEMPORARY_CSTRING_AS_PTR, - FILTER_NEXT, - FILTER_MAP, - MAP_FLATTEN, - ITER_NTH, - ITER_SKIP_NEXT, - GET_UNWRAP, - STRING_EXTEND_CHARS, - ITER_CLONED_COLLECT, - USELESS_ASREF, - UNNECESSARY_FOLD, - UNNECESSARY_FILTER_MAP, - INTO_ITER_ON_ARRAY, - INTO_ITER_ON_REF, - ) - } - - fn name(&self) -> &'static str { - "Methods" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +declare_lint_pass!(Methods => [ + OPTION_UNWRAP_USED, + RESULT_UNWRAP_USED, + SHOULD_IMPLEMENT_TRAIT, + WRONG_SELF_CONVENTION, + WRONG_PUB_SELF_CONVENTION, + OK_EXPECT, + OPTION_MAP_UNWRAP_OR, + OPTION_MAP_UNWRAP_OR_ELSE, + RESULT_MAP_UNWRAP_OR_ELSE, + OPTION_MAP_OR_NONE, + OR_FUN_CALL, + EXPECT_FUN_CALL, + CHARS_NEXT_CMP, + CHARS_LAST_CMP, + CLONE_ON_COPY, + CLONE_ON_REF_PTR, + CLONE_DOUBLE_REF, + NEW_RET_NO_SELF, + SINGLE_CHAR_PATTERN, + SEARCH_IS_SOME, + TEMPORARY_CSTRING_AS_PTR, + FILTER_NEXT, + FILTER_MAP, + MAP_FLATTEN, + ITER_NTH, + ITER_SKIP_NEXT, + GET_UNWRAP, + STRING_EXTEND_CHARS, + ITER_CLONED_COLLECT, + USELESS_ASREF, + UNNECESSARY_FOLD, + UNNECESSARY_FILTER_MAP, + INTO_ITER_ON_ARRAY, + INTO_ITER_ON_REF, +]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { #[allow(clippy::cognitive_complexity)] fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { if in_macro(expr.span) { diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 92cc6f2a3028..b5c064869a42 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -2,7 +2,7 @@ use crate::consts::{constant_simple, Constant}; use crate::utils::{paths, span_lint}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use std::cmp::Ordering; declare_clippy_lint! { @@ -25,17 +25,7 @@ declare_clippy_lint! { "`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant" } -pub struct MinMaxPass; - -impl LintPass for MinMaxPass { - fn get_lints(&self) -> LintArray { - lint_array!(MIN_MAX) - } - - fn name(&self) -> &'static str { - "MinMax" - } -} +declare_lint_pass!(MinMaxPass => [MIN_MAX]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index bd0b4bd4515a..774a878b331f 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -4,7 +4,7 @@ use rustc::hir::intravisit::FnKind; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax::source_map::{ExpnFormat, Span}; @@ -232,31 +232,20 @@ declare_clippy_lint! { "using `==` or `!=` on float constants instead of comparing difference with an epsilon" } -#[derive(Copy, Clone)] -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!( - TOPLEVEL_REF_ARG, - CMP_NAN, - FLOAT_CMP, - CMP_OWNED, - MODULO_ONE, - REDUNDANT_PATTERN, - USED_UNDERSCORE_BINDING, - SHORT_CIRCUIT_STATEMENT, - ZERO_PTR, - FLOAT_CMP_CONST - ) - } - - fn name(&self) -> &'static str { - "MiscLints" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +declare_lint_pass!(MiscLints => [ + TOPLEVEL_REF_ARG, + CMP_NAN, + FLOAT_CMP, + CMP_OWNED, + MODULO_ONE, + REDUNDANT_PATTERN, + USED_UNDERSCORE_BINDING, + SHORT_CIRCUIT_STATEMENT, + ZERO_PTR, + FLOAT_CMP_CONST +]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { fn check_fn( &mut self, cx: &LateContext<'a, 'tcx>, diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 3d41195f3496..5dd9a248631f 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -1,7 +1,7 @@ use crate::utils::{constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then}; use if_chain::if_chain; use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use std::char; @@ -172,27 +172,16 @@ declare_clippy_lint! { "shadowing a builtin type" } -#[derive(Copy, Clone)] -pub struct MiscEarly; - -impl LintPass for MiscEarly { - fn get_lints(&self) -> LintArray { - lint_array!( - UNNEEDED_FIELD_PATTERN, - DUPLICATE_UNDERSCORE_ARGUMENT, - REDUNDANT_CLOSURE_CALL, - DOUBLE_NEG, - MIXED_CASE_HEX_LITERALS, - UNSEPARATED_LITERAL_SUFFIX, - ZERO_PREFIXED_LITERAL, - BUILTIN_TYPE_SHADOW - ) - } - - fn name(&self) -> &'static str { - "MiscEarlyLints" - } -} +declare_lint_pass!(MiscEarlyLints => [ + UNNEEDED_FIELD_PATTERN, + DUPLICATE_UNDERSCORE_ARGUMENT, + REDUNDANT_CLOSURE_CALL, + DOUBLE_NEG, + MIXED_CASE_HEX_LITERALS, + UNSEPARATED_LITERAL_SUFFIX, + ZERO_PREFIXED_LITERAL, + BUILTIN_TYPE_SHADOW +]); // Used to find `return` statements or equivalents e.g., `?` struct ReturnVisitor { @@ -217,7 +206,7 @@ impl<'ast> Visitor<'ast> for ReturnVisitor { } } -impl EarlyLintPass for MiscEarly { +impl EarlyLintPass for MiscEarlyLints { fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) { for param in &gen.params { if let GenericParamKind::Type { .. } = param.kind { @@ -398,7 +387,7 @@ impl EarlyLintPass for MiscEarly { } } -impl MiscEarly { +impl MiscEarlyLints { fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { if_chain! { if let LitKind::Int(value, ..) = lit.node; diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 5bc949a6688a..54f34d64eb50 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -3,7 +3,7 @@ use rustc::hir; use rustc::hir::intravisit::FnKind; use rustc::hir::{Body, Constness, FnDecl, HirId}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn; use syntax_pos::Span; @@ -57,18 +57,7 @@ declare_clippy_lint! { "Lint functions definitions that could be made `const fn`" } -#[derive(Clone)] -pub struct MissingConstForFn; - -impl LintPass for MissingConstForFn { - fn get_lints(&self) -> LintArray { - lint_array!(MISSING_CONST_FOR_FN) - } - - fn name(&self) -> &'static str { - "MissingConstForFn" - } -} +declare_lint_pass!(MissingConstForFn => [MISSING_CONST_FOR_FN]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { fn check_fn( diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 721cfd870201..5d51f41aab67 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -10,7 +10,7 @@ use if_chain::if_chain; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use syntax::ast::{self, MetaItem, MetaItemKind}; use syntax::attr; use syntax::source_map::Span; @@ -103,15 +103,7 @@ impl MissingDoc { } } -impl LintPass for MissingDoc { - fn get_lints(&self) -> LintArray { - lint_array![MISSING_DOCS_IN_PRIVATE_ITEMS] - } - - fn name(&self) -> &'static str { - "MissingDoc" - } -} +impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { fn enter_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, attrs: &'tcx [ast::Attribute]) { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index c6b1b7eaf517..2c887eb54d08 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -1,7 +1,7 @@ use crate::utils::span_lint; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast; use syntax::source_map::Span; @@ -56,8 +56,6 @@ declare_clippy_lint! { "detects missing #[inline] attribute for public callables (functions, trait methods, methods...)" } -pub struct MissingInline; - fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { let has_inline = attrs.iter().any(|a| a.check_name("inline")); if !has_inline { @@ -79,15 +77,7 @@ fn is_executable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>) -> bool { }) } -impl LintPass for MissingInline { - fn get_lints(&self) -> LintArray { - lint_array![MISSING_INLINE_IN_PUBLIC_ITEMS] - } - - fn name(&self) -> &'static str { - "MissingInline" - } -} +declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) { diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 68293f58cadd..483d8944ecc6 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -2,7 +2,7 @@ use crate::utils::span_lint; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::{ast::*, source_map::DUMMY_SP}; use cargo_metadata; @@ -31,19 +31,9 @@ declare_clippy_lint! { "multiple versions of the same crate being used" } -pub struct Pass; +declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(MULTIPLE_CRATE_VERSIONS) - } - - fn name(&self) -> &'static str { - "MultipleCrateVersions" - } -} - -impl EarlyLintPass for Pass { +impl EarlyLintPass for MultipleCrateVersions { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() { metadata diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index f37f72135033..3971346dd1eb 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -3,7 +3,7 @@ use rustc::hir; use rustc::hir::intravisit; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for instances of `mut mut` references. @@ -23,18 +23,7 @@ declare_clippy_lint! { "usage of double-mut refs, e.g., `&mut &mut ...`" } -#[derive(Copy, Clone)] -pub struct MutMut; - -impl LintPass for MutMut { - fn get_lints(&self) -> LintArray { - lint_array!(MUT_MUT) - } - - fn name(&self) -> &'static str { - "MutMut" - } -} +declare_lint_pass!(MutMut => [MUT_MUT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut { fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) { diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 7333aa9f5897..9f356e7ca792 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -3,7 +3,7 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Detects giving a mutable reference to a function that only @@ -23,18 +23,7 @@ declare_clippy_lint! { "an argument passed as a mutable reference although the callee only demands an immutable reference" } -#[derive(Copy, Clone)] -pub struct UnnecessaryMutPassed; - -impl LintPass for UnnecessaryMutPassed { - fn get_lints(&self) -> LintArray { - lint_array!(UNNECESSARY_MUT_PASSED) - } - - fn name(&self) -> &'static str { - "UnneccessaryMutPassed" - } -} +declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 6800e4295f57..3b9641b354f2 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -6,7 +6,7 @@ use crate::utils::{match_type, paths, span_lint}; use rustc::hir::Expr; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast; declare_clippy_lint! { @@ -49,19 +49,9 @@ declare_clippy_lint! { "using a mutex for an integer type" } -impl LintPass for MutexAtomic { - fn get_lints(&self) -> LintArray { - lint_array!(MUTEX_ATOMIC, MUTEX_INTEGER) - } - - fn name(&self) -> &'static str { - "Mutex" - } -} - -pub struct MutexAtomic; +declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutexAtomic { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { let ty = cx.tables.expr_ty(expr); if let ty::Adt(_, subst) = ty.sty { diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 6e81ecac05fb..94febdbd8a79 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -6,7 +6,7 @@ use crate::utils::sugg::Sugg; use crate::utils::{in_macro, span_lint, span_lint_and_sugg}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax::source_map::Spanned; @@ -54,18 +54,7 @@ declare_clippy_lint! { "comparing a variable to a boolean, e.g., `if x == true` or `if x != true`" } -#[derive(Copy, Clone)] -pub struct NeedlessBool; - -impl LintPass for NeedlessBool { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_BOOL) - } - - fn name(&self) -> &'static str { - "NeedlessBool" - } -} +declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { @@ -138,18 +127,7 @@ fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool false } -#[derive(Copy, Clone)] -pub struct BoolComparison; - -impl LintPass for BoolComparison { - fn get_lints(&self) -> LintArray { - lint_array!(BOOL_COMPARISON) - } - - fn name(&self) -> &'static str { - "BoolComparison" - } -} +declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 59b4095f61ec..f32304478bb6 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -8,7 +8,7 @@ use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, MutImmutable, P use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; use rustc::ty::adjustment::{Adjust, Adjustment}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -34,15 +34,7 @@ pub struct NeedlessBorrow { derived_item: Option, } -impl LintPass for NeedlessBorrow { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_BORROW) - } - - fn name(&self) -> &'static str { - "NeedlessBorrow" - } -} +impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 2c1f87c53e35..9de5e1a03890 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -6,7 +6,7 @@ use crate::utils::{in_macro, snippet, span_lint_and_then}; use if_chain::if_chain; use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -51,18 +51,7 @@ declare_clippy_lint! { "taking a needless borrowed reference" } -#[derive(Copy, Clone)] -pub struct NeedlessBorrowedRef; - -impl LintPass for NeedlessBorrowedRef { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_BORROWED_REFERENCE) - } - - fn name(&self) -> &'static str { - "NeedlessBorrowedRef" - } -} +declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index e37e917ddec8..71eb89ae90c9 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -34,7 +34,7 @@ //! //! This lint is **warn** by default. use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use std::borrow::Cow; use syntax::ast; use syntax::source_map::{original_sp, DUMMY_SP}; @@ -106,18 +106,7 @@ declare_clippy_lint! { "`continue` statements that can be replaced by a rearrangement of code" } -#[derive(Copy, Clone)] -pub struct NeedlessContinue; - -impl LintPass for NeedlessContinue { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_CONTINUE) - } - - fn name(&self) -> &'static str { - "NeedlessContinue" - } -} +declare_lint_pass!(NeedlessContinue => [NEEDLESS_CONTINUE]); impl EarlyLintPass for NeedlessContinue { fn check_expr(&mut self, ctx: &EarlyContext<'_>, expr: &ast::Expr) { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 2300456d4c38..dee93f70819e 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -12,7 +12,7 @@ use rustc::middle::expr_use_visitor as euv; use rustc::middle::mem_categorization as mc; use rustc::traits; use rustc::ty::{self, RegionKind, TypeFoldable}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_target::spec::abi::Abi; @@ -50,17 +50,7 @@ declare_clippy_lint! { "functions taking arguments by value, but not consuming them in its body" } -pub struct NeedlessPassByValue; - -impl LintPass for NeedlessPassByValue { - fn get_lints(&self) -> LintArray { - lint_array![NEEDLESS_PASS_BY_VALUE] - } - - fn name(&self) -> &'static str { - "NeedlessPassByValue" - } -} +declare_lint_pass!(NeedlessPassByValue => [NEEDLESS_PASS_BY_VALUE]); macro_rules! need { ($e: expr) => { diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 2ce9bf78aa6c..316395acf263 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -2,7 +2,7 @@ use crate::utils::span_lint; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for needlessly including a base struct on update @@ -26,20 +26,9 @@ declare_clippy_lint! { "using `Foo { ..base }` when there are no missing fields" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_UPDATE) - } - - fn name(&self) -> &'static str { - "NeedUpdate" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.node { let ty = cx.tables.expr_ty(expr); diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 7b074f438f4b..e05a953b3060 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use crate::utils::{self, paths, span_lint}; @@ -42,17 +42,7 @@ declare_clippy_lint! { "The use of negated comparison operators on partially ordered types may produce confusing code." } -pub struct NoNegCompOpForPartialOrd; - -impl LintPass for NoNegCompOpForPartialOrd { - fn get_lints(&self) -> LintArray { - lint_array!(NEG_CMP_OP_ON_PARTIAL_ORD) - } - - fn name(&self) -> &'static str { - "NoNegCompOpForPartialOrd" - } -} +declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 757a3cb6cd5b..c235661a432b 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::source_map::{Span, Spanned}; use crate::consts::{self, Constant}; @@ -23,18 +23,7 @@ declare_clippy_lint! { "multiplying integers with -1" } -#[derive(Copy, Clone)] -pub struct NegMultiply; - -impl LintPass for NegMultiply { - fn get_lints(&self) -> LintArray { - lint_array!(NEG_MULTIPLY) - } - - fn name(&self) -> &'static str { - "NegMultiply" - } -} +declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]); #[allow(clippy::match_same_arms)] impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 3bf0c22c322c..55a4b1588c2b 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -7,7 +7,7 @@ use rustc::hir::def_id::DefId; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty::{self, Ty}; use rustc::util::nodemap::NodeSet; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; use syntax::source_map::Span; @@ -89,15 +89,7 @@ pub struct NewWithoutDefault { impling_types: Option, } -impl LintPass for NewWithoutDefault { - fn get_lints(&self) -> LintArray { - lint_array!(NEW_WITHOUT_DEFAULT) - } - - fn name(&self) -> &'static str { - "NewWithoutDefault" - } -} +impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 74a9b353ea97..1836e929e180 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -2,7 +2,7 @@ use crate::utils::{has_drop, in_macro, snippet_opt, span_lint, span_lint_and_sug use rustc::hir::def::Def; use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::ops::Deref; @@ -93,20 +93,9 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { } } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(NO_EFFECT, UNNECESSARY_OPERATION) - } - - fn name(&self) -> &'static str { - "NoEffect" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect { fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { if let StmtKind::Semi(ref expr) = stmt.node { if has_no_effect(cx, expr) { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 8b7b6b6c42c6..1d947784576a 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -9,7 +9,7 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass}; use rustc::ty::adjustment::Adjust; use rustc::ty::{Ty, TypeFlags}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use rustc_typeck::hir_ty_to_ty; use syntax_pos::{Span, DUMMY_SP}; @@ -143,17 +143,7 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: S }); } -pub struct NonCopyConst; - -impl LintPass for NonCopyConst { - fn get_lints(&self) -> LintArray { - lint_array!(DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST) - } - - fn name(&self) -> &'static str { - "NonCopyConst" - } -} +declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item) { diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 39d69d0bd51b..b1d180c6ceb3 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,6 +1,6 @@ use crate::utils::{span_lint, span_lint_and_then}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use syntax::ast::*; use syntax::attr; use syntax::source_map::Span; @@ -63,19 +63,12 @@ declare_clippy_lint! { "unclear name" } +#[derive(Copy, Clone)] pub struct NonExpressiveNames { pub single_char_binding_names_threshold: u64, } -impl LintPass for NonExpressiveNames { - fn get_lints(&self) -> LintArray { - lint_array!(SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS) - } - - fn name(&self) -> &'static str { - "NoneExpressiveNames" - } -} +impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]); struct ExistingName { interned: LocalInternedString, diff --git a/clippy_lints/src/ok_if_let.rs b/clippy_lints/src/ok_if_let.rs index 11c392b581ad..01d41f679dbb 100644 --- a/clippy_lints/src/ok_if_let.rs +++ b/clippy_lints/src/ok_if_let.rs @@ -2,7 +2,7 @@ use crate::utils::{match_type, method_chain_args, paths, snippet, span_help_and_ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:*** Checks for unnecessary `ok()` in if let. @@ -34,20 +34,9 @@ declare_clippy_lint! { "usage of `ok()` in `if let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(IF_LET_SOME_RESULT) - } - - fn name(&self) -> &'static str { - "OkIfLet" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if_chain! { //begin checking variables if let ExprKind::Match(ref op, ref body, ref source) = expr.node; //test if expr is a match diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 43c7f3884d3a..062534333c23 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -1,7 +1,7 @@ use crate::utils::{match_type, paths, span_lint, walk_ptrs_ty}; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; use syntax::source_map::{Span, Spanned}; @@ -25,20 +25,9 @@ declare_clippy_lint! { "nonsensical combination of options for opening a file" } -#[derive(Copy, Clone)] -pub struct NonSensical; +declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); -impl LintPass for NonSensical { - fn get_lints(&self) -> LintArray { - lint_array!(NONSENSICAL_OPEN_OPTIONS) - } - - fn name(&self) -> &'static str { - "OpenOptions" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSensical { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { if let ExprKind::MethodCall(ref path, _, ref arguments) = e.node { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index c041f3a959a0..c598e915a5af 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -2,7 +2,7 @@ use crate::utils::{span_lint, SpanlessEq}; use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Detects classic underflow/overflow checks. @@ -21,18 +21,7 @@ declare_clippy_lint! { "overflow checks inspired by C which are likely to panic" } -#[derive(Copy, Clone)] -pub struct OverflowCheckConditional; - -impl LintPass for OverflowCheckConditional { - fn get_lints(&self) -> LintArray { - lint_array!(OVERFLOW_CHECK_CONDITIONAL) - } - - fn name(&self) -> &'static str { - "OverflowCheckConditional" - } -} +declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { // a + b < a, a > a + b, a < a - b, a - b > a diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index af0a9214342e..57ff7536a386 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -2,7 +2,7 @@ use crate::utils::{is_direct_expn_of, is_expn_of, paths, resolve_node, span_lint use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; use syntax::ptr::P; use syntax_pos::Span; @@ -42,19 +42,9 @@ declare_clippy_lint! { "`unimplemented!` should not be present in production code" } -pub struct Pass; +declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(PANIC_PARAMS, UNIMPLEMENTED) - } - - fn name(&self) -> &'static str { - "PanicUnimplemented" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if_chain! { if let ExprKind::Block(ref block, _) = expr.node; diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 2f034b9f1aac..6a6725b4d10b 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -2,7 +2,7 @@ use crate::utils::{is_automatically_derived, span_lint_hir}; use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`. @@ -28,20 +28,9 @@ declare_clippy_lint! { "re-implementing `PartialEq::ne`" } -#[derive(Clone, Copy)] -pub struct Pass; +declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(PARTIALEQ_NE_IMPL) - } - - fn name(&self) -> &'static str { - "PartialEqNeImpl" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if_chain! { if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node; diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 6819ac744744..52c11cacaac0 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -1,6 +1,6 @@ use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::*; use syntax::source_map::Spanned; @@ -28,18 +28,7 @@ declare_clippy_lint! { "operations where precedence may be unclear" } -#[derive(Copy, Clone)] -pub struct Precedence; - -impl LintPass for Precedence { - fn get_lints(&self) -> LintArray { - lint_array!(PRECEDENCE) - } - - fn name(&self) -> &'static str { - "Precedence" - } -} +declare_lint_pass!(Precedence => [PRECEDENCE]); impl EarlyLintPass for Precedence { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 331f4216d26f..af69d62ddb73 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -7,7 +7,7 @@ use rustc::hir::QPath; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::borrow::Cow; use syntax::source_map::Span; @@ -94,20 +94,9 @@ declare_clippy_lint! { "fns that create mutable refs from immutable ref args" } -#[derive(Copy, Clone)] -pub struct PointerPass; +declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]); -impl LintPass for PointerPass { - fn get_lints(&self) -> LintArray { - lint_array!(PTR_ARG, CMP_NULL, MUT_FROM_REF) - } - - fn name(&self) -> &'static str { - "Ptr" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Fn(ref decl, _, _, body_id) = item.node { check_fn(cx, decl, item.hir_id, Some(body_id)); diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index 21c7e7213382..2d3c3298f584 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -1,5 +1,7 @@ use crate::utils; -use rustc::{declare_tool_lint, hir, lint, lint_array}; +use rustc::hir::{Expr, ExprKind}; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::fmt; @@ -39,21 +41,10 @@ declare_clippy_lint! { "unneeded pointer offset cast" } -#[derive(Copy, Clone, Debug)] -pub struct Pass; +declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]); -impl lint::LintPass for Pass { - fn get_lints(&self) -> lint::LintArray { - lint_array!(PTR_OFFSET_WITH_CAST) - } - - fn name(&self) -> &'static str { - "PtrOffsetWithCast" - } -} - -impl<'a, 'tcx> lint::LateLintPass<'a, 'tcx> for Pass { - fn check_expr(&mut self, cx: &lint::LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { // Check if the expressions is a ptr.offset or ptr.wrapping_offset method call let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) { Some(call_arg) => call_arg, @@ -84,11 +75,8 @@ impl<'a, 'tcx> lint::LateLintPass<'a, 'tcx> for Pass { } // If the given expression is a cast from a usize, return the lhs of the cast -fn expr_as_cast_from_usize<'a, 'tcx>( - cx: &lint::LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, -) -> Option<&'tcx hir::Expr> { - if let hir::ExprKind::Cast(ref cast_lhs_expr, _) = expr.node { +fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<&'tcx Expr> { + if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.node { if is_expr_ty_usize(cx, &cast_lhs_expr) { return Some(cast_lhs_expr); } @@ -99,10 +87,10 @@ fn expr_as_cast_from_usize<'a, 'tcx>( // If the given expression is a ptr::offset or ptr::wrapping_offset method call, return the // receiver, the arg of the method call, and the method. fn expr_as_ptr_offset_call<'a, 'tcx>( - cx: &lint::LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr, -) -> Option<(&'tcx hir::Expr, &'tcx hir::Expr, Method)> { - if let hir::ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node { + cx: &LateContext<'a, 'tcx>, + expr: &'tcx Expr, +) -> Option<(&'tcx Expr, &'tcx Expr, Method)> { + if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node { if is_expr_ty_raw_ptr(cx, &args[0]) { if path_segment.ident.name == "offset" { return Some((&args[0], &args[1], Method::Offset)); @@ -116,20 +104,20 @@ fn expr_as_ptr_offset_call<'a, 'tcx>( } // Is the type of the expression a usize? -fn is_expr_ty_usize<'a, 'tcx>(cx: &lint::LateContext<'a, 'tcx>, expr: &hir::Expr) -> bool { +fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool { cx.tables.expr_ty(expr) == cx.tcx.types.usize } // Is the type of the expression a raw pointer? -fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &lint::LateContext<'a, 'tcx>, expr: &hir::Expr) -> bool { +fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool { cx.tables.expr_ty(expr).is_unsafe_ptr() } fn build_suggestion<'a, 'tcx>( - cx: &lint::LateContext<'a, 'tcx>, + cx: &LateContext<'a, 'tcx>, method: Method, - receiver_expr: &hir::Expr, - cast_lhs_expr: &hir::Expr, + receiver_expr: &Expr, + cast_lhs_expr: &Expr, ) -> Option { let receiver = utils::snippet_opt(cx, receiver_expr.span)?; let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?; diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index b2e8315716ab..c5388905032c 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -2,7 +2,7 @@ use if_chain::if_chain; use rustc::hir::def::Def; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ptr::P; @@ -34,20 +34,9 @@ declare_clippy_lint! { "checks for expressions that could be replaced by the question mark operator" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(QuestionMark => [QUESTION_MARK]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(QUESTION_MARK) - } - - fn name(&self) -> &'static str { - "QuestionMark" - } -} - -impl Pass { +impl QuestionMark { /// Checks if the given expression on the given context matches the following structure: /// /// ```ignore @@ -165,7 +154,7 @@ impl Pass { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for QuestionMark { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { Self::check_is_none_and_early_return_none(cx, expr); } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 84c9509844fc..a18ee4c2b896 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::RangeLimits; use syntax::source_map::Spanned; @@ -86,25 +86,14 @@ declare_clippy_lint! { "`x..=(y-1)` reads better as `x..y`" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(Ranges => [ + ITERATOR_STEP_BY_ZERO, + RANGE_ZIP_WITH_LEN, + RANGE_PLUS_ONE, + RANGE_MINUS_ONE +]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!( - ITERATOR_STEP_BY_ZERO, - RANGE_ZIP_WITH_LEN, - RANGE_PLUS_ONE, - RANGE_MINUS_ONE - ) - } - - fn name(&self) -> &'static str { - "Ranges" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::MethodCall(ref path, _, ref args) = expr.node { let name = path.ident.as_str(); diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 9df7009c0743..92628cfb4a48 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -13,7 +13,7 @@ use rustc::mir::{ TerminatorKind, }; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::convert::TryFrom; use syntax::source_map::{BytePos, Span}; @@ -64,17 +64,7 @@ declare_clippy_lint! { "`clone()` of an owned value that is going to be dropped immediately" } -pub struct RedundantClone; - -impl LintPass for RedundantClone { - fn get_lints(&self) -> LintArray { - lint_array!(REDUNDANT_CLONE) - } - - fn name(&self) -> &'static str { - "RedundantClone" - } -} +declare_lint_pass!(RedundantClone => [REDUNDANT_CLONE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone { #[allow(clippy::too_many_lines)] diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 7e53035d9dce..389f72057890 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -1,6 +1,6 @@ use crate::utils::span_lint_and_sugg; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::*; @@ -32,17 +32,7 @@ declare_clippy_lint! { "checks for fields in struct literals where shorthands could be used" } -pub struct RedundantFieldNames; - -impl LintPass for RedundantFieldNames { - fn get_lints(&self) -> LintArray { - lint_array!(REDUNDANT_FIELD_NAMES) - } - - fn name(&self) -> &'static str { - "RedundantFieldNames" - } -} +declare_lint_pass!(RedundantFieldNames => [REDUNDANT_FIELD_NAMES]); impl EarlyLintPass for RedundantFieldNames { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { diff --git a/clippy_lints/src/redundant_pattern_matching.rs b/clippy_lints/src/redundant_pattern_matching.rs index ebc5e240a954..fe1a29b98833 100644 --- a/clippy_lints/src/redundant_pattern_matching.rs +++ b/clippy_lints/src/redundant_pattern_matching.rs @@ -1,7 +1,7 @@ use crate::utils::{match_qpath, paths, snippet, span_lint_and_then}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax::ptr::P; @@ -42,20 +42,9 @@ declare_clippy_lint! { "use the proper utility function avoiding an `if let`" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(RedundantPatternMatching => [REDUNDANT_PATTERN_MATCHING]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(REDUNDANT_PATTERN_MATCHING) - } - - fn name(&self) -> &'static str { - "RedundantPatternMatching" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Match(ref op, ref arms, ref match_source) = expr.node { match match_source { diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index d5447027acba..2ee00a2f1034 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -1,7 +1,7 @@ use crate::utils::{snippet_with_applicability, span_lint_and_sugg}; use if_chain::if_chain; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::{Expr, ExprKind, UnOp}; @@ -24,17 +24,7 @@ declare_clippy_lint! { "use of `*&` or `*&mut` in an expression" } -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(DEREF_ADDROF) - } - - fn name(&self) -> &'static str { - "DerefAddrOf" - } -} +declare_lint_pass!(DerefAddrOf => [DEREF_ADDROF]); fn without_parens(mut e: &Expr) -> &Expr { while let ExprKind::Paren(ref child_e) = e.node { @@ -43,7 +33,7 @@ fn without_parens(mut e: &Expr) -> &Expr { e } -impl EarlyLintPass for Pass { +impl EarlyLintPass for DerefAddrOf { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { if_chain! { if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node; @@ -82,19 +72,9 @@ declare_clippy_lint! { "Use of reference in auto dereference expression." } -pub struct DerefPass; - -impl LintPass for DerefPass { - fn get_lints(&self) -> LintArray { - lint_array!(REF_IN_DEREF) - } - - fn name(&self) -> &'static str { - "RefInDeref" - } -} +declare_lint_pass!(RefInDeref => [REF_IN_DEREF]); -impl EarlyLintPass for DerefPass { +impl EarlyLintPass for RefInDeref { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { if_chain! { if let ExprKind::Field(ref object, _) = e.node; diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 4d1dbc75c949..2c912741f8ca 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use regex_syntax; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashSet; use std::convert::TryFrom; use syntax::ast::{LitKind, StrStyle}; @@ -67,22 +67,14 @@ declare_clippy_lint! { } #[derive(Clone, Default)] -pub struct Pass { +pub struct Regex { spans: FxHashSet, last: Option, } -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX) - } - - fn name(&self) -> &'static str { - "Regex" - } -} +impl_lint_pass!(Regex => [INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx Crate) { self.spans.clear(); } diff --git a/clippy_lints/src/replace_consts.rs b/clippy_lints/src/replace_consts.rs index cd7dd8c49070..4dc5cea450d1 100644 --- a/clippy_lints/src/replace_consts.rs +++ b/clippy_lints/src/replace_consts.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir; use rustc::hir::def::Def; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -29,17 +29,7 @@ declare_clippy_lint! { "Lint usages of standard library `const`s that could be replaced by `const fn`s" } -pub struct ReplaceConsts; - -impl LintPass for ReplaceConsts { - fn get_lints(&self) -> LintArray { - lint_array!(REPLACE_CONSTS) - } - - fn name(&self) -> &'static str { - "ReplaceConsts" - } -} +declare_lint_pass!(ReplaceConsts => [REPLACE_CONSTS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 3995d9f2819c..ba871c464ead 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -1,6 +1,6 @@ use if_chain::if_chain; use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast; use syntax::source_map::Span; @@ -83,10 +83,9 @@ declare_clippy_lint! { "needless unit expression" } -#[derive(Copy, Clone)] -pub struct ReturnPass; +declare_lint_pass!(Return => [NEEDLESS_RETURN, LET_AND_RETURN, UNUSED_UNIT]); -impl ReturnPass { +impl Return { // Check the final stmt or expr in a block for unnecessary return. fn check_block_return(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) { if let Some(stmt) = block.stmts.last() { @@ -177,17 +176,7 @@ impl ReturnPass { } } -impl LintPass for ReturnPass { - fn get_lints(&self) -> LintArray { - lint_array!(NEEDLESS_RETURN, LET_AND_RETURN, UNUSED_UNIT) - } - - fn name(&self) -> &'static str { - "Return" - } -} - -impl EarlyLintPass for ReturnPass { +impl EarlyLintPass for Return { fn check_fn(&mut self, cx: &EarlyContext<'_>, kind: FnKind<'_>, decl: &ast::FnDecl, span: Span, _: ast::NodeId) { match kind { FnKind::ItemFn(.., block) | FnKind::Method(.., block) => self.check_block_return(cx, block), diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index e9479af54190..f3d4ff35d487 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -1,7 +1,7 @@ use crate::utils::{get_trait_def_id, paths, span_lint}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for mis-uses of the serde API. @@ -18,20 +18,9 @@ declare_clippy_lint! { "various things that will negatively affect your serde experience" } -#[derive(Copy, Clone)] -pub struct Serde; +declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]); -impl LintPass for Serde { - fn get_lints(&self) -> LintArray { - lint_array!(SERDE_API_MISUSE) - } - - fn name(&self) -> &'static str { - "SerdeAPI" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Serde { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SerdeAPI { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref items) = item.node { let did = trait_ref.path.def.def_id(); diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 99580affef67..e43b591a9cdc 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -4,7 +4,7 @@ use rustc::hir::intravisit::FnKind; use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::source_map::Span; declare_clippy_lint! { @@ -75,20 +75,9 @@ declare_clippy_lint! { "rebinding a name without even using the original value" } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(Shadow => [SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED) - } - - fn name(&self) -> &'static str { - "Shadow" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow { fn check_fn( &mut self, cx: &LateContext<'a, 'tcx>, diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 888405983fd5..0bc992b3191b 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc::hir::intravisit::{walk_block, walk_expr, walk_stmt, NestedVisitorMap, Visitor}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax_pos::symbol::Symbol; @@ -30,18 +30,7 @@ declare_clippy_lint! { "slow vector initialization" } -#[derive(Copy, Clone, Default)] -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(SLOW_VECTOR_INITIALIZATION,) - } - - fn name(&self) -> &'static str { - "SlowVectorInit" - } -} +declare_lint_pass!(SlowVectorInit => [SLOW_VECTOR_INITIALIZATION]); /// `VecAllocation` contains data regarding a vector allocated with `with_capacity` and then /// assigned to a variable. For example, `let mut vec = Vec::with_capacity(0)` or @@ -67,7 +56,7 @@ enum InitializationType<'tcx> { Resize(&'tcx Expr), } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { // Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)` if_chain! { @@ -113,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { } } -impl Pass { +impl SlowVectorInit { /// Checks if the given expression is `Vec::with_capacity(..)`. It will return the expression /// of the first argument of `with_capacity` call if it matches or `None` if it does not. fn is_vec_with_capacity(expr: &Expr) -> Option<&Expr> { diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index cd23722bef4f..f1f006206ffc 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,6 +1,6 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Spanned; @@ -73,18 +73,7 @@ declare_clippy_lint! { "calling `as_bytes` on a string literal instead of using a byte string literal" } -#[derive(Copy, Clone)] -pub struct StringAdd; - -impl LintPass for StringAdd { - fn get_lints(&self) -> LintArray { - lint_array!(STRING_ADD, STRING_ADD_ASSIGN) - } - - fn name(&self) -> &'static str { - "StringAdd" - } -} +declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { @@ -149,18 +138,7 @@ fn is_add(cx: &LateContext<'_, '_>, src: &Expr, target: &Expr) -> bool { } } -#[derive(Copy, Clone)] -pub struct StringLitAsBytes; - -impl LintPass for StringLitAsBytes { - fn get_lints(&self) -> LintArray { - lint_array!(STRING_LIT_AS_BYTES) - } - - fn name(&self) -> &'static str { - "StringLiteralAsBytes" - } -} +declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 76ca1dc28482..f7de396c3897 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Lints for suspicious operations in impls of arithmetic operators, e.g. @@ -49,18 +49,7 @@ declare_clippy_lint! { "suspicious use of operators in impl of OpAssign trait" } -#[derive(Copy, Clone)] -pub struct SuspiciousImpl; - -impl LintPass for SuspiciousImpl { - fn get_lints(&self) -> LintArray { - lint_array![SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_ASSIGN_IMPL] - } - - fn name(&self) -> &'static str { - "SuspiciousImpl" - } -} +declare_lint_pass!(SuspiciousImpl => [SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_ASSIGN_IMPL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 32a67f394399..fc5b2150d52c 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -7,7 +7,7 @@ use matches::matches; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; declare_clippy_lint! { @@ -52,18 +52,7 @@ declare_clippy_lint! { "`foo = bar; bar = foo` sequence" } -#[derive(Copy, Clone)] -pub struct Swap; - -impl LintPass for Swap { - fn get_lints(&self) -> LintArray { - lint_array![MANUAL_SWAP, ALMOST_SWAPPED] - } - - fn name(&self) -> &'static str { - "Swap" - } -} +declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Swap { fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block) { diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index a6126f372828..e03c6689a106 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -3,7 +3,7 @@ use crate::utils::span_lint; use rustc::hir::def::Def; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for construction of a structure or tuple just to @@ -37,20 +37,9 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { } } -#[derive(Copy, Clone)] -pub struct Pass; +declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(TEMPORARY_ASSIGNMENT) - } - - fn name(&self) -> &'static str { - "TemporaryAssignment" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TemporaryAssignment { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Assign(target, _) = &expr.node { let mut base = target; diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index f07fe97020bd..d2d3d3cedb71 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::borrow::Cow; use syntax::ast; @@ -203,27 +203,17 @@ declare_clippy_lint! { "transmutes from a pointer to a pointer / a reference to a reference" } -pub struct Transmute; - -impl LintPass for Transmute { - fn get_lints(&self) -> LintArray { - lint_array!( - CROSSPOINTER_TRANSMUTE, - TRANSMUTE_PTR_TO_REF, - TRANSMUTE_PTR_TO_PTR, - USELESS_TRANSMUTE, - WRONG_TRANSMUTE, - TRANSMUTE_INT_TO_CHAR, - TRANSMUTE_BYTES_TO_STR, - TRANSMUTE_INT_TO_BOOL, - TRANSMUTE_INT_TO_FLOAT, - ) - } - - fn name(&self) -> &'static str { - "Transmute" - } -} +declare_lint_pass!(Transmute => [ + CROSSPOINTER_TRANSMUTE, + TRANSMUTE_PTR_TO_REF, + TRANSMUTE_PTR_TO_PTR, + USELESS_TRANSMUTE, + WRONG_TRANSMUTE, + TRANSMUTE_INT_TO_CHAR, + TRANSMUTE_BYTES_TO_STR, + TRANSMUTE_INT_TO_BOOL, + TRANSMUTE_INT_TO_FLOAT, +]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { #[allow(clippy::similar_names, clippy::too_many_lines)] diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 445abc4832aa..a5bb05dc6418 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -3,7 +3,7 @@ use crate::utils::{match_qpath, span_lint}; use if_chain::if_chain; use rustc::hir::{Expr, ExprKind}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; declare_clippy_lint! { @@ -24,22 +24,11 @@ declare_clippy_lint! { "transmutes from a null pointer to a reference, which is undefined behavior" } -#[derive(Copy, Clone)] -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(TRANSMUTING_NULL,) - } - - fn name(&self) -> &'static str { - "TransmutingNull" - } -} +declare_lint_pass!(TransmutingNull => [TRANSMUTING_NULL]); const LINT_MSG: &str = "transmuting a known null pointer into a reference."; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if in_external_macro(cx.sess(), expr.span) { return; diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index e0f19a146541..36dba74615a4 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -9,7 +9,7 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::session::config::Config as SessionConfig; use rustc::ty::{self, FnSig}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; @@ -137,15 +137,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef { } } -impl LintPass for TriviallyCopyPassByRef { - fn get_lints(&self) -> LintArray { - lint_array![TRIVIALLY_COPY_PASS_BY_REF] - } - - fn name(&self) -> &'static str { - "TrivallyCopyPassByRef" - } -} +impl_lint_pass!(TriviallyCopyPassByRef => [TRIVIALLY_COPY_PASS_BY_REF]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 744ee0f6c202..30c7059a4b62 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -11,7 +11,7 @@ use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty::layout::LayoutOf; use rustc::ty::{self, InferTy, Ty, TyCtxt, TypeckTables}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; use rustc_target::spec::abi::Abi; use rustc_typeck::hir_ty_to_ty; @@ -27,9 +27,6 @@ use crate::utils::{ span_lint, span_lint_and_sugg, span_lint_and_then, unsext, }; -/// Handles all the linting of funky types -pub struct TypePass; - declare_clippy_lint! { /// **What it does:** Checks for use of `Box>` anywhere in the code. /// @@ -165,17 +162,9 @@ declare_clippy_lint! { "a borrow of a boxed type" } -impl LintPass for TypePass { - fn get_lints(&self) -> LintArray { - lint_array!(BOX_VEC, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX) - } +declare_lint_pass!(Types => [BOX_VEC, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX]); - fn name(&self) -> &'static str { - "Types" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types { fn check_fn(&mut self, cx: &LateContext<'_, '_>, _: FnKind<'_>, decl: &FnDecl, _: &Body, _: Span, id: HirId) { // Skip trait implementations; see issue #605. if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_hir_id(cx.tcx.hir().get_parent_item(id)) { @@ -446,8 +435,6 @@ fn is_any_trait(t: &hir::Ty) -> bool { false } -pub struct LetPass; - declare_clippy_lint! { /// **What it does:** Checks for binding a unit value. /// @@ -467,17 +454,9 @@ declare_clippy_lint! { "creating a let binding to a value of unit type, which usually can't be used afterwards" } -impl LintPass for LetPass { - fn get_lints(&self) -> LintArray { - lint_array!(LET_UNIT_VALUE) - } - - fn name(&self) -> &'static str { - "LetUnitValue" - } -} +declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetPass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue { fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { if let StmtKind::Local(ref local) = stmt.node { if is_unit(cx.tables.pat_ty(&local.pat)) { @@ -539,17 +518,7 @@ declare_clippy_lint! { "comparing unit values" } -pub struct UnitCmp; - -impl LintPass for UnitCmp { - fn get_lints(&self) -> LintArray { - lint_array!(UNIT_CMP) - } - - fn name(&self) -> &'static str { - "UnicCmp" - } -} +declare_lint_pass!(UnitCmp => [UNIT_CMP]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { @@ -598,17 +567,7 @@ declare_clippy_lint! { "passing unit to a function" } -pub struct UnitArg; - -impl LintPass for UnitArg { - fn get_lints(&self) -> LintArray { - lint_array!(UNIT_ARG) - } - - fn name(&self) -> &'static str { - "UnitArg" - } -} +declare_lint_pass!(UnitArg => [UNIT_ARG]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { @@ -683,8 +642,6 @@ fn is_unit_literal(expr: &Expr) -> bool { } } -pub struct CastPass; - declare_clippy_lint! { /// **What it does:** Checks for casts from any numerical to a float type where /// the receiving type cannot store all values from the original type without @@ -1113,25 +1070,17 @@ fn check_lossless(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: T } } -impl LintPass for CastPass { - fn get_lints(&self) -> LintArray { - lint_array!( - CAST_PRECISION_LOSS, - CAST_SIGN_LOSS, - CAST_POSSIBLE_TRUNCATION, - CAST_POSSIBLE_WRAP, - CAST_LOSSLESS, - UNNECESSARY_CAST, - CAST_PTR_ALIGNMENT, - FN_TO_NUMERIC_CAST, - FN_TO_NUMERIC_CAST_WITH_TRUNCATION, - ) - } - - fn name(&self) -> &'static str { - "Casts" - } -} +declare_lint_pass!(Casts => [ + CAST_PRECISION_LOSS, + CAST_SIGN_LOSS, + CAST_POSSIBLE_TRUNCATION, + CAST_POSSIBLE_WRAP, + CAST_LOSSLESS, + UNNECESSARY_CAST, + CAST_PTR_ALIGNMENT, + FN_TO_NUMERIC_CAST, + FN_TO_NUMERIC_CAST_WITH_TRUNCATION, +]); // Check if the given type is either `core::ffi::c_void` or // one of the platform specific `libc::::c_void` of libc. @@ -1159,7 +1108,7 @@ fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Cast(ref ex, _) = expr.node { let (cast_from, cast_to) = (cx.tables.expr_ty(ex), cx.tables.expr_ty(expr)); @@ -1342,27 +1291,19 @@ declare_clippy_lint! { "usage of very complex types that might be better factored into `type` definitions" } -pub struct TypeComplexityPass { +pub struct TypeComplexity { threshold: u64, } -impl TypeComplexityPass { +impl TypeComplexity { pub fn new(threshold: u64) -> Self { Self { threshold } } } -impl LintPass for TypeComplexityPass { - fn get_lints(&self) -> LintArray { - lint_array!(TYPE_COMPLEXITY) - } - - fn name(&self) -> &'static str { - "TypeComplexityPass" - } -} +impl_lint_pass!(TypeComplexity => [TYPE_COMPLEXITY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { fn check_fn( &mut self, cx: &LateContext<'a, 'tcx>, @@ -1412,7 +1353,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass { } } -impl<'a, 'tcx> TypeComplexityPass { +impl<'a, 'tcx> TypeComplexity { fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl) { for arg in &decl.inputs { self.check_type(cx, arg); @@ -1518,17 +1459,7 @@ declare_clippy_lint! { "casting a character literal to u8" } -pub struct CharLitAsU8; - -impl LintPass for CharLitAsU8 { - fn get_lints(&self) -> LintArray { - lint_array!(CHAR_LIT_AS_U8) - } - - fn name(&self) -> &'static str { - "CharLiteralAsU8" - } -} +declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { @@ -1582,17 +1513,7 @@ declare_clippy_lint! { "a comparison with a maximum or minimum value that is always true or false" } -pub struct AbsurdExtremeComparisons; - -impl LintPass for AbsurdExtremeComparisons { - fn get_lints(&self) -> LintArray { - lint_array!(ABSURD_EXTREME_COMPARISONS) - } - - fn name(&self) -> &'static str { - "AbsurdExtremeComparisons" - } -} +declare_lint_pass!(AbsurdExtremeComparisons => [ABSURD_EXTREME_COMPARISONS]); enum ExtremeType { Minimum, @@ -1761,17 +1682,7 @@ declare_clippy_lint! { "a comparison involving an upcast which is always true or false" } -pub struct InvalidUpcastComparisons; - -impl LintPass for InvalidUpcastComparisons { - fn get_lints(&self) -> LintArray { - lint_array!(INVALID_UPCAST_COMPARISONS) - } - - fn name(&self) -> &'static str { - "InvalidUpcastComparisons" - } -} +declare_lint_pass!(InvalidUpcastComparisons => [INVALID_UPCAST_COMPARISONS]); #[derive(Copy, Clone, Debug, Eq)] enum FullInt { @@ -2010,17 +1921,7 @@ declare_clippy_lint! { "missing generalization over different hashers" } -pub struct ImplicitHasher; - -impl LintPass for ImplicitHasher { - fn get_lints(&self) -> LintArray { - lint_array!(IMPLICIT_HASHER) - } - - fn name(&self) -> &'static str { - "ImplicitHasher" - } -} +declare_lint_pass!(ImplicitHasher => [IMPLICIT_HASHER]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher { #[allow(clippy::cast_possible_truncation, clippy::too_many_lines)] @@ -2365,17 +2266,7 @@ declare_clippy_lint! { "a cast of reference to a mutable pointer" } -pub struct RefToMut; - -impl LintPass for RefToMut { - fn get_lints(&self) -> LintArray { - lint_array!(CAST_REF_TO_MUT) - } - - fn name(&self) -> &'static str { - "RefToMut" - } -} +declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 4d9e2f18650e..d96596bbb525 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -1,7 +1,7 @@ use crate::utils::{is_allowed, snippet, span_help_and_lint}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; use syntax::source_map::Span; use unicode_normalization::UnicodeNormalization; @@ -58,18 +58,7 @@ declare_clippy_lint! { "using a unicode literal not in NFC normal form (see [unicode tr15](http://www.unicode.org/reports/tr15/) for further information)" } -#[derive(Copy, Clone)] -pub struct Unicode; - -impl LintPass for Unicode { - fn get_lints(&self) -> LintArray { - lint_array!(ZERO_WIDTH_SPACE, NON_ASCII_LITERAL, UNICODE_NOT_NFC) - } - - fn name(&self) -> &'static str { - "Unicode" - } -} +declare_lint_pass!(Unicode => [ZERO_WIDTH_SPACE, NON_ASCII_LITERAL, UNICODE_NOT_NFC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unicode { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 68ceaaac8a31..deeeefb88ab5 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -1,6 +1,6 @@ use crate::utils::span_lint; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; use syntax::source_map::Span; use syntax::symbol::LocalInternedString; @@ -26,17 +26,7 @@ declare_clippy_lint! { "`unsafe` removed from API names on import" } -pub struct UnsafeNameRemoval; - -impl LintPass for UnsafeNameRemoval { - fn get_lints(&self) -> LintArray { - lint_array!(UNSAFE_REMOVED_FROM_NAME) - } - - fn name(&self) -> &'static str { - "UnsafeNameRemoval" - } -} +declare_lint_pass!(UnsafeNameRemoval => [UNSAFE_REMOVED_FROM_NAME]); impl EarlyLintPass for UnsafeNameRemoval { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 89f6873565a5..b3de0823bd45 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -1,7 +1,7 @@ use crate::utils::{is_try, match_qpath, match_trait_method, paths, span_lint}; use rustc::hir; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for unused written/read amount. @@ -30,17 +30,7 @@ declare_clippy_lint! { "unused written/read amount" } -pub struct UnusedIoAmount; - -impl LintPass for UnusedIoAmount { - fn get_lints(&self) -> LintArray { - lint_array!(UNUSED_IO_AMOUNT) - } - - fn name(&self) -> &'static str { - "UnusedIoAmount" - } -} +declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) { diff --git a/clippy_lints/src/unused_label.rs b/clippy_lints/src/unused_label.rs index d92511d999fb..73934adfb33f 100644 --- a/clippy_lints/src/unused_label.rs +++ b/clippy_lints/src/unused_label.rs @@ -2,7 +2,7 @@ use crate::utils::{in_macro, span_lint}; use rustc::hir; use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashMap; use syntax::source_map::Span; use syntax::symbol::LocalInternedString; @@ -27,22 +27,12 @@ declare_clippy_lint! { "unused labels" } -pub struct UnusedLabel; - struct UnusedLabelVisitor<'a, 'tcx: 'a> { labels: FxHashMap, cx: &'a LateContext<'a, 'tcx>, } -impl LintPass for UnusedLabel { - fn get_lints(&self) -> LintArray { - lint_array!(UNUSED_LABEL) - } - - fn name(&self) -> &'static str { - "UnusedLable" - } -} +declare_lint_pass!(UnusedLabel => [UNUSED_LABEL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel { fn check_fn( diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 6b77e0f16faa..720795eace80 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -1,6 +1,6 @@ use if_chain::if_chain; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use crate::utils::{in_macro, match_type, paths, span_lint_and_then, usage::is_potentially_mutated}; use rustc::hir::intravisit::*; @@ -54,8 +54,6 @@ declare_clippy_lint! { "checks for calls of unwrap[_err]() that will always fail" } -pub struct Pass; - /// Visitor that keeps track of which variables are unwrappable. struct UnwrappableVariablesVisitor<'a, 'tcx: 'a> { unwrappables: Vec>, @@ -179,17 +177,9 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { } } -impl<'a> LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(PANICKING_UNWRAP, UNNECESSARY_UNWRAP) - } - - fn name(&self) -> &'static str { - "Unwrap" - } -} +declare_lint_pass!(Unwrap => [PANICKING_UNWRAP, UNNECESSARY_UNWRAP]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unwrap { fn check_fn( &mut self, cx: &LateContext<'a, 'tcx>, diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index d3b011a3bd98..955239d4281f 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -5,7 +5,7 @@ use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::ty; use rustc::ty::DefIdTree; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax_pos::symbol::keywords::SelfUpper; @@ -46,18 +46,7 @@ declare_clippy_lint! { "Unnecessary structure name repetition whereas `Self` is applicable" } -#[derive(Copy, Clone, Default)] -pub struct UseSelf; - -impl LintPass for UseSelf { - fn get_lints(&self) -> LintArray { - lint_array!(USE_SELF) - } - - fn name(&self) -> &'static str { - "UseSelf" - } -} +declare_lint_pass!(UseSelf => [USE_SELF]); const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element"; diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index d0b7dd7e8089..4ddae1d01c13 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -7,7 +7,7 @@ use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; use rustc::hir::{BindingAnnotation, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::session::Session; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashMap; use syntax::ast::{Attribute, LitKind}; @@ -48,17 +48,7 @@ declare_clippy_lint! { "helper for writing lints" } -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(LINT_AUTHOR) - } - - fn name(&self) -> &'static str { - "Author" - } -} +declare_lint_pass!(Author => [LINT_AUTHOR]); fn prelude() { println!("if_chain! {{"); @@ -71,7 +61,7 @@ fn done() { println!("}}"); } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { if !has_attr(cx.sess(), &item.attrs) { return; diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 219503922701..72c0b5ce365c 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -5,7 +5,7 @@ use rustc::hir; use rustc::hir::print; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::session::Session; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::Attribute; declare_clippy_lint! { @@ -30,19 +30,9 @@ declare_clippy_lint! { "helper to dump info about code" } -pub struct Pass; +declare_lint_pass!(DeepCodeInspector => [DEEP_CODE_INSPECTION]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(DEEP_CODE_INSPECTION) - } - - fn name(&self) -> &'static str { - "DeepCodeInspector" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { if !has_attr(cx.sess(), &item.attrs) { return; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index b71d5000c6b2..375e3d2b3f4e 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -5,7 +5,7 @@ use rustc::hir::def::Def; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::*; use rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use syntax::ast::{Crate as AstCrate, ItemKind, Name}; use syntax::source_map::Span; @@ -31,8 +31,8 @@ declare_clippy_lint! { /// putting a lint to a `LintPass::get_lints()`'s return, the compiler will not /// know the name of the lint. /// - /// **Known problems:** Only checks for lints associated using the `lint_array!` - /// macro. + /// **Known problems:** Only checks for lints associated using the + /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros. /// /// **Example:** /// ```rust @@ -40,13 +40,8 @@ declare_clippy_lint! { /// declare_lint! { pub LINT_2, ... } /// declare_lint! { pub FORGOTTEN_LINT, ... } /// // ... - /// pub struct Pass; - /// impl LintPass for Pass { - /// fn get_lints(&self) -> LintArray { - /// lint_array![LINT_1, LINT_2] - /// // missing FORGOTTEN_LINT - /// } - /// } + /// declare_lint_pass!(Pass => [LINT_1, LINT_2]); + /// // missing FORGOTTEN_LINT /// ``` pub LINT_WITHOUT_LINT_PASS, internal, @@ -77,20 +72,9 @@ declare_clippy_lint! { "usage of the lint functions of the compiler instead of the utils::* variant" } -#[derive(Copy, Clone)] -pub struct Clippy; +declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]); -impl LintPass for Clippy { - fn get_lints(&self) -> LintArray { - lint_array!(CLIPPY_LINTS_INTERNAL) - } - - fn name(&self) -> &'static str { - "ClippyLintsInternal" - } -} - -impl EarlyLintPass for Clippy { +impl EarlyLintPass for ClippyLintsInternal { fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &AstCrate) { if let Some(utils) = krate.module.items.iter().find(|item| item.ident.name == "utils") { if let ItemKind::Mod(ref utils_mod) = utils.node { @@ -125,14 +109,7 @@ pub struct LintWithoutLintPass { registered_lints: FxHashSet, } -impl LintPass for LintWithoutLintPass { - fn get_lints(&self) -> LintArray { - lint_array!(LINT_WITHOUT_LINT_PASS) - } - fn name(&self) -> &'static str { - "LintWithoutLintPass" - } -} +impl_lint_pass!(LintWithoutLintPass => [LINT_WITHOUT_LINT_PASS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { @@ -247,15 +224,7 @@ impl CompilerLintFunctions { } } -impl LintPass for CompilerLintFunctions { - fn get_lints(&self) -> LintArray { - lint_array!(COMPILER_LINT_FUNCTIONS) - } - - fn name(&self) -> &'static str { - "CompileLintFunctions" - } -} +impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 9b8b2372c53b..2422a7060cd1 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty::{self, Ty}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::source_map::Span; @@ -25,20 +25,9 @@ declare_clippy_lint! { "useless `vec!`" } -#[derive(Copy, Clone, Debug)] -pub struct Pass; +declare_lint_pass!(UselessVec => [USELESS_VEC]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(USELESS_VEC) - } - - fn name(&self) -> &'static str { - "UselessVec" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index 30bd2177ca91..b2a66b6d5a44 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,6 +1,6 @@ use crate::utils::span_lint; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::{ast::*, source_map::DUMMY_SP}; use cargo_metadata; @@ -27,19 +27,9 @@ declare_clippy_lint! { "wildcard dependencies being used" } -pub struct Pass; +declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(WILDCARD_DEPENDENCIES) - } - - fn name(&self) -> &'static str { - "WildcardDependencies" - } -} - -impl EarlyLintPass for Pass { +impl EarlyLintPass for WildcardDependencies { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() { metadata diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index c0ffb16c3574..9f4ebdec7143 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -1,6 +1,6 @@ use crate::utils::{snippet_with_applicability, span_lint, span_lint_and_sugg}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::borrow::Cow; use syntax::ast::*; @@ -168,29 +168,18 @@ declare_clippy_lint! { "writing a literal with a format string" } -#[derive(Copy, Clone, Debug)] -pub struct Pass; +declare_lint_pass!(Write => [ + PRINT_WITH_NEWLINE, + PRINTLN_EMPTY_STRING, + PRINT_STDOUT, + USE_DEBUG, + PRINT_LITERAL, + WRITE_WITH_NEWLINE, + WRITELN_EMPTY_STRING, + WRITE_LITERAL +]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!( - PRINT_WITH_NEWLINE, - PRINTLN_EMPTY_STRING, - PRINT_STDOUT, - USE_DEBUG, - PRINT_LITERAL, - WRITE_WITH_NEWLINE, - WRITELN_EMPTY_STRING, - WRITE_LITERAL - ) - } - - fn name(&self) -> &'static str { - "Write" - } -} - -impl EarlyLintPass for Pass { +impl EarlyLintPass for Write { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) { if mac.node.path == "println" { span_lint(cx, PRINT_STDOUT, mac.span, "use of `println!`"); diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index de13816f66fd..094cb627dc3a 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -3,7 +3,7 @@ use crate::utils::span_help_and_lint; use if_chain::if_chain; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; +use rustc::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { /// **What it does:** Checks for `0.0 / 0.0`. @@ -22,19 +22,9 @@ declare_clippy_lint! { "usage of `0.0 / 0.0` to obtain NaN instead of std::f32::NaN or std::f64::NaN" } -pub struct Pass; +declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(ZERO_DIVIDED_BY_ZERO) - } - - fn name(&self) -> &'static str { - "ZeroDiv" - } -} - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { // check for instances of 0.0/0.0 if_chain! { From ef29db773e8367e68e957f435f70ee96a85d9a8f Mon Sep 17 00:00:00 2001 From: Matthew Kraai Date: Tue, 16 Apr 2019 15:21:12 -0700 Subject: [PATCH 4/4] Add tests for declare_lint_pass and impl_lint_pass --- tests/ui/lint_without_lint_pass.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/ui/lint_without_lint_pass.rs b/tests/ui/lint_without_lint_pass.rs index a6f10a006dbd..81b639848915 100644 --- a/tests/ui/lint_without_lint_pass.rs +++ b/tests/ui/lint_without_lint_pass.rs @@ -3,7 +3,7 @@ #[macro_use] extern crate rustc; -use rustc::lint; +use rustc::lint::{LintArray, LintPass}; #[macro_use] extern crate clippy_lints; @@ -21,8 +21,8 @@ declare_clippy_lint! { } pub struct Pass; -impl lint::LintPass for Pass { - fn get_lints(&self) -> lint::LintArray { +impl LintPass for Pass { + fn get_lints(&self) -> LintArray { lint_array!(TEST_LINT_REGISTERED) } @@ -31,4 +31,9 @@ impl lint::LintPass for Pass { } } +declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]); + +pub struct Pass3; +impl_lint_pass!(Pass3 => [TEST_LINT_REGISTERED]); + fn main() {}