Auto merge of #3968 - kraai:lint-pass-macros, r=flip1995

Lint pass macros
This commit is contained in:
bors 2019-04-18 07:24:35 +00:00
commit 58e12130e4
133 changed files with 612 additions and 2132 deletions

View File

@ -1,7 +1,7 @@
use crate::utils::span_lint; use crate::utils::span_lint;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 std::f64::consts as f64;
use syntax::ast::{FloatTy, Lit, LitKind}; use syntax::ast::{FloatTy, Lit, LitKind};
use syntax::symbol; use syntax::symbol;
@ -53,20 +53,9 @@ const KNOWN_CONSTS: &[(f64, &str, usize)] = &[
(f64::SQRT_2, "SQRT_2", 5), (f64::SQRT_2, "SQRT_2", 5),
]; ];
#[derive(Copy, Clone)] declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
fn get_lints(&self) -> LintArray {
lint_array!(APPROX_CONSTANT)
}
fn name(&self) -> &'static str {
"ApproxConstant"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Lit(lit) = &e.node { if let ExprKind::Lit(lit) = &e.node {
check_lit(cx, lit, e); check_lit(cx, lit, e);

View File

@ -2,7 +2,7 @@ use crate::consts::constant_simple;
use crate::utils::span_lint; use crate::utils::span_lint;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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; use syntax::source_map::Span;
declare_clippy_lint! { declare_clippy_lint! {
@ -48,15 +48,7 @@ pub struct Arithmetic {
const_span: Option<Span>, const_span: Option<Span>,
} }
impl LintPass for Arithmetic { impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
fn get_lints(&self) -> LintArray {
lint_array!(INTEGER_ARITHMETIC, FLOAT_ARITHMETIC)
}
fn name(&self) -> &'static str {
"Arithmetic"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {

View File

@ -1,7 +1,7 @@
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::{Expr, ExprKind}; use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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::consts::{constant, Constant};
use crate::syntax::ast::LitKind; 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!()`" "`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`"
} }
pub struct AssertionsOnConstants; declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
impl LintPass for AssertionsOnConstants {
fn get_lints(&self) -> LintArray {
lint_array![ASSERTIONS_ON_CONSTANTS]
}
fn name(&self) -> &'static str {
"AssertionsOnConstants"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -2,7 +2,7 @@ use if_chain::if_chain;
use rustc::hir; use rustc::hir;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use crate::utils::{ use crate::utils::{
@ -53,18 +53,7 @@ declare_clippy_lint! {
"having a variable on both sides of an assign op" "having a variable on both sides of an assign op"
} }
#[derive(Copy, Clone, Default)] declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]

View File

@ -12,7 +12,7 @@ use rustc::lint::{
LintContext, LintPass, LintContext, LintPass,
}; };
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use semver::Version; use semver::Version;
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; 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`" "usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Attributes => [
pub struct AttrPass; INLINE_ALWAYS,
DEPRECATED_SEMVER,
USELESS_ATTRIBUTE,
EMPTY_LINE_AFTER_OUTER_ATTR,
UNKNOWN_CLIPPY_LINTS,
]);
impl LintPass for AttrPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
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 {
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) { fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
if let Some(items) = &attr.meta_item_list() { if let Some(items) = &attr.meta_item_list() {
if let Some(ident) = attr.ident() { if let Some(ident) = attr.ident() {
@ -506,20 +495,9 @@ fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool {
true true
} }
#[derive(Copy, Clone)] declare_lint_pass!(DeprecatedCfgAttribute => [DEPRECATED_CFG_ATTR]);
pub struct CfgAttrPass;
impl LintPass for CfgAttrPass { impl EarlyLintPass for DeprecatedCfgAttribute {
fn get_lints(&self) -> LintArray {
lint_array!(DEPRECATED_CFG_ATTR,)
}
fn name(&self) -> &'static str {
"DeprecatedCfgAttribute"
}
}
impl EarlyLintPass for CfgAttrPass {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! { if_chain! {
// check cfg_attr // check cfg_attr

View File

@ -4,7 +4,7 @@ use crate::utils::{span_lint, span_lint_and_then};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -107,14 +107,7 @@ impl BitMask {
} }
} }
impl LintPass for BitMask { impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]);
fn get_lints(&self) -> LintArray {
lint_array!(BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK)
}
fn name(&self) -> &'static str {
"BitMask"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -1,7 +1,7 @@
use crate::utils::span_lint; use crate::utils::span_lint;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_data_structures::fx::FxHashSet;
declare_clippy_lint! { declare_clippy_lint! {
@ -23,26 +23,19 @@ declare_clippy_lint! {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct BlackListedName { pub struct BlacklistedName {
blacklist: FxHashSet<String>, blacklist: FxHashSet<String>,
} }
impl BlackListedName { impl BlacklistedName {
pub fn new(blacklist: FxHashSet<String>) -> Self { pub fn new(blacklist: FxHashSet<String>) -> Self {
Self { blacklist } Self { blacklist }
} }
} }
impl LintPass for BlackListedName { impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
fn get_lints(&self) -> LintArray {
lint_array!(BLACKLISTED_NAME)
}
fn name(&self) -> &'static str {
"BlacklistedName"
}
}
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) { fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if let PatKind::Binding(.., ident, _) = pat.node { if let PatKind::Binding(.., ident, _) = pat.node {
if self.blacklist.contains(&ident.name.to_string()) { if self.blacklist.contains(&ident.name.to_string()) {

View File

@ -3,7 +3,7 @@ use matches::matches;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:** Checks for `if` conditions that use blocks to contain an /// **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 } ...`" "complex blocks in conditions, e.g., `if { let x = true; x } ...`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]);
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"
}
}
struct ExVisitor<'a, 'tcx: 'a> { struct ExVisitor<'a, 'tcx: 'a> {
found_block: Option<&'tcx Expr>, found_block: Option<&'tcx Expr>,

View File

@ -4,7 +4,7 @@ use crate::utils::{
use rustc::hir::intravisit::*; use rustc::hir::intravisit::*;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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_data_structures::thin_vec::ThinVec;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::LitKind; use syntax::ast::LitKind;
@ -51,18 +51,7 @@ declare_clippy_lint! {
// For each pairs, both orders are considered. // For each pairs, both orders are considered.
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")]; const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];
#[derive(Copy, Clone)] declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
pub struct NonminimalBool;
impl LintPass for NonminimalBool {
fn get_lints(&self) -> LintArray {
lint_array!(NONMINIMAL_BOOL, LOGIC_BUG)
}
fn name(&self) -> &'static str {
"NonminimalBool"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
fn check_fn( fn check_fn(

View File

@ -6,7 +6,7 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::{Name, UintTy}; use syntax::ast::{Name, UintTy};
@ -31,18 +31,7 @@ declare_clippy_lint! {
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values" "use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"
} }
#[derive(Copy, Clone)] declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
pub struct ByteCount;
impl LintPass for ByteCount {
fn get_lints(&self) -> LintArray {
lint_array!(NAIVE_BYTECOUNT)
}
fn name(&self) -> &'static str {
"ByteCount"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {

View File

@ -2,7 +2,7 @@
use crate::utils::span_lint; use crate::utils::span_lint;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 syntax::{ast::*, source_map::DUMMY_SP};
use cargo_metadata; use cargo_metadata;
@ -56,19 +56,9 @@ fn is_empty_vec(value: &[String]) -> bool {
value.iter().all(std::string::String::is_empty) value.iter().all(std::string::String::is_empty)
} }
pub struct Pass; declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
impl LintPass for Pass { impl EarlyLintPass for CargoCommonMetadata {
fn get_lints(&self) -> LintArray {
lint_array!(CARGO_COMMON_METADATA)
}
fn name(&self) -> &'static str {
"CargoCommonMetadata"
}
}
impl EarlyLintPass for Pass {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() { let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
metadata metadata

View File

@ -5,7 +5,7 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, impl_lint_pass};
use syntax::ast::Attribute; use syntax::ast::Attribute;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -38,15 +38,7 @@ impl CognitiveComplexity {
} }
} }
impl LintPass for CognitiveComplexity { impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]);
fn get_lints(&self) -> LintArray {
lint_array!(COGNITIVE_COMPLEXITY)
}
fn name(&self) -> &'static str {
"CognitiveComplexity"
}
}
impl CognitiveComplexity { impl CognitiveComplexity {
fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) { fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {

View File

@ -14,7 +14,7 @@
use if_chain::if_chain; use if_chain::if_chain;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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::ast;
use crate::utils::sugg::Sugg; 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 { ... } }`)" "`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)"
} }
#[derive(Copy, Clone)] declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]);
pub struct CollapsibleIf;
impl LintPass for CollapsibleIf {
fn get_lints(&self) -> LintArray {
lint_array!(COLLAPSIBLE_IF)
}
fn name(&self) -> &'static str {
"CollapsibleIf"
}
}
impl EarlyLintPass for CollapsibleIf { impl EarlyLintPass for CollapsibleIf {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {

View File

@ -1,6 +1,6 @@
use crate::utils::{in_macro, snippet, span_lint_and_then}; use crate::utils::{in_macro, snippet, span_lint_and_then};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::*; use syntax::ast::*;
@ -26,17 +26,7 @@ declare_clippy_lint! {
"Using explicit `'static` lifetime for constants when elision rules would allow omitting them." "Using explicit `'static` lifetime for constants when elision rules would allow omitting them."
} }
pub struct StaticConst; declare_lint_pass!(StaticConst => [CONST_STATIC_LIFETIME]);
impl LintPass for StaticConst {
fn get_lints(&self) -> LintArray {
lint_array!(CONST_STATIC_LIFETIME)
}
fn name(&self) -> &'static str {
"StaticConst"
}
}
impl StaticConst { impl StaticConst {
// Recursively visit types // Recursively visit types

View File

@ -3,7 +3,7 @@ use crate::utils::{SpanlessEq, SpanlessHash};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::Ty; 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 rustc_data_structures::fx::FxHashMap;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
@ -103,18 +103,7 @@ declare_clippy_lint! {
"`match` with identical arm bodies" "`match` with identical arm bodies"
} }
#[derive(Copy, Clone, Debug)] declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -1,7 +1,7 @@
use crate::utils::{is_copy, match_path, paths, span_note_and_lint}; use crate::utils::{is_copy, match_path, paths, span_note_and_lint};
use rustc::hir::{Item, ItemKind}; use rustc::hir::{Item, ItemKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:** Checks for types that implement `Copy` as well as /// **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" "implementing `Iterator` on a `Copy` type"
} }
pub struct CopyIterator; declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
impl LintPass for CopyIterator {
fn get_lints(&self) -> LintArray {
lint_array![COPY_ITERATOR]
}
fn name(&self) -> &'static str {
"CopyIterator"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {

View File

@ -1,6 +1,6 @@
use crate::utils::{snippet_opt, span_help_and_lint, span_lint_and_sugg}; use crate::utils::{snippet_opt, span_help_and_lint, span_lint_and_sugg};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast; use syntax::ast;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -27,20 +27,9 @@ declare_clippy_lint! {
"`dbg!` macro is intended as a debugging tool" "`dbg!` macro is intended as a debugging tool"
} }
#[derive(Copy, Clone, Debug)] declare_lint_pass!(DbgMacro => [DBG_MACRO]);
pub struct Pass;
impl LintPass for Pass { impl EarlyLintPass for DbgMacro {
fn get_lints(&self) -> LintArray {
lint_array!(DBG_MACRO)
}
fn name(&self) -> &'static str {
"DbgMacro"
}
}
impl EarlyLintPass for Pass {
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
if mac.node.path == "dbg" { if mac.node.path == "dbg" {
if let Some(sugg) = tts_span(mac.node.tts.clone()).and_then(|span| snippet_opt(cx, span)) { if let Some(sugg) = tts_span(mac.node.tts.clone()).and_then(|span| snippet_opt(cx, span)) {

View File

@ -2,7 +2,7 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use crate::utils::{any_parent_is_automatically_derived, paths, span_lint_and_sugg}; 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()" "checks for literal calls to Default::default()"
} }
#[derive(Copy, Clone)] declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]);
pub struct DefaultTraitAccess;
impl LintPass for DefaultTraitAccess {
fn get_lints(&self) -> LintArray {
lint_array!(DEFAULT_TRAIT_ACCESS)
}
fn name(&self) -> &'static str {
"DefaultTraitAccess"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -4,7 +4,7 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::{self, Ty}; 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; use syntax::source_map::Span;
declare_clippy_lint! { declare_clippy_lint! {
@ -62,17 +62,7 @@ declare_clippy_lint! {
"implementing `Clone` explicitly on `Copy` types" "implementing `Clone` explicitly on `Copy` types"
} }
pub struct Derive; declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {

View File

@ -2,7 +2,7 @@ use crate::utils::span_lint;
use itertools::Itertools; use itertools::Itertools;
use pulldown_cmark; use pulldown_cmark;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 rustc_data_structures::fx::FxHashSet;
use syntax::ast; use syntax::ast;
use syntax::source_map::{BytePos, Span}; use syntax::source_map::{BytePos, Span};
@ -33,28 +33,21 @@ declare_clippy_lint! {
"presence of `_`, `::` or camel-case outside backticks in documentation" "presence of `_`, `::` or camel-case outside backticks in documentation"
} }
#[allow(clippy::module_name_repetitions)]
#[derive(Clone)] #[derive(Clone)]
pub struct Doc { pub struct DocMarkdown {
valid_idents: FxHashSet<String>, valid_idents: FxHashSet<String>,
} }
impl Doc { impl DocMarkdown {
pub fn new(valid_idents: FxHashSet<String>) -> Self { pub fn new(valid_idents: FxHashSet<String>) -> Self {
Self { valid_idents } Self { valid_idents }
} }
} }
impl LintPass for Doc { impl_lint_pass!(DocMarkdown => [DOC_MARKDOWN]);
fn get_lints(&self) -> LintArray {
lint_array![DOC_MARKDOWN]
}
fn name(&self) -> &'static str { impl EarlyLintPass for DocMarkdown {
"DocMarkdown"
}
}
impl EarlyLintPass for Doc {
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) { fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) {
check_attrs(cx, &self.valid_idents, &krate.attrs); check_attrs(cx, &self.valid_idents, &krate.attrs);
} }

View File

@ -2,7 +2,7 @@
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -31,21 +31,11 @@ declare_clippy_lint! {
"unnecessary double comparisons that can be simplified" "unnecessary double comparisons that can be simplified"
} }
pub struct Pass; declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
impl LintPass for Pass { impl<'a, 'tcx> DoubleComparisons {
fn get_lints(&self) -> LintArray {
lint_array!(DOUBLE_COMPARISONS)
}
fn name(&self) -> &'static str {
"DoubleComparisons"
}
}
impl<'a, 'tcx> Pass {
#[allow(clippy::similar_names)] #[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()) { let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (lhs.node.clone(), rhs.node.clone()) {
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => { (ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
(lb.node, llhs, lrhs, rb.node, 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) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.node { if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.node {
self.check_binop(cx, kind.node, lhs, rhs, expr.span); self.check_binop(cx, kind.node, lhs, rhs, expr.span);

View File

@ -1,6 +1,6 @@
use crate::utils::{in_macro, span_lint}; use crate::utils::{in_macro, span_lint};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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::ast::*;
declare_clippy_lint! { declare_clippy_lint! {
@ -22,18 +22,7 @@ declare_clippy_lint! {
"Warn on unnecessary double parentheses" "Warn on unnecessary double parentheses"
} }
#[derive(Copy, Clone)] declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]);
pub struct DoubleParens;
impl LintPass for DoubleParens {
fn get_lints(&self) -> LintArray {
lint_array!(DOUBLE_PARENS)
}
fn name(&self) -> &'static str {
"DoubleParens"
}
}
impl EarlyLintPass for DoubleParens { impl EarlyLintPass for DoubleParens {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {

View File

@ -2,7 +2,7 @@ use crate::utils::{paths, span_lint};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateLintPass, LintArray, LintPass}; use rustc::lint::{LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for generics with `std::ops::Drop` as bounds. /// **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. \ 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."; 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 { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds {
fn get_lints(&self) -> LintArray {
lint_array!(DROP_BOUNDS)
}
fn name(&self) -> &'static str {
"DropBounds"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam) { fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam) {
for bound in &p.bounds { for bound in &p.bounds {
lint_bound(cx, bound); lint_bound(cx, bound);

View File

@ -3,7 +3,7 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::drop` with a reference /// **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. \ const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements Copy. \
Forgetting a copy leaves the original intact."; 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 { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
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 {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! { if_chain! {
if let ExprKind::Call(ref path, ref args) = expr.node; if let ExprKind::Call(ref path, ref args) = expr.node;

View File

@ -1,7 +1,7 @@
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
@ -29,18 +29,7 @@ declare_clippy_lint! {
"checks for calculation of subsecond microseconds or milliseconds" "checks for calculation of subsecond microseconds or milliseconds"
} }
#[derive(Copy, Clone)] declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]);
pub struct DurationSubsec;
impl LintPass for DurationSubsec {
fn get_lints(&self) -> LintArray {
lint_array!(DURATION_SUBSEC)
}
fn name(&self) -> &'static str {
"DurationSubsec"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -1,7 +1,7 @@
//! Lint on if expressions with an else if, but without a final else branch. //! 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::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 syntax::ast::*;
use crate::utils::span_help_and_lint; 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" "if expression with an `else if`, but without a final `else` branch"
} }
#[derive(Copy, Clone)] declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]);
pub struct ElseIfWithoutElse;
impl LintPass for ElseIfWithoutElse {
fn get_lints(&self) -> LintArray {
lint_array!(ELSE_IF_WITHOUT_ELSE)
}
fn name(&self) -> &'static str {
"ElseIfWithoutElse"
}
}
impl EarlyLintPass for ElseIfWithoutElse { impl EarlyLintPass for ElseIfWithoutElse {
fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) {

View File

@ -3,7 +3,7 @@
use crate::utils::span_lint_and_then; use crate::utils::span_lint_and_then;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:** Checks for `enum`s with no variants. /// **What it does:** Checks for `enum`s with no variants.
@ -23,18 +23,7 @@ declare_clippy_lint! {
"enum with no variants" "enum with no variants"
} }
#[derive(Copy, Clone)] declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
pub struct EmptyEnum;
impl LintPass for EmptyEnum {
fn get_lints(&self) -> LintArray {
lint_array!(EMPTY_ENUM)
}
fn name(&self) -> &'static str {
"EmptyEnum"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {

View File

@ -4,7 +4,7 @@ use if_chain::if_chain;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -37,20 +37,9 @@ declare_clippy_lint! {
"use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`" "use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
pub struct HashMapLint;
impl LintPass for HashMapLint { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
fn get_lints(&self) -> LintArray {
lint_array!(MAP_ENTRY)
}
fn name(&self) -> &'static str {
"HashMap"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { 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::If(ref check, ref then_block, ref else_block) = expr.node {
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node { if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node {

View File

@ -9,7 +9,7 @@ use rustc::mir::interpret::GlobalId;
use rustc::ty; use rustc::ty;
use rustc::ty::subst::InternalSubsts; use rustc::ty::subst::InternalSubsts;
use rustc::ty::util::IntTypeExt; 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}; use syntax::ast::{IntTy, UintTy};
declare_clippy_lint! { 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`" "C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`"
} }
pub struct UnportableVariant; declare_lint_pass!(UnportableVariant => [ENUM_CLIKE_UNPORTABLE_VARIANT]);
impl LintPass for UnportableVariant {
fn get_lints(&self) -> LintArray {
lint_array!(ENUM_CLIKE_UNPORTABLE_VARIANT)
}
fn name(&self) -> &'static str {
"UnportableVariant"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)] #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)]

View File

@ -4,7 +4,7 @@ use crate::utils::span_lint;
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 syntax::source_map::Span;
declare_clippy_lint! { declare_clippy_lint! {
@ -25,17 +25,7 @@ declare_clippy_lint! {
"use items that import all variants of an enum" "use items that import all variants of an enum"
} }
pub struct EnumGlobUse; declare_lint_pass!(EnumGlobUse => [ENUM_GLOB_USE]);
impl LintPass for EnumGlobUse {
fn get_lints(&self) -> LintArray {
lint_array!(ENUM_GLOB_USE)
}
fn name(&self) -> &'static str {
"EnumGlobUse"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) { 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 { impl EnumGlobUse {
fn lint_item(&self, cx: &LateContext<'_, '_>, item: &Item) { fn lint_item(self, cx: &LateContext<'_, '_>, item: &Item) {
if item.vis.node.is_pub() { if item.vis.node.is_pub() {
return; // re-exports are fine return; // re-exports are fine
} }

View File

@ -3,7 +3,7 @@
use crate::utils::{camel_case, in_macro}; use crate::utils::{camel_case, in_macro};
use crate::utils::{span_help_and_lint, span_lint}; use crate::utils::{span_help_and_lint, span_lint};
use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass}; 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::ast::*;
use syntax::source_map::Span; use syntax::source_map::Span;
use syntax::symbol::{InternedString, LocalInternedString}; use syntax::symbol::{InternedString, LocalInternedString};
@ -115,20 +115,12 @@ impl EnumVariantNames {
} }
} }
impl LintPass for EnumVariantNames { impl_lint_pass!(EnumVariantNames => [
fn get_lints(&self) -> LintArray { ENUM_VARIANT_NAMES,
lint_array!( PUB_ENUM_VARIANT_NAMES,
ENUM_VARIANT_NAMES, MODULE_NAME_REPETITIONS,
PUB_ENUM_VARIANT_NAMES, MODULE_INCEPTION
MODULE_NAME_REPETITIONS, ]);
MODULE_INCEPTION
)
}
fn name(&self) -> &'static str {
"EnumVariantNames"
}
}
fn var2str(var: &Variant) -> LocalInternedString { fn var2str(var: &Variant) -> LocalInternedString {
var.node.ident.as_str() var.node.ident.as_str()

View File

@ -3,7 +3,7 @@ use crate::utils::{
}; };
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -46,18 +46,7 @@ declare_clippy_lint! {
"taking a reference to satisfy the type constraints on `==`" "taking a reference to satisfy the type constraints on `==`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(EqOp => [EQ_OP, OP_REF]);
pub struct EqOp;
impl LintPass for EqOp {
fn get_lints(&self) -> LintArray {
lint_array!(EQ_OP, OP_REF)
}
fn name(&self) -> &'static str {
"EqOp"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
#[allow(clippy::similar_names, clippy::too_many_lines)] #[allow(clippy::similar_names, clippy::too_many_lines)]

View File

@ -1,6 +1,6 @@
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 syntax::source_map::Span;
use crate::consts::{constant_simple, Constant}; use crate::consts::{constant_simple, Constant};
@ -27,18 +27,7 @@ declare_clippy_lint! {
"using erasing operations, e.g., `x * 0` or `y & 0`" "using erasing operations, e.g., `x * 0` or `y & 0`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(ErasingOp => [ERASING_OP]);
pub struct ErasingOp;
impl LintPass for ErasingOp {
fn get_lints(&self) -> LintArray {
lint_array!(ERASING_OP)
}
fn name(&self) -> &'static str {
"ErasingOp"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -6,12 +6,13 @@ use rustc::middle::mem_categorization::{cmt_, Categorization};
use rustc::ty::layout::LayoutOf; use rustc::ty::layout::LayoutOf;
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::util::nodemap::HirIdSet; 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 syntax::source_map::Span;
use crate::utils::span_lint; use crate::utils::span_lint;
pub struct Pass { #[derive(Copy, Clone)]
pub struct BoxedLocal {
pub too_large_for_stack: u64, pub too_large_for_stack: u64,
} }
@ -48,17 +49,9 @@ struct EscapeDelegate<'a, 'tcx: 'a> {
too_large_for_stack: u64, too_large_for_stack: u64,
} }
impl LintPass for Pass { impl_lint_pass!(BoxedLocal => [BOXED_LOCAL]);
fn get_lints(&self) -> LintArray {
lint_array!(BOXED_LOCAL)
}
fn name(&self) -> &'static str { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
"BoxedLocal"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_fn( fn check_fn(
&mut self, &mut self,
cx: &LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,

View File

@ -2,13 +2,11 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty::{self, Ty}; 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 rustc_errors::Applicability;
use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function}; use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function};
pub struct EtaPass;
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for closures which just call another function where /// **What it does:** Checks for closures which just call another function where
/// the function can be called directly. `unsafe` functions or calls where types /// 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`)" "redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)"
} }
impl LintPass for EtaPass { declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE]);
fn get_lints(&self) -> LintArray {
lint_array!(REDUNDANT_CLOSURE)
}
fn name(&self) -> &'static str { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
"EtaReduction"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaPass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_external_macro(cx.sess(), expr.span) { if in_external_macro(cx.sess(), expr.span) {
return; return;

View File

@ -4,7 +4,7 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for a read and a write to the same variable where /// **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" "whether an expression contains a diverging sub expression"
} }
#[derive(Copy, Clone)] declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -3,7 +3,7 @@ use if_chain::if_chain;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use std::f32; use std::f32;
use std::f64; use std::f64;
@ -35,17 +35,7 @@ declare_clippy_lint! {
"excessive precision for float literal" "excessive precision for float literal"
} }
pub struct ExcessivePrecision; declare_lint_pass!(ExcessivePrecision => [EXCESSIVE_PRECISION]);
impl LintPass for ExcessivePrecision {
fn get_lints(&self) -> LintArray {
lint_array!(EXCESSIVE_PRECISION)
}
fn name(&self) -> &'static str {
"ExcessivePrecision"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { 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 { impl ExcessivePrecision {
// None if nothing to lint, Some(suggestion) if lint necessary // None if nothing to lint, Some(suggestion) if lint necessary
fn check(&self, sym: Symbol, fty: FloatTy) -> Option<String> { fn check(self, sym: Symbol, fty: FloatTy) -> Option<String> {
let max = max_digits(fty); let max = max_digits(fty);
let sym_str = sym.as_str(); let sym_str = sym.as_str();
if dot_zero_exclusion(&sym_str) { if dot_zero_exclusion(&sym_str) {

View File

@ -2,7 +2,7 @@ use crate::utils::{is_expn_of, resolve_node, span_lint, span_lint_and_sugg};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::LitKind; 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" "using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work"
} }
#[derive(Copy, Clone, Debug)] declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
fn get_lints(&self) -> LintArray {
lint_array!(EXPLICIT_WRITE)
}
fn name(&self) -> &'static str {
"ExplicitWrite"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! { if_chain! {
// match call to unwrap // match call to unwrap

View File

@ -4,7 +4,7 @@ use if_chain::if_chain;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! { declare_clippy_lint! {
@ -28,17 +28,7 @@ declare_clippy_lint! {
"Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`" "Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`"
} }
pub struct FallibleImplFrom; declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
impl LintPass for FallibleImplFrom {
fn get_lints(&self) -> LintArray {
lint_array!(FALLIBLE_IMPL_FROM)
}
fn name(&self) -> &'static str {
"FallibleImpleFrom"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {

View File

@ -6,7 +6,7 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -33,20 +33,9 @@ declare_clippy_lint! {
"useless use of `format!`" "useless use of `format!`"
} }
#[derive(Copy, Clone, Debug)] declare_lint_pass!(UselessFormat => [USELESS_FORMAT]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat {
fn get_lints(&self) -> LintArray {
lint_array![USELESS_FORMAT]
}
fn name(&self) -> &'static str {
"UselessFormat"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let Some(span) = is_expn_of(expr.span, "format") { if let Some(span) = is_expn_of(expr.span, "format") {
if in_macro(span) { if in_macro(span) {

View File

@ -1,7 +1,7 @@
use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint}; use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass}; 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::ast;
use syntax::ptr::P; use syntax::ptr::P;
@ -79,22 +79,11 @@ declare_clippy_lint! {
"possible missing comma in array" "possible missing comma in array"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Formatting => [
pub struct Formatting; SUSPICIOUS_ASSIGNMENT_FORMATTING,
SUSPICIOUS_ELSE_FORMATTING,
impl LintPass for Formatting { POSSIBLE_MISSING_COMMA
fn get_lints(&self) -> LintArray { ]);
lint_array!(
SUSPICIOUS_ASSIGNMENT_FORMATTING,
SUSPICIOUS_ELSE_FORMATTING,
POSSIBLE_MISSING_COMMA
)
}
fn name(&self) -> &'static str {
"Formatting"
}
}
impl EarlyLintPass for Formatting { impl EarlyLintPass for Formatting {
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) { fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {

View File

@ -5,7 +5,7 @@ use rustc::hir::def::Def;
use rustc::hir::intravisit; use rustc::hir::intravisit;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty; 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_data_structures::fx::FxHashSet;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -93,15 +93,7 @@ impl Functions {
} }
} }
impl LintPass for Functions { impl_lint_pass!(Functions => [TOO_MANY_ARGUMENTS, TOO_MANY_LINES, NOT_UNSAFE_PTR_ARG_DEREF]);
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<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
fn check_fn( fn check_fn(

View File

@ -2,7 +2,7 @@ use crate::utils::{in_macro, match_trait_method, same_tys, snippet, snippet_with
use crate::utils::{paths, resolve_node}; use crate::utils::{paths, resolve_node};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -27,15 +27,7 @@ pub struct IdentityConversion {
try_desugar_arm: Vec<HirId>, try_desugar_arm: Vec<HirId>,
} }
impl LintPass for IdentityConversion { impl_lint_pass!(IdentityConversion => [IDENTITY_CONVERSION]);
fn get_lints(&self) -> LintArray {
lint_array!(IDENTITY_CONVERSION)
}
fn name(&self) -> &'static str {
"IdentityConversion"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -1,7 +1,7 @@
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::source_map::Span; use syntax::source_map::Span;
use crate::consts::{constant_simple, Constant}; use crate::consts::{constant_simple, Constant};
@ -24,18 +24,7 @@ declare_clippy_lint! {
"using identity operations, e.g., `x + 0` or `y / 1`" "using identity operations, e.g., `x + 0` or `y / 1`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(IdentityOp => [IDENTITY_OP]);
pub struct IdentityOp;
impl LintPass for IdentityOp {
fn get_lints(&self) -> LintArray {
lint_array!(IDENTITY_OP)
}
fn name(&self) -> &'static str {
"IdentityOp"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -2,7 +2,7 @@
//! on the condition //! on the condition
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; 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 syntax::ast::*;
use crate::utils::span_help_and_lint; 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" "`if` branches that could be swapped so no negation operation is necessary on the condition"
} }
pub struct IfNotElse; declare_lint_pass!(IfNotElse => [IF_NOT_ELSE]);
impl LintPass for IfNotElse {
fn get_lints(&self) -> LintArray {
lint_array!(IF_NOT_ELSE)
}
fn name(&self) -> &'static str {
"IfNotElse"
}
}
impl EarlyLintPass for IfNotElse { impl EarlyLintPass for IfNotElse {
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {

View File

@ -1,7 +1,7 @@
use crate::utils::{in_macro, is_expn_of, snippet_opt, span_lint_and_then}; 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::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -33,9 +33,9 @@ declare_clippy_lint! {
"use a return statement like `return expr` instead of an expression" "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) { 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| { span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
if let Some(snippet) = snippet_opt(cx, inner_span) { if let Some(snippet) = snippet_opt(cx, inner_span) {
@ -110,17 +110,7 @@ impl Pass {
} }
} }
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn {
fn get_lints(&self) -> LintArray {
lint_array!(IMPLICIT_RETURN)
}
fn name(&self) -> &'static str {
"ImplicitReturn"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_fn( fn check_fn(
&mut self, &mut self,
cx: &LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,

View File

@ -7,7 +7,7 @@ use crate::utils::higher::Range;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::ast::RangeLimits; use syntax::ast::RangeLimits;
declare_clippy_lint! { declare_clippy_lint! {
@ -85,18 +85,7 @@ declare_clippy_lint! {
"indexing/slicing usage" "indexing/slicing usage"
} }
#[derive(Copy, Clone)] declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -2,7 +2,7 @@ use super::utils::{get_arg_name, match_var, remove_blocks, snippet_with_applicab
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -40,20 +40,9 @@ declare_clippy_lint! {
"a match statement with a single infallible arm instead of a `let`" "a match statement with a single infallible arm instead of a `let`"
} }
#[derive(Copy, Clone, Default)] declare_lint_pass!(InfallibleDestructingMatch => [INFALLIBLE_DESTRUCTURING_MATCH]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch {
fn get_lints(&self) -> LintArray {
lint_array!(INFALLIBLE_DESTRUCTURING_MATCH)
}
fn name(&self) -> &'static str {
"InfallibleDestructingMatch"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) { fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) {
if_chain! { if_chain! {
if let Some(ref expr) = local.init; if let Some(ref expr) = local.init;

View File

@ -1,6 +1,6 @@
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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}; 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" "possible infinite iteration"
} }
#[derive(Copy, Clone)] declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfiniteIter {
fn get_lints(&self) -> LintArray {
lint_array!(INFINITE_ITER, MAYBE_INFINITE_ITER)
}
fn name(&self) -> &'static str {
"InfiniteIter"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
let (lint, msg) = match complete_infinite_iter(cx, expr) { let (lint, msg) = match complete_infinite_iter(cx, expr) {
Infinite => (INFINITE_ITER, "infinite iteration detected"), Infinite => (INFINITE_ITER, "infinite iteration detected"),

View File

@ -3,9 +3,8 @@
use crate::utils::span_lint_and_then; use crate::utils::span_lint_and_then;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_data_structures::fx::FxHashMap;
use std::default::Default;
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! { declare_clippy_lint! {
@ -40,29 +39,15 @@ declare_clippy_lint! {
"Multiple inherent impl that could be grouped" "Multiple inherent impl that could be grouped"
} }
pub struct Pass { #[allow(clippy::module_name_repetitions)]
#[derive(Default)]
pub struct MultipleInherentImpl {
impls: FxHashMap<def_id::DefId, (Span, Generics)>, impls: FxHashMap<def_id::DefId, (Span, Generics)>,
} }
impl Default for Pass { impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
fn default() -> Self {
Self {
impls: FxHashMap::default(),
}
}
}
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
fn get_lints(&self) -> LintArray {
lint_array!(MULTIPLE_INHERENT_IMPL)
}
fn name(&self) -> &'static str {
"MultipleInherientImpl"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node { if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
// Remember for each inherent implementation encoutered its span and generics // Remember for each inherent implementation encoutered its span and generics

View File

@ -4,7 +4,7 @@ use crate::utils::span_lint_and_then;
use crate::utils::sugg::DiagnosticBuilderExt; use crate::utils::sugg::DiagnosticBuilderExt;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::{Attribute, Name}; use syntax::ast::{Attribute, Name};
@ -28,20 +28,9 @@ declare_clippy_lint! {
"use of `#[inline]` on trait methods without bodies" "use of `#[inline]` on trait methods without bodies"
} }
#[derive(Copy, Clone)] declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody {
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 {
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) { fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node { if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
check_attrs(cx, item.ident.name, &item.attrs); check_attrs(cx, item.ident.name, &item.attrs);

View File

@ -1,7 +1,7 @@
//! lint on blocks unnecessarily using >= with a + 1 or - 1 //! lint on blocks unnecessarily using >= with a + 1 or - 1
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::*; use syntax::ast::*;
@ -30,17 +30,7 @@ declare_clippy_lint! {
"instead of using x >= y + 1, use x > y" "instead of using x >= y + 1, use x > y"
} }
pub struct IntPlusOne; declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]);
impl LintPass for IntPlusOne {
fn get_lints(&self) -> LintArray {
lint_array!(INT_PLUS_ONE)
}
fn name(&self) -> &'static str {
"IntPlusOne"
}
}
// cases: // cases:
// BinOpKind::Ge // BinOpKind::Ge
@ -59,14 +49,14 @@ enum Side {
impl IntPlusOne { impl IntPlusOne {
#[allow(clippy::cast_sign_loss)] #[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 { if let LitKind::Int(value, ..) = lit.node {
return value == (target_value as u128); return value == (target_value as u128);
} }
false false
} }
fn check_binop(&self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> { fn check_binop(self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> {
match (binop, &lhs.node, &rhs.node) { match (binop, &lhs.node, &rhs.node) {
// case where `x - 1 >= ...` or `-1 + x >= ...` // case where `x - 1 >= ...` or `-1 + x >= ...`
(BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => { (BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => {
@ -131,7 +121,7 @@ impl IntPlusOne {
} }
fn generate_recommendation( fn generate_recommendation(
&self, self,
cx: &EarlyContext<'_>, cx: &EarlyContext<'_>,
binop: BinOpKind, binop: BinOpKind,
node: &Expr, node: &Expr,
@ -155,7 +145,7 @@ impl IntPlusOne {
None 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( span_lint_and_then(
cx, cx,
INT_PLUS_ONE, INT_PLUS_ONE,

View File

@ -3,7 +3,7 @@ use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for creation of references to zeroed or uninitialized memory. /// **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; \ const HELP: &str = "Creation of a null reference is undefined behavior; \
see https://doc.rust-lang.org/reference/behavior-considered-undefined.html"; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html";
pub struct InvalidRef; declare_lint_pass!(InvalidRef => [INVALID_REF]);
impl LintPass for InvalidRef {
fn get_lints(&self) -> LintArray {
lint_array!(INVALID_REF)
}
fn name(&self) -> &'static str {
"InvalidRef"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -3,7 +3,7 @@
use crate::utils::{in_macro, span_lint}; use crate::utils::{in_macro, span_lint};
use matches::matches; use matches::matches;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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::ast::*;
declare_clippy_lint! { declare_clippy_lint! {
@ -34,17 +34,7 @@ declare_clippy_lint! {
"blocks where an item comes after a statement" "blocks where an item comes after a statement"
} }
pub struct ItemsAfterStatements; declare_lint_pass!(ItemsAfterStatements => [ITEMS_AFTER_STATEMENTS]);
impl LintPass for ItemsAfterStatements {
fn get_lints(&self) -> LintArray {
lint_array!(ITEMS_AFTER_STATEMENTS)
}
fn name(&self) -> &'static str {
"ItemsAfterStatements"
}
}
impl EarlyLintPass for ItemsAfterStatements { impl EarlyLintPass for ItemsAfterStatements {
fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) { fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) {

View File

@ -4,7 +4,7 @@ use crate::utils::{snippet_opt, span_lint_and_then};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::layout::LayoutOf; use rustc::ty::layout::LayoutOf;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, impl_lint_pass};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -42,15 +42,7 @@ impl LargeEnumVariant {
} }
} }
impl LintPass for LargeEnumVariant { impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
fn get_lints(&self) -> LintArray {
lint_array!(LARGE_ENUM_VARIANT)
}
fn name(&self) -> &'static str {
"LargeEnumVariant"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {

View File

@ -3,7 +3,7 @@ use rustc::hir::def_id::DefId;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; 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_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::{Lit, LitKind, Name}; 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" "traits or impls with a public `len` method but no corresponding `is_empty` method"
} }
#[derive(Copy, Clone)] declare_lint_pass!(LenZero => [LEN_ZERO, LEN_WITHOUT_IS_EMPTY]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {

View File

@ -4,7 +4,7 @@ use rustc::hir;
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::BindingAnnotation; use rustc::hir::BindingAnnotation;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -52,18 +52,7 @@ declare_clippy_lint! {
"unidiomatic `let mut` declaration followed by initialization in `if`" "unidiomatic `let mut` declaration followed by initialization in `if`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(LetIfSeq => [USELESS_LET_IF_SEQ]);
pub struct LetIfSeq;
impl LintPass for LetIfSeq {
fn get_lints(&self) -> LintArray {
lint_array!(USELESS_LET_IF_SEQ)
}
fn name(&self) -> &'static str {
"LetIfSeq"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) { fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {

View File

@ -290,7 +290,7 @@ pub fn register_pre_expansion_lints(
store: &mut rustc::lint::LintStore, store: &mut rustc::lint::LintStore,
conf: &Conf, 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( store.register_pre_expansion_pass(
Some(session), Some(session),
true, true,
@ -305,8 +305,8 @@ pub fn register_pre_expansion_lints(
single_char_binding_names_threshold: conf.single_char_binding_names_threshold, 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 attrs::DeprecatedCfgAttribute);
store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::Pass); store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::DbgMacro);
} }
#[doc(hidden)] #[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, its used in `update_lints` // end deprecated lints, do not remove this comment, its used in `update_lints`
reg.register_late_lint_pass(box serde_api::Serde); reg.register_late_lint_pass(box serde_api::SerdeAPI);
reg.register_early_lint_pass(box utils::internal_lints::Clippy); 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::CompilerLintFunctions::new());
reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default()); 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::inspector::DeepCodeInspector);
reg.register_late_lint_pass(box utils::author::Pass); reg.register_late_lint_pass(box utils::author::Author);
reg.register_late_lint_pass(box types::TypePass); reg.register_late_lint_pass(box types::Types);
reg.register_late_lint_pass(box booleans::NonminimalBool); reg.register_late_lint_pass(box booleans::NonminimalBool);
reg.register_late_lint_pass(box eq_op::EqOp); reg.register_late_lint_pass(box eq_op::EqOp);
reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold)); 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 enum_clike::UnportableVariant);
reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision); 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 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::NeedlessBool);
reg.register_late_lint_pass(box needless_bool::BoolComparison); reg.register_late_lint_pass(box needless_bool::BoolComparison);
reg.register_late_lint_pass(box approx_const::Pass); reg.register_late_lint_pass(box approx_const::ApproxConstant);
reg.register_late_lint_pass(box misc::Pass); reg.register_late_lint_pass(box misc::MiscLints);
reg.register_early_lint_pass(box precedence::Precedence); reg.register_early_lint_pass(box precedence::Precedence);
reg.register_early_lint_pass(box needless_continue::NeedlessContinue); 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 identity_op::IdentityOp);
reg.register_late_lint_pass(box erasing_op::ErasingOp); reg.register_late_lint_pass(box erasing_op::ErasingOp);
reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements); 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_mut::MutMut);
reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed); reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
reg.register_late_lint_pass(box len_zero::LenZero); 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_early_lint_pass(box collapsible_if::CollapsibleIf);
reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition); 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 unicode::Unicode);
reg.register_late_lint_pass(box strings::StringAdd); reg.register_late_lint_pass(box strings::StringAdd);
reg.register_early_lint_pass(box returns::ReturnPass); reg.register_early_lint_pass(box returns::Return);
reg.register_late_lint_pass(box implicit_return::Pass); reg.register_late_lint_pass(box implicit_return::ImplicitReturn);
reg.register_late_lint_pass(box methods::Pass); reg.register_late_lint_pass(box methods::Methods);
reg.register_late_lint_pass(box map_clone::Pass); reg.register_late_lint_pass(box map_clone::MapClone);
reg.register_late_lint_pass(box shadow::Pass); reg.register_late_lint_pass(box shadow::Shadow);
reg.register_late_lint_pass(box types::LetPass); reg.register_late_lint_pass(box types::LetUnitValue);
reg.register_late_lint_pass(box types::UnitCmp); reg.register_late_lint_pass(box types::UnitCmp);
reg.register_late_lint_pass(box loops::Pass); reg.register_late_lint_pass(box loops::Loops);
reg.register_late_lint_pass(box lifetimes::LifetimePass); reg.register_late_lint_pass(box lifetimes::Lifetimes);
reg.register_late_lint_pass(box entry::HashMapLint); reg.register_late_lint_pass(box entry::HashMapPass);
reg.register_late_lint_pass(box ranges::Pass); reg.register_late_lint_pass(box ranges::Ranges);
reg.register_late_lint_pass(box types::CastPass); reg.register_late_lint_pass(box types::Casts);
reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold)); reg.register_late_lint_pass(box types::TypeComplexity::new(conf.type_complexity_threshold));
reg.register_late_lint_pass(box matches::MatchPass); reg.register_late_lint_pass(box matches::Matches);
reg.register_late_lint_pass(box minmax::MinMaxPass); reg.register_late_lint_pass(box minmax::MinMaxPass);
reg.register_late_lint_pass(box open_options::NonSensical); reg.register_late_lint_pass(box open_options::OpenOptions);
reg.register_late_lint_pass(box zero_div_zero::Pass); reg.register_late_lint_pass(box zero_div_zero::ZeroDiv);
reg.register_late_lint_pass(box mutex_atomic::MutexAtomic); reg.register_late_lint_pass(box mutex_atomic::Mutex);
reg.register_late_lint_pass(box needless_update::Pass); 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_borrow::NeedlessBorrow::default());
reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef); 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 no_effect::NoEffect);
reg.register_late_lint_pass(box temporary_assignment::Pass); reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignment);
reg.register_late_lint_pass(box transmute::Transmute); reg.register_late_lint_pass(box transmute::Transmute);
reg.register_late_lint_pass( reg.register_late_lint_pass(
box cognitive_complexity::CognitiveComplexity::new(conf.cognitive_complexity_threshold) 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_late_lint_pass(box escape::BoxedLocal{too_large_for_stack: conf.too_large_for_stack});
reg.register_early_lint_pass(box misc_early::MiscEarly); reg.register_early_lint_pass(box misc_early::MiscEarlyLints);
reg.register_late_lint_pass(box panic_unimplemented::Pass); reg.register_late_lint_pass(box panic_unimplemented::PanicUnimplemented);
reg.register_late_lint_pass(box strings::StringLitAsBytes); reg.register_late_lint_pass(box strings::StringLitAsBytes);
reg.register_late_lint_pass(box derive::Derive); reg.register_late_lint_pass(box derive::Derive);
reg.register_late_lint_pass(box types::CharLitAsU8); reg.register_late_lint_pass(box types::CharLitAsU8);
reg.register_late_lint_pass(box vec::Pass); reg.register_late_lint_pass(box vec::UselessVec);
reg.register_late_lint_pass(box drop_bounds::Pass); reg.register_late_lint_pass(box drop_bounds::DropBounds);
reg.register_late_lint_pass(box drop_forget_ref::Pass); 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 empty_enum::EmptyEnum);
reg.register_late_lint_pass(box types::AbsurdExtremeComparisons); reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
reg.register_late_lint_pass(box types::InvalidUpcastComparisons); 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 copies::CopyAndPaste);
reg.register_late_lint_pass(box copy_iterator::CopyIterator); 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_early_lint_pass(box formatting::Formatting);
reg.register_late_lint_pass(box swap::Swap); reg.register_late_lint_pass(box swap::Swap);
reg.register_early_lint_pass(box if_not_else::IfNotElse); 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 overflow_check_conditional::OverflowCheckConditional);
reg.register_late_lint_pass(box unused_label::UnusedLabel); 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 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() 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_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_late_lint_pass(box neg_multiply::NegMultiply);
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval); reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant); 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 eval_order_dependence::EvalOrderDependence);
reg.register_late_lint_pass(box missing_doc::MissingDoc::new()); 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 missing_inline::MissingInline);
reg.register_late_lint_pass(box ok_if_let::Pass); reg.register_late_lint_pass(box ok_if_let::OkIfLet);
reg.register_late_lint_pass(box redundant_pattern_matching::Pass); reg.register_late_lint_pass(box redundant_pattern_matching::RedundantPatternMatching);
reg.register_late_lint_pass(box partialeq_ne_impl::Pass); reg.register_late_lint_pass(box partialeq_ne_impl::PartialEqNeImpl);
reg.register_early_lint_pass(box reference::Pass); reg.register_early_lint_pass(box reference::DerefAddrOf);
reg.register_early_lint_pass(box reference::DerefPass); reg.register_early_lint_pass(box reference::RefInDeref);
reg.register_early_lint_pass(box double_parens::DoubleParens); 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 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 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 needless_pass_by_value::NeedlessPassByValue);
reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new( reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
conf.trivial_copy_size_limit, conf.trivial_copy_size_limit,
&reg.sess.target, &reg.sess.target,
)); ));
reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping); 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 conf.literal_representation_threshold
)); ));
reg.register_late_lint_pass(box use_self::UseSelf); reg.register_late_lint_pass(box use_self::UseSelf);
reg.register_late_lint_pass(box bytecount::ByteCount); reg.register_late_lint_pass(box bytecount::ByteCount);
reg.register_late_lint_pass(box infinite_iter::Pass); reg.register_late_lint_pass(box infinite_iter::InfiniteIter);
reg.register_late_lint_pass(box inline_fn_without_body::Pass); 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 invalid_ref::InvalidRef);
reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default()); reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
reg.register_late_lint_pass(box types::ImplicitHasher); 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 fallible_impl_from::FallibleImplFrom);
reg.register_late_lint_pass(box replace_consts::ReplaceConsts); reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
reg.register_late_lint_pass(box types::UnitArg); reg.register_late_lint_pass(box types::UnitArg);
reg.register_late_lint_pass(box double_comparison::Pass); reg.register_late_lint_pass(box double_comparison::DoubleComparisons);
reg.register_late_lint_pass(box question_mark::Pass); reg.register_late_lint_pass(box question_mark::QuestionMark);
reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl); 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 cargo_common_metadata::CargoCommonMetadata);
reg.register_early_lint_pass(box multiple_crate_versions::Pass); reg.register_early_lint_pass(box multiple_crate_versions::MultipleCrateVersions);
reg.register_early_lint_pass(box wildcard_dependencies::Pass); reg.register_early_lint_pass(box wildcard_dependencies::WildcardDependencies);
reg.register_late_lint_pass(box map_unit_fn::Pass); reg.register_late_lint_pass(box map_unit_fn::MapUnit);
reg.register_late_lint_pass(box infallible_destructuring_match::Pass); reg.register_late_lint_pass(box infallible_destructuring_match::InfallibleDestructingMatch);
reg.register_late_lint_pass(box inherent_impl::Pass::default()); 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 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 duration_subsec::DurationSubsec);
reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess); 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 indexing_slicing::IndexingSlicing);
reg.register_late_lint_pass(box non_copy_const::NonCopyConst); 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 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 types::RefToMut);
reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants); 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 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![ reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
arithmetic::FLOAT_ARITHMETIC, arithmetic::FLOAT_ARITHMETIC,

View File

@ -3,7 +3,7 @@ use rustc::hir::def::Def;
use rustc::hir::intravisit::*; use rustc::hir::intravisit::*;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; 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 rustc_data_structures::fx::{FxHashMap, FxHashSet};
use syntax::source_map::Span; use syntax::source_map::Span;
use syntax::symbol::keywords; use syntax::symbol::keywords;
@ -55,20 +55,9 @@ declare_clippy_lint! {
"unused lifetimes in function definitions" "unused lifetimes in function definitions"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]);
pub struct LifetimePass;
impl LintPass for LifetimePass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
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 {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Fn(ref decl, _, ref generics, id) = item.node { if let ItemKind::Fn(ref decl, _, ref generics, id) = item.node {
check_fn_inner(cx, decl, Some(id), generics, item.span); check_fn_inner(cx, decl, Some(id), generics, item.span);

View File

@ -4,7 +4,7 @@
use crate::utils::{snippet_opt, span_lint_and_sugg}; use crate::utils::{snippet_opt, span_lint_and_sugg};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::*; use syntax::ast::*;
use syntax_pos; use syntax_pos;
@ -334,23 +334,12 @@ impl WarningType {
} }
} }
#[derive(Copy, Clone)] declare_lint_pass!(LiteralDigitGrouping => [
pub struct LiteralDigitGrouping; UNREADABLE_LITERAL,
INCONSISTENT_DIGIT_GROUPING,
impl LintPass for LiteralDigitGrouping { LARGE_DIGIT_GROUPS,
fn get_lints(&self) -> LintArray { MISTYPED_LITERAL_SUFFIXES,
lint_array!( ]);
UNREADABLE_LITERAL,
INCONSISTENT_DIGIT_GROUPING,
LARGE_DIGIT_GROUPS,
MISTYPED_LITERAL_SUFFIXES,
)
}
fn name(&self) -> &'static str {
"LiteralDigitGrouping"
}
}
impl EarlyLintPass for LiteralDigitGrouping { impl EarlyLintPass for LiteralDigitGrouping {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
@ -488,22 +477,15 @@ impl LiteralDigitGrouping {
} }
} }
#[allow(clippy::module_name_repetitions)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct LiteralRepresentation { pub struct DecimalLiteralRepresentation {
threshold: u64, threshold: u64,
} }
impl LintPass for LiteralRepresentation { impl_lint_pass!(DecimalLiteralRepresentation => [DECIMAL_LITERAL_REPRESENTATION]);
fn get_lints(&self) -> LintArray {
lint_array!(DECIMAL_LITERAL_REPRESENTATION)
}
fn name(&self) -> &'static str { impl EarlyLintPass for DecimalLiteralRepresentation {
"DecimalLiteralRepresentation"
}
}
impl EarlyLintPass for LiteralRepresentation {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if in_external_macro(cx.sess(), expr.span) { if in_external_macro(cx.sess(), expr.span) {
return; return;
@ -515,7 +497,7 @@ impl EarlyLintPass for LiteralRepresentation {
} }
} }
impl LiteralRepresentation { impl DecimalLiteralRepresentation {
pub fn new(threshold: u64) -> Self { pub fn new(threshold: u64) -> Self {
Self { threshold } Self { threshold }
} }

View File

@ -7,7 +7,7 @@ use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedV
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::middle::region; 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 rustc::middle::region::CodeExtent;
use crate::consts::{constant, Constant}; use crate::consts::{constant, Constant};
use crate::utils::usage::mutated_variables; use crate::utils::usage::mutated_variables;
@ -439,39 +439,28 @@ declare_clippy_lint! {
"variables used within while expression are not mutated in the body" "variables used within while expression are not mutated in the body"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Loops => [
pub struct Pass; 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 LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
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 {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// we don't want to check expanded macros // we don't want to check expanded macros

View File

@ -6,14 +6,11 @@ use if_chain::if_chain;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::Ident; use syntax::ast::Ident;
use syntax::source_map::Span; use syntax::source_map::Span;
#[derive(Clone)]
pub struct Pass;
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests /// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests
/// `iterator.cloned()` instead /// `iterator.cloned()` instead
@ -42,17 +39,9 @@ declare_clippy_lint! {
"using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types" "using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types"
} }
impl LintPass for Pass { declare_lint_pass!(MapClone => [MAP_CLONE]);
fn get_lints(&self) -> LintArray {
lint_array!(MAP_CLONE)
}
fn name(&self) -> &'static str { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
"MapClone"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
if in_macro(e.span) { if in_macro(e.span) {
return; return;

View File

@ -4,13 +4,10 @@ use if_chain::if_chain;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::{self, Ty}; 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 rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
#[derive(Clone)]
pub struct Pass;
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for usage of `option.map(f)` where f is a function /// **What it does:** Checks for usage of `option.map(f)` where f is a function
/// or closure that returns the unit type. /// 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 ()" "using `result.map(f)`, where f is a function or closure that returns ()"
} }
impl LintPass for Pass { declare_lint_pass!(MapUnit => [OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN]);
fn get_lints(&self) -> LintArray {
lint_array!(OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN)
}
fn name(&self) -> &'static str {
"MapUnit"
}
}
fn is_unit_type(ty: Ty<'_>) -> bool { fn is_unit_type(ty: Ty<'_>) -> bool {
match ty.sty { 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) { fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) {
if in_macro(stmt.span) { if in_macro(stmt.span) {
return; return;

View File

@ -10,7 +10,7 @@ use rustc::hir::def::CtorKind;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty::{self, Ty}; 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 rustc_errors::Applicability;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::Bound; use std::collections::Bound;
@ -215,29 +215,18 @@ declare_clippy_lint! {
"a wildcard enum match arm using `_`" "a wildcard enum match arm using `_`"
} }
#[allow(missing_copy_implementations)] declare_lint_pass!(Matches => [
pub struct MatchPass; 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 LintPass for MatchPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
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 {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_external_macro(cx.sess(), expr.span) { if in_external_macro(cx.sess(), expr.span) {
return; return;

View File

@ -2,7 +2,7 @@ use crate::utils::{paths, snippet, span_lint_and_then, walk_ptrs_ty_depth};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::{Expr, ExprKind}; use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use std::iter; use std::iter;
@ -27,17 +27,7 @@ declare_clippy_lint! {
"calling mem::descriminant on non-enum type" "calling mem::descriminant on non-enum type"
} }
pub struct MemDiscriminant; declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]);
impl LintPass for MemDiscriminant {
fn get_lints(&self) -> LintArray {
lint_array![MEM_DISCRIMINANT_NON_ENUM]
}
fn name(&self) -> &'static str {
"MemDiscriminant"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -1,7 +1,7 @@
use crate::utils::{paths, span_lint}; use crate::utils::{paths, span_lint};
use rustc::hir::{Expr, ExprKind}; use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is /// **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" "`mem::forget` usage on `Drop` types, likely to cause memory leaks"
} }
pub struct MemForget; declare_lint_pass!(MemForget => [MEM_FORGET]);
impl LintPass for MemForget {
fn get_lints(&self) -> LintArray {
lint_array![MEM_FORGET]
}
fn name(&self) -> &'static str {
"MemForget"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -2,7 +2,7 @@ use crate::utils::{match_qpath, paths, snippet_with_applicability, span_lint_and
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::{Expr, ExprKind, MutMutable, QPath}; use rustc::hir::{Expr, ExprKind, MutMutable, QPath};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -32,17 +32,7 @@ declare_clippy_lint! {
"replacing an `Option` with `None` instead of `take()`" "replacing an `Option` with `None` instead of `take()`"
} }
pub struct MemReplace; declare_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE]);
impl LintPass for MemReplace {
fn get_lints(&self) -> LintArray {
lint_array![MEM_REPLACE_OPTION_WITH_NONE]
}
fn name(&self) -> &'static str {
"MemReplace"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -11,7 +11,7 @@ use rustc::hir;
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass};
use rustc::ty::{self, Predicate, Ty}; 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 rustc_errors::Applicability;
use syntax::ast; use syntax::ast;
use syntax::source_map::{BytePos, Span}; 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, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
}; };
#[derive(Clone)]
pub struct Pass;
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for `.unwrap()` calls on `Option`s. /// **What it does:** Checks for `.unwrap()` calls on `Option`s.
/// ///
@ -777,52 +774,44 @@ declare_clippy_lint! {
"using `.into_iter()` on a reference" "using `.into_iter()` on a reference"
} }
impl LintPass for Pass { declare_lint_pass!(Methods => [
fn get_lints(&self) -> LintArray { OPTION_UNWRAP_USED,
lint_array!( RESULT_UNWRAP_USED,
OPTION_UNWRAP_USED, SHOULD_IMPLEMENT_TRAIT,
RESULT_UNWRAP_USED, WRONG_SELF_CONVENTION,
SHOULD_IMPLEMENT_TRAIT, WRONG_PUB_SELF_CONVENTION,
WRONG_SELF_CONVENTION, OK_EXPECT,
WRONG_PUB_SELF_CONVENTION, OPTION_MAP_UNWRAP_OR,
OK_EXPECT, OPTION_MAP_UNWRAP_OR_ELSE,
OPTION_MAP_UNWRAP_OR, RESULT_MAP_UNWRAP_OR_ELSE,
OPTION_MAP_UNWRAP_OR_ELSE, OPTION_MAP_OR_NONE,
RESULT_MAP_UNWRAP_OR_ELSE, OR_FUN_CALL,
OPTION_MAP_OR_NONE, EXPECT_FUN_CALL,
OR_FUN_CALL, CHARS_NEXT_CMP,
EXPECT_FUN_CALL, CHARS_LAST_CMP,
CHARS_NEXT_CMP, CLONE_ON_COPY,
CHARS_LAST_CMP, CLONE_ON_REF_PTR,
CLONE_ON_COPY, CLONE_DOUBLE_REF,
CLONE_ON_REF_PTR, NEW_RET_NO_SELF,
CLONE_DOUBLE_REF, SINGLE_CHAR_PATTERN,
NEW_RET_NO_SELF, SEARCH_IS_SOME,
SINGLE_CHAR_PATTERN, TEMPORARY_CSTRING_AS_PTR,
SEARCH_IS_SOME, FILTER_NEXT,
TEMPORARY_CSTRING_AS_PTR, FILTER_MAP,
FILTER_NEXT, MAP_FLATTEN,
FILTER_MAP, ITER_NTH,
MAP_FLATTEN, ITER_SKIP_NEXT,
ITER_NTH, GET_UNWRAP,
ITER_SKIP_NEXT, STRING_EXTEND_CHARS,
GET_UNWRAP, ITER_CLONED_COLLECT,
STRING_EXTEND_CHARS, USELESS_ASREF,
ITER_CLONED_COLLECT, UNNECESSARY_FOLD,
USELESS_ASREF, UNNECESSARY_FILTER_MAP,
UNNECESSARY_FOLD, INTO_ITER_ON_ARRAY,
UNNECESSARY_FILTER_MAP, INTO_ITER_ON_REF,
INTO_ITER_ON_ARRAY, ]);
INTO_ITER_ON_REF,
)
}
fn name(&self) -> &'static str { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
"Methods"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if in_macro(expr.span) { if in_macro(expr.span) {

View File

@ -2,7 +2,7 @@ use crate::consts::{constant_simple, Constant};
use crate::utils::{paths, span_lint}; use crate::utils::{paths, span_lint};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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; use std::cmp::Ordering;
declare_clippy_lint! { declare_clippy_lint! {
@ -25,17 +25,7 @@ declare_clippy_lint! {
"`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant" "`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant"
} }
pub struct MinMaxPass; declare_lint_pass!(MinMaxPass => [MIN_MAX]);
impl LintPass for MinMaxPass {
fn get_lints(&self) -> LintArray {
lint_array!(MIN_MAX)
}
fn name(&self) -> &'static str {
"MinMax"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -4,7 +4,7 @@ use rustc::hir::intravisit::FnKind;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::source_map::{ExpnFormat, Span}; 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" "using `==` or `!=` on float constants instead of comparing difference with an epsilon"
} }
#[derive(Copy, Clone)] declare_lint_pass!(MiscLints => [
pub struct Pass; 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 LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
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 {
fn check_fn( fn check_fn(
&mut self, &mut self,
cx: &LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,

View File

@ -1,7 +1,7 @@
use crate::utils::{constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then}; use crate::utils::{constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; 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_data_structures::fx::FxHashMap;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use std::char; use std::char;
@ -172,27 +172,16 @@ declare_clippy_lint! {
"shadowing a builtin type" "shadowing a builtin type"
} }
#[derive(Copy, Clone)] declare_lint_pass!(MiscEarlyLints => [
pub struct MiscEarly; UNNEEDED_FIELD_PATTERN,
DUPLICATE_UNDERSCORE_ARGUMENT,
impl LintPass for MiscEarly { REDUNDANT_CLOSURE_CALL,
fn get_lints(&self) -> LintArray { DOUBLE_NEG,
lint_array!( MIXED_CASE_HEX_LITERALS,
UNNEEDED_FIELD_PATTERN, UNSEPARATED_LITERAL_SUFFIX,
DUPLICATE_UNDERSCORE_ARGUMENT, ZERO_PREFIXED_LITERAL,
REDUNDANT_CLOSURE_CALL, BUILTIN_TYPE_SHADOW
DOUBLE_NEG, ]);
MIXED_CASE_HEX_LITERALS,
UNSEPARATED_LITERAL_SUFFIX,
ZERO_PREFIXED_LITERAL,
BUILTIN_TYPE_SHADOW
)
}
fn name(&self) -> &'static str {
"MiscEarlyLints"
}
}
// Used to find `return` statements or equivalents e.g., `?` // Used to find `return` statements or equivalents e.g., `?`
struct ReturnVisitor { 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) { fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
for param in &gen.params { for param in &gen.params {
if let GenericParamKind::Type { .. } = param.kind { 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) { fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
if_chain! { if_chain! {
if let LitKind::Int(value, ..) = lit.node; if let LitKind::Int(value, ..) = lit.node;

View File

@ -3,7 +3,7 @@ use rustc::hir;
use rustc::hir::intravisit::FnKind; use rustc::hir::intravisit::FnKind;
use rustc::hir::{Body, Constness, FnDecl, HirId}; use rustc::hir::{Body, Constness, FnDecl, HirId};
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
use syntax_pos::Span; use syntax_pos::Span;
@ -57,18 +57,7 @@ declare_clippy_lint! {
"Lint functions definitions that could be made `const fn`" "Lint functions definitions that could be made `const fn`"
} }
#[derive(Clone)] declare_lint_pass!(MissingConstForFn => [MISSING_CONST_FOR_FN]);
pub struct MissingConstForFn;
impl LintPass for MissingConstForFn {
fn get_lints(&self) -> LintArray {
lint_array!(MISSING_CONST_FOR_FN)
}
fn name(&self) -> &'static str {
"MissingConstForFn"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
fn check_fn( fn check_fn(

View File

@ -10,7 +10,7 @@ use if_chain::if_chain;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty; 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::ast::{self, MetaItem, MetaItemKind};
use syntax::attr; use syntax::attr;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -103,15 +103,7 @@ impl MissingDoc {
} }
} }
impl LintPass for MissingDoc { impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]);
fn get_lints(&self) -> LintArray {
lint_array![MISSING_DOCS_IN_PRIVATE_ITEMS]
}
fn name(&self) -> &'static str {
"MissingDoc"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
fn enter_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, attrs: &'tcx [ast::Attribute]) { fn enter_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, attrs: &'tcx [ast::Attribute]) {

View File

@ -1,7 +1,7 @@
use crate::utils::span_lint; use crate::utils::span_lint;
use rustc::hir; use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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::ast;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -56,8 +56,6 @@ declare_clippy_lint! {
"detects missing #[inline] attribute for public callables (functions, trait methods, methods...)" "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) { 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")); let has_inline = attrs.iter().any(|a| a.check_name("inline"));
if !has_inline { if !has_inline {
@ -79,15 +77,7 @@ fn is_executable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>) -> bool {
}) })
} }
impl LintPass for MissingInline { declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
fn get_lints(&self) -> LintArray {
lint_array![MISSING_INLINE_IN_PUBLIC_ITEMS]
}
fn name(&self) -> &'static str {
"MissingInline"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {

View File

@ -2,7 +2,7 @@
use crate::utils::span_lint; use crate::utils::span_lint;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 syntax::{ast::*, source_map::DUMMY_SP};
use cargo_metadata; use cargo_metadata;
@ -31,19 +31,9 @@ declare_clippy_lint! {
"multiple versions of the same crate being used" "multiple versions of the same crate being used"
} }
pub struct Pass; declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);
impl LintPass for Pass { impl EarlyLintPass for MultipleCrateVersions {
fn get_lints(&self) -> LintArray {
lint_array!(MULTIPLE_CRATE_VERSIONS)
}
fn name(&self) -> &'static str {
"MultipleCrateVersions"
}
}
impl EarlyLintPass for Pass {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() { let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() {
metadata metadata

View File

@ -3,7 +3,7 @@ use rustc::hir;
use rustc::hir::intravisit; use rustc::hir::intravisit;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for instances of `mut mut` references. /// **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 ...`" "usage of double-mut refs, e.g., `&mut &mut ...`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(MutMut => [MUT_MUT]);
pub struct MutMut;
impl LintPass for MutMut {
fn get_lints(&self) -> LintArray {
lint_array!(MUT_MUT)
}
fn name(&self) -> &'static str {
"MutMut"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut {
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) { fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {

View File

@ -3,7 +3,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::subst::Subst; use rustc::ty::subst::Subst;
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Detects giving a mutable reference to a function that only /// **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" "an argument passed as a mutable reference although the callee only demands an immutable reference"
} }
#[derive(Copy, Clone)] declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]);
pub struct UnnecessaryMutPassed;
impl LintPass for UnnecessaryMutPassed {
fn get_lints(&self) -> LintArray {
lint_array!(UNNECESSARY_MUT_PASSED)
}
fn name(&self) -> &'static str {
"UnneccessaryMutPassed"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -6,7 +6,7 @@ use crate::utils::{match_type, paths, span_lint};
use rustc::hir::Expr; use rustc::hir::Expr;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::ast; use syntax::ast;
declare_clippy_lint! { declare_clippy_lint! {
@ -49,19 +49,9 @@ declare_clippy_lint! {
"using a mutex for an integer type" "using a mutex for an integer type"
} }
impl LintPass for MutexAtomic { declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]);
fn get_lints(&self) -> LintArray {
lint_array!(MUTEX_ATOMIC, MUTEX_INTEGER)
}
fn name(&self) -> &'static str { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex {
"Mutex"
}
}
pub struct MutexAtomic;
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutexAtomic {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
let ty = cx.tables.expr_ty(expr); let ty = cx.tables.expr_ty(expr);
if let ty::Adt(_, subst) = ty.sty { if let ty::Adt(_, subst) = ty.sty {

View File

@ -6,7 +6,7 @@ use crate::utils::sugg::Sugg;
use crate::utils::{in_macro, span_lint, span_lint_and_sugg}; use crate::utils::{in_macro, span_lint, span_lint_and_sugg};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::source_map::Spanned; 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`" "comparing a variable to a boolean, e.g., `if x == true` or `if x != true`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]);
pub struct NeedlessBool;
impl LintPass for NeedlessBool {
fn get_lints(&self) -> LintArray {
lint_array!(NEEDLESS_BOOL)
}
fn name(&self) -> &'static str {
"NeedlessBool"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { 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 false
} }
#[derive(Copy, Clone)] declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]);
pub struct BoolComparison;
impl LintPass for BoolComparison {
fn get_lints(&self) -> LintArray {
lint_array!(BOOL_COMPARISON)
}
fn name(&self) -> &'static str {
"BoolComparison"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -8,7 +8,7 @@ use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, MutImmutable, P
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::ty::adjustment::{Adjust, Adjustment}; 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; use rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -34,15 +34,7 @@ pub struct NeedlessBorrow {
derived_item: Option<HirId>, derived_item: Option<HirId>,
} }
impl LintPass for NeedlessBorrow { impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
fn get_lints(&self) -> LintArray {
lint_array!(NEEDLESS_BORROW)
}
fn name(&self) -> &'static str {
"NeedlessBorrow"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {

View File

@ -6,7 +6,7 @@ use crate::utils::{in_macro, snippet, span_lint_and_then};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind}; use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
declare_clippy_lint! { declare_clippy_lint! {
@ -51,18 +51,7 @@ declare_clippy_lint! {
"taking a needless borrowed reference" "taking a needless borrowed reference"
} }
#[derive(Copy, Clone)] declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]);
pub struct NeedlessBorrowedRef;
impl LintPass for NeedlessBorrowedRef {
fn get_lints(&self) -> LintArray {
lint_array!(NEEDLESS_BORROWED_REFERENCE)
}
fn name(&self) -> &'static str {
"NeedlessBorrowedRef"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) { fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {

View File

@ -34,7 +34,7 @@
//! //!
//! This lint is **warn** by default. //! This lint is **warn** by default.
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 std::borrow::Cow;
use syntax::ast; use syntax::ast;
use syntax::source_map::{original_sp, DUMMY_SP}; 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" "`continue` statements that can be replaced by a rearrangement of code"
} }
#[derive(Copy, Clone)] declare_lint_pass!(NeedlessContinue => [NEEDLESS_CONTINUE]);
pub struct NeedlessContinue;
impl LintPass for NeedlessContinue {
fn get_lints(&self) -> LintArray {
lint_array!(NEEDLESS_CONTINUE)
}
fn name(&self) -> &'static str {
"NeedlessContinue"
}
}
impl EarlyLintPass for NeedlessContinue { impl EarlyLintPass for NeedlessContinue {
fn check_expr(&mut self, ctx: &EarlyContext<'_>, expr: &ast::Expr) { fn check_expr(&mut self, ctx: &EarlyContext<'_>, expr: &ast::Expr) {

View File

@ -12,7 +12,7 @@ use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc; use rustc::middle::mem_categorization as mc;
use rustc::traits; use rustc::traits;
use rustc::ty::{self, RegionKind, TypeFoldable}; 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_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_target::spec::abi::Abi; 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" "functions taking arguments by value, but not consuming them in its body"
} }
pub struct NeedlessPassByValue; declare_lint_pass!(NeedlessPassByValue => [NEEDLESS_PASS_BY_VALUE]);
impl LintPass for NeedlessPassByValue {
fn get_lints(&self) -> LintArray {
lint_array![NEEDLESS_PASS_BY_VALUE]
}
fn name(&self) -> &'static str {
"NeedlessPassByValue"
}
}
macro_rules! need { macro_rules! need {
($e: expr) => { ($e: expr) => {

View File

@ -2,7 +2,7 @@ use crate::utils::span_lint;
use rustc::hir::{Expr, ExprKind}; use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for needlessly including a base struct on update /// **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" "using `Foo { ..base }` when there are no missing fields"
} }
#[derive(Copy, Clone)] declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate {
fn get_lints(&self) -> LintArray {
lint_array!(NEEDLESS_UPDATE)
}
fn name(&self) -> &'static str {
"NeedUpdate"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.node { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.node {
let ty = cx.tables.expr_ty(expr); let ty = cx.tables.expr_ty(expr);

View File

@ -1,7 +1,7 @@
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; 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}; 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." "The use of negated comparison operators on partially ordered types may produce confusing code."
} }
pub struct NoNegCompOpForPartialOrd; declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]);
impl LintPass for NoNegCompOpForPartialOrd {
fn get_lints(&self) -> LintArray {
lint_array!(NEG_CMP_OP_ON_PARTIAL_ORD)
}
fn name(&self) -> &'static str {
"NoNegCompOpForPartialOrd"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {

View File

@ -1,7 +1,7 @@
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 syntax::source_map::{Span, Spanned};
use crate::consts::{self, Constant}; use crate::consts::{self, Constant};
@ -23,18 +23,7 @@ declare_clippy_lint! {
"multiplying integers with -1" "multiplying integers with -1"
} }
#[derive(Copy, Clone)] declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
pub struct NegMultiply;
impl LintPass for NegMultiply {
fn get_lints(&self) -> LintArray {
lint_array!(NEG_MULTIPLY)
}
fn name(&self) -> &'static str {
"NegMultiply"
}
}
#[allow(clippy::match_same_arms)] #[allow(clippy::match_same_arms)]
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {

View File

@ -7,7 +7,7 @@ use rustc::hir::def_id::DefId;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::util::nodemap::NodeSet; 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 rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -89,15 +89,7 @@ pub struct NewWithoutDefault {
impling_types: Option<NodeSet>, impling_types: Option<NodeSet>,
} }
impl LintPass for NewWithoutDefault { impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]);
fn get_lints(&self) -> LintArray {
lint_array!(NEW_WITHOUT_DEFAULT)
}
fn name(&self) -> &'static str {
"NewWithoutDefault"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {

View File

@ -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::def::Def;
use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource}; use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use std::ops::Deref; use std::ops::Deref;
@ -93,20 +93,9 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
} }
} }
#[derive(Copy, Clone)] declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect {
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 {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
if let StmtKind::Semi(ref expr) = stmt.node { if let StmtKind::Semi(ref expr) = stmt.node {
if has_no_effect(cx, expr) { if has_no_effect(cx, expr) {

View File

@ -9,7 +9,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::ty::adjustment::Adjust; use rustc::ty::adjustment::Adjust;
use rustc::ty::{Ty, TypeFlags}; 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_errors::Applicability;
use rustc_typeck::hir_ty_to_ty; use rustc_typeck::hir_ty_to_ty;
use syntax_pos::{Span, DUMMY_SP}; 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; declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST]);
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"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item) {

View File

@ -1,6 +1,6 @@
use crate::utils::{span_lint, span_lint_and_then}; use crate::utils::{span_lint, span_lint_and_then};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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::ast::*;
use syntax::attr; use syntax::attr;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -63,19 +63,12 @@ declare_clippy_lint! {
"unclear name" "unclear name"
} }
#[derive(Copy, Clone)]
pub struct NonExpressiveNames { pub struct NonExpressiveNames {
pub single_char_binding_names_threshold: u64, pub single_char_binding_names_threshold: u64,
} }
impl LintPass for NonExpressiveNames { impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]);
fn get_lints(&self) -> LintArray {
lint_array!(SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS)
}
fn name(&self) -> &'static str {
"NoneExpressiveNames"
}
}
struct ExistingName { struct ExistingName {
interned: LocalInternedString, interned: LocalInternedString,

View File

@ -2,7 +2,7 @@ use crate::utils::{match_type, method_chain_args, paths, snippet, span_help_and_
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:*** Checks for unnecessary `ok()` in if let. /// **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" "usage of `ok()` in `if let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead"
} }
#[derive(Copy, Clone)] declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet {
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 {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! { //begin checking variables if_chain! { //begin checking variables
if let ExprKind::Match(ref op, ref body, ref source) = expr.node; //test if expr is a match if let ExprKind::Match(ref op, ref body, ref source) = expr.node; //test if expr is a match

View File

@ -1,7 +1,7 @@
use crate::utils::{match_type, paths, span_lint, walk_ptrs_ty}; use crate::utils::{match_type, paths, span_lint, walk_ptrs_ty};
use rustc::hir::{Expr, ExprKind}; use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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::ast::LitKind;
use syntax::source_map::{Span, Spanned}; use syntax::source_map::{Span, Spanned};
@ -25,20 +25,9 @@ declare_clippy_lint! {
"nonsensical combination of options for opening a file" "nonsensical combination of options for opening a file"
} }
#[derive(Copy, Clone)] declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]);
pub struct NonSensical;
impl LintPass for NonSensical { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions {
fn get_lints(&self) -> LintArray {
lint_array!(NONSENSICAL_OPEN_OPTIONS)
}
fn name(&self) -> &'static str {
"OpenOptions"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSensical {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::MethodCall(ref path, _, ref arguments) = e.node { if let ExprKind::MethodCall(ref path, _, ref arguments) = e.node {
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0]));

View File

@ -2,7 +2,7 @@ use crate::utils::{span_lint, SpanlessEq};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:** Detects classic underflow/overflow checks. /// **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" "overflow checks inspired by C which are likely to panic"
} }
#[derive(Copy, Clone)] declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]);
pub struct OverflowCheckConditional;
impl LintPass for OverflowCheckConditional {
fn get_lints(&self) -> LintArray {
lint_array!(OVERFLOW_CHECK_CONDITIONAL)
}
fn name(&self) -> &'static str {
"OverflowCheckConditional"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
// a + b < a, a > a + b, a < a - b, a - b > a // a + b < a, a > a + b, a < a - b, a - b > a

View File

@ -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 if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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::ast::LitKind;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
@ -42,19 +42,9 @@ declare_clippy_lint! {
"`unimplemented!` should not be present in production code" "`unimplemented!` should not be present in production code"
} }
pub struct Pass; declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED]);
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
fn get_lints(&self) -> LintArray {
lint_array!(PANIC_PARAMS, UNIMPLEMENTED)
}
fn name(&self) -> &'static str {
"PanicUnimplemented"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! { if_chain! {
if let ExprKind::Block(ref block, _) = expr.node; if let ExprKind::Block(ref block, _) = expr.node;

View File

@ -2,7 +2,7 @@ use crate::utils::{is_automatically_derived, span_lint_hir};
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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! { declare_clippy_lint! {
/// **What it does:** Checks for manual re-implementations of `PartialEq::ne`. /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
@ -28,20 +28,9 @@ declare_clippy_lint! {
"re-implementing `PartialEq::ne`" "re-implementing `PartialEq::ne`"
} }
#[derive(Clone, Copy)] declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]);
pub struct Pass;
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl {
fn get_lints(&self) -> LintArray {
lint_array!(PARTIALEQ_NE_IMPL)
}
fn name(&self) -> &'static str {
"PartialEqNeImpl"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if_chain! { if_chain! {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node; if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;

View File

@ -1,6 +1,6 @@
use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg}; use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::*; use syntax::ast::*;
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
@ -28,18 +28,7 @@ declare_clippy_lint! {
"operations where precedence may be unclear" "operations where precedence may be unclear"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Precedence => [PRECEDENCE]);
pub struct Precedence;
impl LintPass for Precedence {
fn get_lints(&self) -> LintArray {
lint_array!(PRECEDENCE)
}
fn name(&self) -> &'static str {
"Precedence"
}
}
impl EarlyLintPass for Precedence { impl EarlyLintPass for Precedence {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {

View File

@ -7,7 +7,7 @@ use rustc::hir::QPath;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty; use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use std::borrow::Cow; use std::borrow::Cow;
use syntax::source_map::Span; use syntax::source_map::Span;
@ -94,20 +94,9 @@ declare_clippy_lint! {
"fns that create mutable refs from immutable ref args" "fns that create mutable refs from immutable ref args"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]);
pub struct PointerPass;
impl LintPass for PointerPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
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 {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Fn(ref decl, _, _, body_id) = item.node { if let ItemKind::Fn(ref decl, _, _, body_id) = item.node {
check_fn(cx, decl, item.hir_id, Some(body_id)); check_fn(cx, decl, item.hir_id, Some(body_id));

View File

@ -1,5 +1,7 @@
use crate::utils; 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 rustc_errors::Applicability;
use std::fmt; use std::fmt;
@ -39,21 +41,10 @@ declare_clippy_lint! {
"unneeded pointer offset cast" "unneeded pointer offset cast"
} }
#[derive(Copy, Clone, Debug)] declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]);
pub struct Pass;
impl lint::LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
fn get_lints(&self) -> lint::LintArray { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
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) {
// Check if the expressions is a ptr.offset or ptr.wrapping_offset method call // 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) { let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) {
Some(call_arg) => call_arg, 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 // If the given expression is a cast from a usize, return the lhs of the cast
fn expr_as_cast_from_usize<'a, 'tcx>( fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<&'tcx Expr> {
cx: &lint::LateContext<'a, 'tcx>, if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.node {
expr: &'tcx hir::Expr,
) -> Option<&'tcx hir::Expr> {
if let hir::ExprKind::Cast(ref cast_lhs_expr, _) = expr.node {
if is_expr_ty_usize(cx, &cast_lhs_expr) { if is_expr_ty_usize(cx, &cast_lhs_expr) {
return Some(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 // 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. // receiver, the arg of the method call, and the method.
fn expr_as_ptr_offset_call<'a, 'tcx>( fn expr_as_ptr_offset_call<'a, 'tcx>(
cx: &lint::LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,
expr: &'tcx hir::Expr, expr: &'tcx Expr,
) -> Option<(&'tcx hir::Expr, &'tcx hir::Expr, Method)> { ) -> Option<(&'tcx Expr, &'tcx Expr, Method)> {
if let hir::ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node { if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node {
if is_expr_ty_raw_ptr(cx, &args[0]) { if is_expr_ty_raw_ptr(cx, &args[0]) {
if path_segment.ident.name == "offset" { if path_segment.ident.name == "offset" {
return Some((&args[0], &args[1], Method::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? // 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 cx.tables.expr_ty(expr) == cx.tcx.types.usize
} }
// Is the type of the expression a raw pointer? // 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() cx.tables.expr_ty(expr).is_unsafe_ptr()
} }
fn build_suggestion<'a, 'tcx>( fn build_suggestion<'a, 'tcx>(
cx: &lint::LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,
method: Method, method: Method,
receiver_expr: &hir::Expr, receiver_expr: &Expr,
cast_lhs_expr: &hir::Expr, cast_lhs_expr: &Expr,
) -> Option<String> { ) -> Option<String> {
let receiver = utils::snippet_opt(cx, receiver_expr.span)?; let receiver = utils::snippet_opt(cx, receiver_expr.span)?;
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?; let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?;

View File

@ -2,7 +2,7 @@ use if_chain::if_chain;
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ptr::P; use syntax::ptr::P;
@ -34,20 +34,9 @@ declare_clippy_lint! {
"checks for expressions that could be replaced by the question mark operator" "checks for expressions that could be replaced by the question mark operator"
} }
#[derive(Copy, Clone)] declare_lint_pass!(QuestionMark => [QUESTION_MARK]);
pub struct Pass;
impl LintPass for Pass { impl QuestionMark {
fn get_lints(&self) -> LintArray {
lint_array!(QUESTION_MARK)
}
fn name(&self) -> &'static str {
"QuestionMark"
}
}
impl Pass {
/// Checks if the given expression on the given context matches the following structure: /// Checks if the given expression on the given context matches the following structure:
/// ///
/// ```ignore /// ```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) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
Self::check_is_none_and_early_return_none(cx, expr); Self::check_is_none_and_early_return_none(cx, expr);
} }

View File

@ -1,7 +1,7 @@
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; 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 rustc_errors::Applicability;
use syntax::ast::RangeLimits; use syntax::ast::RangeLimits;
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
@ -86,25 +86,14 @@ declare_clippy_lint! {
"`x..=(y-1)` reads better as `x..y`" "`x..=(y-1)` reads better as `x..y`"
} }
#[derive(Copy, Clone)] declare_lint_pass!(Ranges => [
pub struct Pass; ITERATOR_STEP_BY_ZERO,
RANGE_ZIP_WITH_LEN,
RANGE_PLUS_ONE,
RANGE_MINUS_ONE
]);
impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
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 {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::MethodCall(ref path, _, ref args) = expr.node { if let ExprKind::MethodCall(ref path, _, ref args) = expr.node {
let name = path.ident.as_str(); let name = path.ident.as_str();

Some files were not shown because too many files have changed in this diff Show More