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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ use crate::utils::{paths, span_lint};
use if_chain::if_chain;
use rustc::hir::*;
use rustc::lint::{LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
/// **What it does:** Checks for generics with `std::ops::Drop` as bounds.
@ -35,19 +35,9 @@ declare_clippy_lint! {
const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \
Use `std::mem::needs_drop` to detect if a type has drop glue.";
pub struct Pass;
declare_lint_pass!(DropBounds => [DROP_BOUNDS]);
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(DROP_BOUNDS)
}
fn name(&self) -> &'static str {
"DropBounds"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds {
fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam) {
for bound in &p.bounds {
lint_bound(cx, bound);

View File

@ -3,7 +3,7 @@ use if_chain::if_chain;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::drop` with a reference
@ -106,19 +106,9 @@ const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that imp
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements Copy. \
Forgetting a copy leaves the original intact.";
pub struct Pass;
declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]);
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY)
}
fn name(&self) -> &'static str {
"DropForgetRef"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! {
if let ExprKind::Call(ref path, ref args) = expr.node;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ use if_chain::if_chain;
use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use std::f32;
use std::f64;
@ -35,17 +35,7 @@ declare_clippy_lint! {
"excessive precision for float literal"
}
pub struct ExcessivePrecision;
impl LintPass for ExcessivePrecision {
fn get_lints(&self) -> LintArray {
lint_array!(EXCESSIVE_PRECISION)
}
fn name(&self) -> &'static str {
"ExcessivePrecision"
}
}
declare_lint_pass!(ExcessivePrecision => [EXCESSIVE_PRECISION]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
@ -72,7 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
impl ExcessivePrecision {
// None if nothing to lint, Some(suggestion) if lint necessary
fn check(&self, sym: Symbol, fty: FloatTy) -> Option<String> {
fn check(self, sym: Symbol, fty: FloatTy) -> Option<String> {
let max = max_digits(fty);
let sym_str = sym.as_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 rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use syntax::ast::LitKind;
@ -24,20 +24,9 @@ declare_clippy_lint! {
"using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work"
}
#[derive(Copy, Clone, Debug)]
pub struct Pass;
declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]);
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(EXPLICIT_WRITE)
}
fn name(&self) -> &'static str {
"ExplicitWrite"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! {
// match call to unwrap

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ use rustc::hir::def::Def;
use rustc::hir::intravisit;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_tool_lint, impl_lint_pass};
use rustc_data_structures::fx::FxHashSet;
use rustc_target::spec::abi::Abi;
use syntax::source_map::Span;
@ -93,15 +93,7 @@ impl Functions {
}
}
impl LintPass for Functions {
fn get_lints(&self) -> LintArray {
lint_array!(TOO_MANY_ARGUMENTS, TOO_MANY_LINES, NOT_UNSAFE_PTR_ARG_DEREF)
}
fn name(&self) -> &'static str {
"Functions"
}
}
impl_lint_pass!(Functions => [TOO_MANY_ARGUMENTS, TOO_MANY_LINES, NOT_UNSAFE_PTR_ARG_DEREF]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
fn check_fn(

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

View File

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

View File

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

View File

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

View File

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

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

View File

@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, match_type, paths, span_lint};
@ -41,20 +41,9 @@ declare_clippy_lint! {
"possible infinite iteration"
}
#[derive(Copy, Clone)]
pub struct Pass;
declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]);
impl LintPass for Pass {
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 {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfiniteIter {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
let (lint, msg) = match complete_infinite_iter(cx, expr) {
Infinite => (INFINITE_ITER, "infinite iteration detected"),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -290,7 +290,7 @@ pub fn register_pre_expansion_lints(
store: &mut rustc::lint::LintStore,
conf: &Conf,
) {
store.register_pre_expansion_pass(Some(session), true, false, box write::Pass);
store.register_pre_expansion_pass(Some(session), true, false, box write::Write);
store.register_pre_expansion_pass(
Some(session),
true,
@ -305,8 +305,8 @@ pub fn register_pre_expansion_lints(
single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
},
);
store.register_pre_expansion_pass(Some(session), true, false, box attrs::CfgAttrPass);
store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::Pass);
store.register_pre_expansion_pass(Some(session), true, false, box attrs::DeprecatedCfgAttribute);
store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::DbgMacro);
}
#[doc(hidden)]
@ -421,13 +421,13 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
);
// end deprecated lints, do not remove this comment, its used in `update_lints`
reg.register_late_lint_pass(box serde_api::Serde);
reg.register_early_lint_pass(box utils::internal_lints::Clippy);
reg.register_late_lint_pass(box serde_api::SerdeAPI);
reg.register_early_lint_pass(box utils::internal_lints::ClippyLintsInternal);
reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
reg.register_late_lint_pass(box utils::inspector::Pass);
reg.register_late_lint_pass(box utils::author::Pass);
reg.register_late_lint_pass(box types::TypePass);
reg.register_late_lint_pass(box utils::inspector::DeepCodeInspector);
reg.register_late_lint_pass(box utils::author::Author);
reg.register_late_lint_pass(box types::Types);
reg.register_late_lint_pass(box booleans::NonminimalBool);
reg.register_late_lint_pass(box eq_op::EqOp);
reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold));
@ -435,68 +435,68 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box enum_clike::UnportableVariant);
reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision);
reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold));
reg.register_late_lint_pass(box ptr::PointerPass);
reg.register_late_lint_pass(box ptr::Ptr);
reg.register_late_lint_pass(box needless_bool::NeedlessBool);
reg.register_late_lint_pass(box needless_bool::BoolComparison);
reg.register_late_lint_pass(box approx_const::Pass);
reg.register_late_lint_pass(box misc::Pass);
reg.register_late_lint_pass(box approx_const::ApproxConstant);
reg.register_late_lint_pass(box misc::MiscLints);
reg.register_early_lint_pass(box precedence::Precedence);
reg.register_early_lint_pass(box needless_continue::NeedlessContinue);
reg.register_late_lint_pass(box eta_reduction::EtaPass);
reg.register_late_lint_pass(box eta_reduction::EtaReduction);
reg.register_late_lint_pass(box identity_op::IdentityOp);
reg.register_late_lint_pass(box erasing_op::ErasingOp);
reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
reg.register_late_lint_pass(box mut_mut::MutMut);
reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
reg.register_late_lint_pass(box len_zero::LenZero);
reg.register_late_lint_pass(box attrs::AttrPass);
reg.register_late_lint_pass(box attrs::Attributes);
reg.register_early_lint_pass(box collapsible_if::CollapsibleIf);
reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
reg.register_late_lint_pass(box unicode::Unicode);
reg.register_late_lint_pass(box strings::StringAdd);
reg.register_early_lint_pass(box returns::ReturnPass);
reg.register_late_lint_pass(box implicit_return::Pass);
reg.register_late_lint_pass(box methods::Pass);
reg.register_late_lint_pass(box map_clone::Pass);
reg.register_late_lint_pass(box shadow::Pass);
reg.register_late_lint_pass(box types::LetPass);
reg.register_early_lint_pass(box returns::Return);
reg.register_late_lint_pass(box implicit_return::ImplicitReturn);
reg.register_late_lint_pass(box methods::Methods);
reg.register_late_lint_pass(box map_clone::MapClone);
reg.register_late_lint_pass(box shadow::Shadow);
reg.register_late_lint_pass(box types::LetUnitValue);
reg.register_late_lint_pass(box types::UnitCmp);
reg.register_late_lint_pass(box loops::Pass);
reg.register_late_lint_pass(box lifetimes::LifetimePass);
reg.register_late_lint_pass(box entry::HashMapLint);
reg.register_late_lint_pass(box ranges::Pass);
reg.register_late_lint_pass(box types::CastPass);
reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
reg.register_late_lint_pass(box matches::MatchPass);
reg.register_late_lint_pass(box loops::Loops);
reg.register_late_lint_pass(box lifetimes::Lifetimes);
reg.register_late_lint_pass(box entry::HashMapPass);
reg.register_late_lint_pass(box ranges::Ranges);
reg.register_late_lint_pass(box types::Casts);
reg.register_late_lint_pass(box types::TypeComplexity::new(conf.type_complexity_threshold));
reg.register_late_lint_pass(box matches::Matches);
reg.register_late_lint_pass(box minmax::MinMaxPass);
reg.register_late_lint_pass(box open_options::NonSensical);
reg.register_late_lint_pass(box zero_div_zero::Pass);
reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
reg.register_late_lint_pass(box needless_update::Pass);
reg.register_late_lint_pass(box open_options::OpenOptions);
reg.register_late_lint_pass(box zero_div_zero::ZeroDiv);
reg.register_late_lint_pass(box mutex_atomic::Mutex);
reg.register_late_lint_pass(box needless_update::NeedlessUpdate);
reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow::default());
reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef);
reg.register_late_lint_pass(box no_effect::Pass);
reg.register_late_lint_pass(box temporary_assignment::Pass);
reg.register_late_lint_pass(box no_effect::NoEffect);
reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignment);
reg.register_late_lint_pass(box transmute::Transmute);
reg.register_late_lint_pass(
box cognitive_complexity::CognitiveComplexity::new(conf.cognitive_complexity_threshold)
);
reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
reg.register_early_lint_pass(box misc_early::MiscEarly);
reg.register_late_lint_pass(box panic_unimplemented::Pass);
reg.register_late_lint_pass(box escape::BoxedLocal{too_large_for_stack: conf.too_large_for_stack});
reg.register_early_lint_pass(box misc_early::MiscEarlyLints);
reg.register_late_lint_pass(box panic_unimplemented::PanicUnimplemented);
reg.register_late_lint_pass(box strings::StringLitAsBytes);
reg.register_late_lint_pass(box derive::Derive);
reg.register_late_lint_pass(box types::CharLitAsU8);
reg.register_late_lint_pass(box vec::Pass);
reg.register_late_lint_pass(box drop_bounds::Pass);
reg.register_late_lint_pass(box drop_forget_ref::Pass);
reg.register_late_lint_pass(box vec::UselessVec);
reg.register_late_lint_pass(box drop_bounds::DropBounds);
reg.register_late_lint_pass(box drop_forget_ref::DropForgetRef);
reg.register_late_lint_pass(box empty_enum::EmptyEnum);
reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
reg.register_late_lint_pass(box regex::Pass::default());
reg.register_late_lint_pass(box regex::Regex::default());
reg.register_late_lint_pass(box copies::CopyAndPaste);
reg.register_late_lint_pass(box copy_iterator::CopyIterator);
reg.register_late_lint_pass(box format::Pass);
reg.register_late_lint_pass(box format::UselessFormat);
reg.register_early_lint_pass(box formatting::Formatting);
reg.register_late_lint_pass(box swap::Swap);
reg.register_early_lint_pass(box if_not_else::IfNotElse);
@ -505,11 +505,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
reg.register_late_lint_pass(box unused_label::UnusedLabel);
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
reg.register_late_lint_pass(box blacklisted_name::BlacklistedName::new(
conf.blacklisted_names.iter().cloned().collect()
));
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold, conf.too_many_lines_threshold));
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
reg.register_early_lint_pass(box doc::DocMarkdown::new(conf.doc_valid_idents.iter().cloned().collect()));
reg.register_late_lint_pass(box neg_multiply::NegMultiply);
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
@ -521,28 +521,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box eval_order_dependence::EvalOrderDependence);
reg.register_late_lint_pass(box missing_doc::MissingDoc::new());
reg.register_late_lint_pass(box missing_inline::MissingInline);
reg.register_late_lint_pass(box ok_if_let::Pass);
reg.register_late_lint_pass(box redundant_pattern_matching::Pass);
reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
reg.register_early_lint_pass(box reference::Pass);
reg.register_early_lint_pass(box reference::DerefPass);
reg.register_late_lint_pass(box ok_if_let::OkIfLet);
reg.register_late_lint_pass(box redundant_pattern_matching::RedundantPatternMatching);
reg.register_late_lint_pass(box partialeq_ne_impl::PartialEqNeImpl);
reg.register_early_lint_pass(box reference::DerefAddrOf);
reg.register_early_lint_pass(box reference::RefInDeref);
reg.register_early_lint_pass(box double_parens::DoubleParens);
reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount);
reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold));
reg.register_late_lint_pass(box explicit_write::Pass);
reg.register_late_lint_pass(box explicit_write::ExplicitWrite);
reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
conf.trivial_copy_size_limit,
&reg.sess.target,
));
reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping);
reg.register_early_lint_pass(box literal_representation::LiteralRepresentation::new(
reg.register_early_lint_pass(box literal_representation::DecimalLiteralRepresentation::new(
conf.literal_representation_threshold
));
reg.register_late_lint_pass(box use_self::UseSelf);
reg.register_late_lint_pass(box bytecount::ByteCount);
reg.register_late_lint_pass(box infinite_iter::Pass);
reg.register_late_lint_pass(box inline_fn_without_body::Pass);
reg.register_late_lint_pass(box infinite_iter::InfiniteIter);
reg.register_late_lint_pass(box inline_fn_without_body::InlineFnWithoutBody);
reg.register_late_lint_pass(box invalid_ref::InvalidRef);
reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
reg.register_late_lint_pass(box types::ImplicitHasher);
@ -550,28 +550,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
reg.register_late_lint_pass(box types::UnitArg);
reg.register_late_lint_pass(box double_comparison::Pass);
reg.register_late_lint_pass(box question_mark::Pass);
reg.register_late_lint_pass(box double_comparison::DoubleComparisons);
reg.register_late_lint_pass(box question_mark::QuestionMark);
reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
reg.register_early_lint_pass(box cargo_common_metadata::Pass);
reg.register_early_lint_pass(box multiple_crate_versions::Pass);
reg.register_early_lint_pass(box wildcard_dependencies::Pass);
reg.register_late_lint_pass(box map_unit_fn::Pass);
reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
reg.register_late_lint_pass(box inherent_impl::Pass::default());
reg.register_early_lint_pass(box cargo_common_metadata::CargoCommonMetadata);
reg.register_early_lint_pass(box multiple_crate_versions::MultipleCrateVersions);
reg.register_early_lint_pass(box wildcard_dependencies::WildcardDependencies);
reg.register_late_lint_pass(box map_unit_fn::MapUnit);
reg.register_late_lint_pass(box infallible_destructuring_match::InfallibleDestructingMatch);
reg.register_late_lint_pass(box inherent_impl::MultipleInherentImpl::default());
reg.register_late_lint_pass(box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd);
reg.register_late_lint_pass(box unwrap::Pass);
reg.register_late_lint_pass(box unwrap::Unwrap);
reg.register_late_lint_pass(box duration_subsec::DurationSubsec);
reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess);
reg.register_late_lint_pass(box indexing_slicing::IndexingSlicing);
reg.register_late_lint_pass(box non_copy_const::NonCopyConst);
reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
reg.register_late_lint_pass(box ptr_offset_with_cast::PtrOffsetWithCast);
reg.register_late_lint_pass(box redundant_clone::RedundantClone);
reg.register_late_lint_pass(box slow_vector_initialization::Pass);
reg.register_late_lint_pass(box slow_vector_initialization::SlowVectorInit);
reg.register_late_lint_pass(box types::RefToMut);
reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants);
reg.register_late_lint_pass(box missing_const_for_fn::MissingConstForFn);
reg.register_late_lint_pass(box transmuting_null::Pass);
reg.register_late_lint_pass(box transmuting_null::TransmutingNull);
reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
arithmetic::FLOAT_ARITHMETIC,

View File

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

View File

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

View File

@ -7,7 +7,7 @@ use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedV
use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::middle::region;
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
// use rustc::middle::region::CodeExtent;
use crate::consts::{constant, Constant};
use crate::utils::usage::mutated_variables;
@ -439,39 +439,28 @@ declare_clippy_lint! {
"variables used within while expression are not mutated in the body"
}
#[derive(Copy, Clone)]
pub struct Pass;
declare_lint_pass!(Loops => [
MANUAL_MEMCPY,
NEEDLESS_RANGE_LOOP,
EXPLICIT_ITER_LOOP,
EXPLICIT_INTO_ITER_LOOP,
ITER_NEXT_LOOP,
FOR_LOOP_OVER_RESULT,
FOR_LOOP_OVER_OPTION,
WHILE_LET_LOOP,
UNUSED_COLLECT,
NEEDLESS_COLLECT,
REVERSE_RANGE_LOOP,
EXPLICIT_COUNTER_LOOP,
EMPTY_LOOP,
WHILE_LET_ON_ITERATOR,
FOR_KV_MAP,
NEVER_LOOP,
MUT_RANGE_BOUND,
WHILE_IMMUTABLE_CONDITION,
]);
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(
MANUAL_MEMCPY,
NEEDLESS_RANGE_LOOP,
EXPLICIT_ITER_LOOP,
EXPLICIT_INTO_ITER_LOOP,
ITER_NEXT_LOOP,
FOR_LOOP_OVER_RESULT,
FOR_LOOP_OVER_OPTION,
WHILE_LET_LOOP,
UNUSED_COLLECT,
NEEDLESS_COLLECT,
REVERSE_RANGE_LOOP,
EXPLICIT_COUNTER_LOOP,
EMPTY_LOOP,
WHILE_LET_ON_ITERATOR,
FOR_KV_MAP,
NEVER_LOOP,
MUT_RANGE_BOUND,
WHILE_IMMUTABLE_CONDITION,
)
}
fn name(&self) -> &'static str {
"Loops"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
#[allow(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// we don't want to check expanded macros

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ use rustc::hir::intravisit::FnKind;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::{ExpnFormat, Span};
@ -232,31 +232,20 @@ declare_clippy_lint! {
"using `==` or `!=` on float constants instead of comparing difference with an epsilon"
}
#[derive(Copy, Clone)]
pub struct Pass;
declare_lint_pass!(MiscLints => [
TOPLEVEL_REF_ARG,
CMP_NAN,
FLOAT_CMP,
CMP_OWNED,
MODULO_ONE,
REDUNDANT_PATTERN,
USED_UNDERSCORE_BINDING,
SHORT_CIRCUIT_STATEMENT,
ZERO_PTR,
FLOAT_CMP_CONST
]);
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(
TOPLEVEL_REF_ARG,
CMP_NAN,
FLOAT_CMP,
CMP_OWNED,
MODULO_ONE,
REDUNDANT_PATTERN,
USED_UNDERSCORE_BINDING,
SHORT_CIRCUIT_STATEMENT,
ZERO_PTR,
FLOAT_CMP_CONST
)
}
fn name(&self) -> &'static str {
"MiscLints"
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
fn check_fn(
&mut self,
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 if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Applicability;
use std::char;
@ -172,27 +172,16 @@ declare_clippy_lint! {
"shadowing a builtin type"
}
#[derive(Copy, Clone)]
pub struct MiscEarly;
impl LintPass for MiscEarly {
fn get_lints(&self) -> LintArray {
lint_array!(
UNNEEDED_FIELD_PATTERN,
DUPLICATE_UNDERSCORE_ARGUMENT,
REDUNDANT_CLOSURE_CALL,
DOUBLE_NEG,
MIXED_CASE_HEX_LITERALS,
UNSEPARATED_LITERAL_SUFFIX,
ZERO_PREFIXED_LITERAL,
BUILTIN_TYPE_SHADOW
)
}
fn name(&self) -> &'static str {
"MiscEarlyLints"
}
}
declare_lint_pass!(MiscEarlyLints => [
UNNEEDED_FIELD_PATTERN,
DUPLICATE_UNDERSCORE_ARGUMENT,
REDUNDANT_CLOSURE_CALL,
DOUBLE_NEG,
MIXED_CASE_HEX_LITERALS,
UNSEPARATED_LITERAL_SUFFIX,
ZERO_PREFIXED_LITERAL,
BUILTIN_TYPE_SHADOW
]);
// Used to find `return` statements or equivalents e.g., `?`
struct ReturnVisitor {
@ -217,7 +206,7 @@ impl<'ast> Visitor<'ast> for ReturnVisitor {
}
}
impl EarlyLintPass for MiscEarly {
impl EarlyLintPass for MiscEarlyLints {
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
for param in &gen.params {
if let GenericParamKind::Type { .. } = param.kind {
@ -398,7 +387,7 @@ impl EarlyLintPass for MiscEarly {
}
}
impl MiscEarly {
impl MiscEarlyLints {
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
if_chain! {
if let LitKind::Int(value, ..) = lit.node;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

@ -9,7 +9,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::ty::adjustment::Adjust;
use rustc::ty::{Ty, TypeFlags};
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use rustc_typeck::hir_ty_to_ty;
use syntax_pos::{Span, DUMMY_SP};
@ -143,17 +143,7 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: S
});
}
pub struct NonCopyConst;
impl LintPass for NonCopyConst {
fn get_lints(&self) -> LintArray {
lint_array!(DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST)
}
fn name(&self) -> &'static str {
"NonCopyConst"
}
}
declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item) {

View File

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

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
use crate::utils;
use rustc::{declare_tool_lint, hir, lint, lint_array};
use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use std::fmt;
@ -39,21 +41,10 @@ declare_clippy_lint! {
"unneeded pointer offset cast"
}
#[derive(Copy, Clone, Debug)]
pub struct Pass;
declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]);
impl lint::LintPass for Pass {
fn get_lints(&self) -> lint::LintArray {
lint_array!(PTR_OFFSET_WITH_CAST)
}
fn name(&self) -> &'static str {
"PtrOffsetWithCast"
}
}
impl<'a, 'tcx> lint::LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &lint::LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// Check if the expressions is a ptr.offset or ptr.wrapping_offset method call
let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) {
Some(call_arg) => call_arg,
@ -84,11 +75,8 @@ impl<'a, 'tcx> lint::LateLintPass<'a, 'tcx> for Pass {
}
// If the given expression is a cast from a usize, return the lhs of the cast
fn expr_as_cast_from_usize<'a, 'tcx>(
cx: &lint::LateContext<'a, 'tcx>,
expr: &'tcx hir::Expr,
) -> Option<&'tcx hir::Expr> {
if let hir::ExprKind::Cast(ref cast_lhs_expr, _) = expr.node {
fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<&'tcx Expr> {
if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.node {
if is_expr_ty_usize(cx, &cast_lhs_expr) {
return Some(cast_lhs_expr);
}
@ -99,10 +87,10 @@ fn expr_as_cast_from_usize<'a, 'tcx>(
// If the given expression is a ptr::offset or ptr::wrapping_offset method call, return the
// receiver, the arg of the method call, and the method.
fn expr_as_ptr_offset_call<'a, 'tcx>(
cx: &lint::LateContext<'a, 'tcx>,
expr: &'tcx hir::Expr,
) -> Option<(&'tcx hir::Expr, &'tcx hir::Expr, Method)> {
if let hir::ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node {
cx: &LateContext<'a, 'tcx>,
expr: &'tcx Expr,
) -> Option<(&'tcx Expr, &'tcx Expr, Method)> {
if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node {
if is_expr_ty_raw_ptr(cx, &args[0]) {
if path_segment.ident.name == "offset" {
return Some((&args[0], &args[1], Method::Offset));
@ -116,20 +104,20 @@ fn expr_as_ptr_offset_call<'a, 'tcx>(
}
// Is the type of the expression a usize?
fn is_expr_ty_usize<'a, 'tcx>(cx: &lint::LateContext<'a, 'tcx>, expr: &hir::Expr) -> bool {
fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool {
cx.tables.expr_ty(expr) == cx.tcx.types.usize
}
// Is the type of the expression a raw pointer?
fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &lint::LateContext<'a, 'tcx>, expr: &hir::Expr) -> bool {
fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool {
cx.tables.expr_ty(expr).is_unsafe_ptr()
}
fn build_suggestion<'a, 'tcx>(
cx: &lint::LateContext<'a, 'tcx>,
cx: &LateContext<'a, 'tcx>,
method: Method,
receiver_expr: &hir::Expr,
cast_lhs_expr: &hir::Expr,
receiver_expr: &Expr,
cast_lhs_expr: &Expr,
) -> Option<String> {
let receiver = utils::snippet_opt(cx, receiver_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::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use syntax::ptr::P;
@ -34,20 +34,9 @@ declare_clippy_lint! {
"checks for expressions that could be replaced by the question mark operator"
}
#[derive(Copy, Clone)]
pub struct Pass;
declare_lint_pass!(QuestionMark => [QUESTION_MARK]);
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(QUESTION_MARK)
}
fn name(&self) -> &'static str {
"QuestionMark"
}
}
impl Pass {
impl QuestionMark {
/// Checks if the given expression on the given context matches the following structure:
///
/// ```ignore
@ -165,7 +154,7 @@ impl Pass {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for QuestionMark {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
Self::check_is_none_and_early_return_none(cx, expr);
}

View File

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

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