move lint documentation into macro invocations

This commit is contained in:
Andy Russell
2019-03-05 11:50:33 -05:00
parent a8f61e70a8
commit fe96ffeac9
132 changed files with 5405 additions and 5390 deletions

View File

@@ -12,8 +12,9 @@ use walkdir::WalkDir;
lazy_static! {
static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new(
r#"(?x)
declare_clippy_lint!\s*[\{(]\s*
pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
declare_clippy_lint!\s*[\{(]
(?:\s+///.*)*
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
(?P<cat>[a-z_]+)\s*,\s*
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
"#
@@ -22,7 +23,8 @@ lazy_static! {
static ref DEC_DEPRECATED_LINT_RE: Regex = Regex::new(
r#"(?x)
declare_deprecated_lint!\s*[{(]\s*
pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
(?:\s+///.*)*
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
"#
)

View File

@@ -6,6 +6,7 @@ use std::f64::consts as f64;
use syntax::ast::{FloatTy, Lit, LitKind};
use syntax::symbol;
declare_clippy_lint! {
/// **What it does:** Checks for floating point literals that approximate
/// constants which are defined in
/// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
@@ -27,7 +28,6 @@ use syntax::symbol;
/// ```rust
/// let x = 3.14;
/// ```
declare_clippy_lint! {
pub APPROX_CONSTANT,
correctness,
"the approximate of a known float constant (in `std::fXX::consts`)"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for plain integer arithmetic.
///
/// **Why is this bad?** This is only checked against overflow in debug builds.
@@ -17,12 +18,12 @@ use syntax::source_map::Span;
/// ```rust
/// a + 1
/// ```
declare_clippy_lint! {
pub INTEGER_ARITHMETIC,
restriction,
"any integer arithmetic statement"
}
declare_clippy_lint! {
/// **What it does:** Checks for float arithmetic.
///
/// **Why is this bad?** For some embedded systems or kernel development, it
@@ -34,7 +35,6 @@ declare_clippy_lint! {
/// ```rust
/// a + 1.0
/// ```
declare_clippy_lint! {
pub FLOAT_ARITHMETIC,
restriction,
"any floating-point arithmetic statement"

View File

@@ -6,6 +6,7 @@ use crate::syntax::ast::LitKind;
use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
use if_chain::if_chain;
declare_clippy_lint! {
/// **What it does:** Check to call assert!(true/false)
///
/// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a
@@ -22,7 +23,6 @@ use if_chain::if_chain;
/// const B: bool = false;
/// assert!(B)
/// ```
declare_clippy_lint! {
pub ASSERTIONS_ON_CONSTANTS,
style,
"assert!(true/false) will be optimized out by the compiler/should probably be replaced by a panic!() or unreachable!()"

View File

@@ -7,6 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
/// patterns.
///
@@ -21,12 +22,12 @@ use rustc_errors::Applicability;
/// ...
/// a = a + b;
/// ```
declare_clippy_lint! {
pub ASSIGN_OP_PATTERN,
style,
"assigning the result of an operation on a variable to that same variable"
}
declare_clippy_lint! {
/// **What it does:** Checks for `a op= a op b` or `a op= b op a` patterns.
///
/// **Why is this bad?** Most likely these are bugs where one meant to write `a
@@ -43,7 +44,6 @@ declare_clippy_lint! {
/// ...
/// a += a + b;
/// ```
declare_clippy_lint! {
pub MISREFACTORED_ASSIGN_OP,
complexity,
"having a variable on both sides of an assign op"

View File

@@ -17,6 +17,7 @@ use semver::Version;
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
/// unless the annotated function is empty or simply panics.
///
@@ -37,12 +38,12 @@ use syntax::source_map::Span;
/// #[inline(always)]
/// fn not_quite_hot_code(..) { ... }
/// ```
declare_clippy_lint! {
pub INLINE_ALWAYS,
pedantic,
"use of `#[inline(always)]`"
}
declare_clippy_lint! {
/// **What it does:** Checks for `extern crate` and `use` items annotated with
/// lint attributes.
///
@@ -70,12 +71,12 @@ declare_clippy_lint! {
/// #[macro_use]
/// extern crate baz;
/// ```
declare_clippy_lint! {
pub USELESS_ATTRIBUTE,
correctness,
"use of lint attributes on `extern crate` items"
}
declare_clippy_lint! {
/// **What it does:** Checks for `#[deprecated]` annotations with a `since`
/// field that is not a valid semantic version.
///
@@ -89,12 +90,12 @@ declare_clippy_lint! {
/// #[deprecated(since = "forever")]
/// fn something_else(..) { ... }
/// ```
declare_clippy_lint! {
pub DEPRECATED_SEMVER,
correctness,
"use of `#[deprecated(since = \"x\")]` where x is not semver"
}
declare_clippy_lint! {
/// **What it does:** Checks for empty lines after outer attributes
///
/// **Why is this bad?**
@@ -124,12 +125,12 @@ declare_clippy_lint! {
/// #[inline(always)]
/// fn this_is_fine_too(..) { ... }
/// ```
declare_clippy_lint! {
pub EMPTY_LINE_AFTER_OUTER_ATTR,
nursery,
"empty line after outer attribute"
}
declare_clippy_lint! {
/// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy
/// lints and if those lints exist in clippy. If there is a uppercase letter in the lint name
/// (not the tool name) and a lowercase version of this lint exists, it will suggest to lowercase
@@ -151,12 +152,12 @@ declare_clippy_lint! {
/// #![warn(if_not_else)]
/// #![deny(clippy::all)]
/// ```
declare_clippy_lint! {
pub UNKNOWN_CLIPPY_LINTS,
style,
"unknown_lints for scoped Clippy lints"
}
declare_clippy_lint! {
/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
/// with `#[rustfmt::skip]`.
///
@@ -180,7 +181,6 @@ declare_clippy_lint! {
/// #[rustfmt::skip]
/// fn main() { }
/// ```
declare_clippy_lint! {
pub DEPRECATED_CFG_ATTR,
complexity,
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"

View File

@@ -9,6 +9,7 @@ use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for incompatible bit masks in comparisons.
///
/// The formula for detecting if an expression of the type `_ <bit_op> m
@@ -39,12 +40,12 @@ use syntax::source_map::Span;
/// ```rust
/// if (x & 1 == 2) { … }
/// ```
declare_clippy_lint! {
pub BAD_BIT_MASK,
correctness,
"expressions of the form `_ & mask == select` that will only ever return `true` or `false`"
}
declare_clippy_lint! {
/// **What it does:** Checks for bit masks in comparisons which can be removed
/// without changing the outcome. The basic structure can be seen in the
/// following table:
@@ -67,12 +68,12 @@ declare_clippy_lint! {
/// ```rust
/// if (x | 1 > 3) { … }
/// ```
declare_clippy_lint! {
pub INEFFECTIVE_BIT_MASK,
correctness,
"expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`"
}
declare_clippy_lint! {
/// **What it does:** Checks for bit masks that can be replaced by a call
/// to `trailing_zeros`
///
@@ -85,7 +86,6 @@ declare_clippy_lint! {
/// ```rust
/// x & 0x1111 == 0
/// ```
declare_clippy_lint! {
pub VERBOSE_BIT_MASK,
style,
"expressions where a bit mask is less readable than the corresponding method call"

View File

@@ -4,6 +4,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet;
declare_clippy_lint! {
/// **What it does:** Checks for usage of blacklisted names for variables, such
/// as `foo`.
///
@@ -16,7 +17,6 @@ use rustc_data_structures::fx::FxHashSet;
/// ```rust
/// let foo = 3.14;
/// ```
declare_clippy_lint! {
pub BLACKLISTED_NAME,
style,
"usage of a blacklisted/placeholder name"

View File

@@ -5,6 +5,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for `if` conditions that use blocks to contain an
/// expression.
///
@@ -17,12 +18,12 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// if { true } ..
/// ```
declare_clippy_lint! {
pub BLOCK_IN_IF_CONDITION_EXPR,
style,
"braces that can be eliminated in conditions, e.g. `if { true } ...`"
}
declare_clippy_lint! {
/// **What it does:** Checks for `if` conditions that use blocks containing
/// statements, or conditions that use closures with blocks.
///
@@ -36,7 +37,6 @@ declare_clippy_lint! {
/// // or
/// if somefunc(|x| { x == 47 }) ..
/// ```
declare_clippy_lint! {
pub BLOCK_IN_IF_CONDITION_STMT,
style,
"complex blocks in conditions, e.g. `if { let x = true; x } ...`"

View File

@@ -10,6 +10,7 @@ use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
declare_clippy_lint! {
/// **What it does:** Checks for boolean expressions that can be written more
/// concisely.
///
@@ -24,12 +25,12 @@ use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
/// if a && true // should be: if a
/// if !(a == b) // should be: if a != b
/// ```
declare_clippy_lint! {
pub NONMINIMAL_BOOL,
complexity,
"boolean expressions that can be written more concisely"
}
declare_clippy_lint! {
/// **What it does:** Checks for boolean expressions that contain terminals that
/// can be eliminated.
///
@@ -42,7 +43,6 @@ declare_clippy_lint! {
/// if a && b || a { ... }
/// ```
/// The `b` is unnecessary, the expression is equivalent to `if a`.
declare_clippy_lint! {
pub LOGIC_BUG,
correctness,
"boolean expressions that contain terminals which can be eliminated"

View File

@@ -10,6 +10,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast::{Name, UintTy};
declare_clippy_lint! {
/// **What it does:** Checks for naive byte counts
///
/// **Why is this bad?** The [`bytecount`](https://crates.io/crates/bytecount)
@@ -25,7 +26,6 @@ use syntax::ast::{Name, UintTy};
/// ```rust
/// &my_data.filter(|&x| x == 0u8).count() // use bytecount::count instead
/// ```
declare_clippy_lint! {
pub NAIVE_BYTECOUNT,
perf,
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"

View File

@@ -7,6 +7,7 @@ use syntax::{ast::*, source_map::DUMMY_SP};
use cargo_metadata;
declare_clippy_lint! {
/// **What it does:** Checks to see if all common metadata is defined in
/// `Cargo.toml`. See: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata
///
@@ -28,7 +29,6 @@ use cargo_metadata;
/// keywords = ["clippy", "lint", "plugin"]
/// categories = ["development-tools", "development-tools::cargo-plugins"]
/// ```
declare_clippy_lint! {
pub CARGO_COMMON_METADATA,
cargo,
"common metadata is defined in `Cargo.toml`"

View File

@@ -21,6 +21,7 @@ use crate::utils::sugg::Sugg;
use crate::utils::{in_macro, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for nested `if` statements which can be collapsed
/// by `&&`-combining their conditions and for `else { if ... }` expressions
/// that
@@ -65,7 +66,6 @@ use rustc_errors::Applicability;
/// …
/// }
/// ```
declare_clippy_lint! {
pub COLLAPSIBLE_IF,
style,
"`if`s that can be collapsed (e.g. `if x { if y { ... } }` and `else { if x { ... } }`)"

View File

@@ -4,6 +4,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast::*;
declare_clippy_lint! {
/// **What it does:** Checks for constants with an explicit `'static` lifetime.
///
/// **Why is this bad?** Adding `'static` to every reference can create very
@@ -20,7 +21,6 @@ use syntax::ast::*;
/// ```rust
/// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...]
/// ```
declare_clippy_lint! {
pub CONST_STATIC_LIFETIME,
style,
"Using explicit `'static` lifetime for constants when elision rules would allow omitting them."

View File

@@ -10,6 +10,7 @@ use std::collections::hash_map::Entry;
use std::hash::BuildHasherDefault;
use syntax::symbol::LocalInternedString;
declare_clippy_lint! {
/// **What it does:** Checks for consecutive `if`s with the same condition.
///
/// **Why is this bad?** This is probably a copy & paste error.
@@ -35,12 +36,12 @@ use syntax::symbol::LocalInternedString;
/// …
/// }
/// ```
declare_clippy_lint! {
pub IFS_SAME_COND,
correctness,
"consecutive `ifs` with the same condition"
}
declare_clippy_lint! {
/// **What it does:** Checks for `if/else` with the same body as the *then* part
/// and the *else* part.
///
@@ -56,12 +57,12 @@ declare_clippy_lint! {
/// 42
/// };
/// ```
declare_clippy_lint! {
pub IF_SAME_THEN_ELSE,
correctness,
"if with the same *then* and *else* blocks"
}
declare_clippy_lint! {
/// **What it does:** Checks for `match` with identical arm bodies.
///
/// **Why is this bad?** This is probably a copy & paste error. If arm bodies
@@ -97,7 +98,6 @@ declare_clippy_lint! {
/// Quz => quz(),
/// }
/// ```
declare_clippy_lint! {
pub MATCH_SAME_ARMS,
pedantic,
"`match` with identical arm bodies"

View File

@@ -3,6 +3,7 @@ use rustc::hir::{Item, ItemKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for types that implement `Copy` as well as
/// `Iterator`.
///
@@ -23,7 +24,6 @@ use rustc::{declare_tool_lint, lint_array};
/// let a: Vec<_> = my_iterator.take(1).collect();
/// let b: Vec<_> = my_iterator.collect();
/// ```
declare_clippy_lint! {
pub COPY_ITERATOR,
pedantic,
"implementing `Iterator` on a `Copy` type"

View File

@@ -11,6 +11,7 @@ use syntax::source_map::Span;
use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
declare_clippy_lint! {
/// **What it does:** Checks for methods with high cyclomatic complexity.
///
/// **Why is this bad?** Methods of high cyclomatic complexity tend to be badly
@@ -20,7 +21,6 @@ use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint,
/// complexity.
///
/// **Example:** No. You'll see it when you get the warning.
declare_clippy_lint! {
pub CYCLOMATIC_COMPLEXITY,
complexity,
"functions that should be split up into multiple functions"

View File

@@ -6,6 +6,7 @@ use syntax::ast;
use syntax::source_map::Span;
use syntax::tokenstream::TokenStream;
declare_clippy_lint! {
/// **What it does:** Checks for usage of dbg!() macro.
///
/// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It
@@ -21,7 +22,6 @@ use syntax::tokenstream::TokenStream;
/// // Good
/// true
/// ```
declare_clippy_lint! {
pub DBG_MACRO,
restriction,
"`dbg!` macro is intended as a debugging tool"

View File

@@ -7,6 +7,7 @@ use rustc_errors::Applicability;
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
declare_clippy_lint! {
/// **What it does:** Checks for literal calls to `Default::default()`.
///
/// **Why is this bad?** It's more clear to the reader to use the name of the type whose default is
@@ -22,7 +23,6 @@ use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_
/// // Good
/// let s = String::default();
/// ```
declare_clippy_lint! {
pub DEFAULT_TRAIT_ACCESS,
pedantic,
"checks for literal calls to Default::default()"

View File

@@ -7,6 +7,7 @@ use rustc::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
/// explicitly or vice versa.
///
@@ -30,12 +31,12 @@ use syntax::source_map::Span;
/// ...
/// }
/// ```
declare_clippy_lint! {
pub DERIVE_HASH_XOR_EQ,
correctness,
"deriving `Hash` but implementing `PartialEq` explicitly"
}
declare_clippy_lint! {
/// **What it does:** Checks for explicit `Clone` implementations for `Copy`
/// types.
///
@@ -56,7 +57,6 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub EXPL_IMPL_CLONE_ON_COPY,
pedantic,
"implementing `Clone` explicitly on `Copy` types"

View File

@@ -9,6 +9,7 @@ use syntax::source_map::{BytePos, Span};
use syntax_pos::Pos;
use url::Url;
declare_clippy_lint! {
/// **What it does:** Checks for the presence of `_`, `::` or camel-case words
/// outside ticks in documentation.
///
@@ -27,7 +28,6 @@ use url::Url;
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
/// fn doit(foo_bar) { .. }
/// ```
declare_clippy_lint! {
pub DOC_MARKDOWN,
pedantic,
"presence of `_`, `::` or camel-case outside backticks in documentation"

View File

@@ -8,6 +8,7 @@ use syntax::source_map::Span;
use crate::utils::{snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
declare_clippy_lint! {
/// **What it does:** Checks for double comparions that could be simplified to a single expression.
///
///
@@ -25,7 +26,6 @@ use crate::utils::{snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
/// ```rust
/// x <= y
/// ```
declare_clippy_lint! {
pub DOUBLE_COMPARISONS,
complexity,
"unnecessary double comparisons that can be simplified"

View File

@@ -3,6 +3,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::*;
declare_clippy_lint! {
/// **What it does:** Checks for unnecessary double parentheses.
///
/// **Why is this bad?** This makes code harder to read and might indicate a
@@ -16,7 +17,6 @@ use syntax::ast::*;
/// foo((0))
/// ((1, 2))
/// ```
declare_clippy_lint! {
pub DOUBLE_PARENS,
complexity,
"Warn on unnecessary double parentheses"

View File

@@ -4,6 +4,7 @@ use rustc::hir::*;
use rustc::lint::{LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for generics with `std::ops::Drop` as bounds.
///
/// **Why is this bad?** `Drop` bounds do not really accomplish anything.
@@ -26,7 +27,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// fn foo<T: Drop>() {}
/// ```
declare_clippy_lint! {
pub DROP_BOUNDS,
correctness,
"Bounds of the form `T: Drop` are useless"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::drop` with a reference
/// instead of an owned value.
///
@@ -22,12 +23,12 @@ use rustc::{declare_tool_lint, lint_array};
/// // still locked
/// operation_that_requires_mutex_to_be_unlocked();
/// ```
declare_clippy_lint! {
pub DROP_REF,
correctness,
"calls to `std::mem::drop` with a reference instead of an owned value"
}
declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::forget` with a reference
/// instead of an owned value.
///
@@ -43,12 +44,12 @@ declare_clippy_lint! {
/// let x = Box::new(1);
/// std::mem::forget(&x) // Should have been forget(x), x will still be dropped
/// ```
declare_clippy_lint! {
pub FORGET_REF,
correctness,
"calls to `std::mem::forget` with a reference instead of an owned value"
}
declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::drop` with a value
/// that derives the Copy trait
///
@@ -64,12 +65,12 @@ declare_clippy_lint! {
/// std::mem::drop(x) // A copy of x is passed to the function, leaving the
/// // original unaffected
/// ```
declare_clippy_lint! {
pub DROP_COPY,
correctness,
"calls to `std::mem::drop` with a value that implements Copy"
}
declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::forget` with a value that
/// derives the Copy trait
///
@@ -91,7 +92,6 @@ declare_clippy_lint! {
/// std::mem::forget(x) // A copy of x is passed to the function, leaving the
/// // original unaffected
/// ```
declare_clippy_lint! {
pub FORGET_COPY,
correctness,
"calls to `std::mem::forget` with a value that implements Copy"

View File

@@ -9,6 +9,7 @@ use crate::consts::{constant, Constant};
use crate::utils::paths;
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg, walk_ptrs_ty};
declare_clippy_lint! {
/// **What it does:** Checks for calculation of subsecond microseconds or milliseconds
/// from other `Duration` methods.
///
@@ -23,7 +24,6 @@ use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg, w
/// let _micros = dur.subsec_nanos() / 1_000;
/// let _millis = dur.subsec_nanos() / 1_000_000;
/// ```
declare_clippy_lint! {
pub DURATION_SUBSEC,
complexity,
"checks for calculation of subsecond microseconds or milliseconds"

View File

@@ -6,6 +6,7 @@ use syntax::ast::*;
use crate::utils::span_help_and_lint;
declare_clippy_lint! {
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
/// but without a final `else` branch.
///
@@ -33,7 +34,6 @@ use crate::utils::span_help_and_lint;
/// // we don't care about zero
/// }
/// ```
declare_clippy_lint! {
pub ELSE_IF_WITHOUT_ELSE,
restriction,
"if expression with an `else if`, but without a final `else` branch"

View File

@@ -5,6 +5,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for `enum`s with no variants.
///
/// **Why is this bad?** Enum's with no variants should be replaced with `!`,
@@ -17,7 +18,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// enum Test {}
/// ```
declare_clippy_lint! {
pub EMPTY_ENUM,
pedantic,
"enum with no variants"

View File

@@ -8,6 +8,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap`
/// or `BTreeMap`.
///
@@ -31,7 +32,6 @@ use syntax::source_map::Span;
/// ```rust
/// m.entry(k).or_insert(v);
/// ```
declare_clippy_lint! {
pub MAP_ENTRY,
perf,
"use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`"

View File

@@ -12,6 +12,7 @@ use rustc::ty::util::IntTypeExt;
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::{IntTy, UintTy};
declare_clippy_lint! {
/// **What it does:** Checks for C-like enumerations that are
/// `repr(isize/usize)` and have values that don't fit into an `i32`.
///
@@ -28,7 +29,6 @@ use syntax::ast::{IntTy, UintTy};
/// Y = 0,
/// }
/// ```
declare_clippy_lint! {
pub ENUM_CLIKE_UNPORTABLE_VARIANT,
correctness,
"C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`"

View File

@@ -7,6 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for `use Enum::*`.
///
/// **Why is this bad?** It is usually better style to use the prefixed name of
@@ -19,7 +20,6 @@ use syntax::source_map::Span;
/// ```rust
/// use std::cmp::Ordering::*;
/// ```
declare_clippy_lint! {
pub ENUM_GLOB_USE,
pedantic,
"use items that import all variants of an enum"

View File

@@ -8,6 +8,7 @@ use syntax::ast::*;
use syntax::source_map::Span;
use syntax::symbol::{InternedString, LocalInternedString};
declare_clippy_lint! {
/// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters.
///
@@ -24,12 +25,12 @@ use syntax::symbol::{InternedString, LocalInternedString};
/// BattenbergCake,
/// }
/// ```
declare_clippy_lint! {
pub ENUM_VARIANT_NAMES,
style,
"enums where all variants share a prefix/postfix"
}
declare_clippy_lint! {
/// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters.
///
@@ -46,12 +47,12 @@ declare_clippy_lint! {
/// BattenbergCake,
/// }
/// ```
declare_clippy_lint! {
pub PUB_ENUM_VARIANT_NAMES,
pedantic,
"enums where all variants share a prefix/postfix"
}
declare_clippy_lint! {
/// **What it does:** Detects type names that are prefixed or suffixed by the
/// containing module's name.
///
@@ -65,12 +66,12 @@ declare_clippy_lint! {
/// struct BlackForestCake;
/// }
/// ```
declare_clippy_lint! {
pub MODULE_NAME_REPETITIONS,
pedantic,
"type names prefixed/postfixed with their containing module's name"
}
declare_clippy_lint! {
/// **What it does:** Checks for modules that have the same name as their
/// parent module
///
@@ -95,7 +96,6 @@ declare_clippy_lint! {
/// ...
/// }
/// ```
declare_clippy_lint! {
pub MODULE_INCEPTION,
style,
"modules that have the same name as their parent module"

View File

@@ -6,6 +6,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for equal operands to comparison, logical and
/// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`,
/// `||`, `&`, `|`, `^`, `-` and `/`).
@@ -21,12 +22,12 @@ use rustc_errors::Applicability;
/// ```rust
/// x + 1 == x + 1
/// ```
declare_clippy_lint! {
pub EQ_OP,
correctness,
"equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)"
}
declare_clippy_lint! {
/// **What it does:** Checks for arguments to `==` which have their address
/// taken to satisfy a bound
/// and suggests to dereference the other argument instead
@@ -39,7 +40,6 @@ declare_clippy_lint! {
/// ```rust
/// &x == y
/// ```
declare_clippy_lint! {
pub OP_REF,
style,
"taking a reference to satisfy the type constraints on `==`"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for erasing operations, e.g. `x * 0`.
///
/// **Why is this bad?** The whole expression can be replaced by zero.
@@ -19,7 +20,6 @@ use syntax::source_map::Span;
/// 0 * x;
/// x & 0
/// ```
declare_clippy_lint! {
pub ERASING_OP,
correctness,
"using erasing operations, e.g. `x * 0` or `y & 0`"

View File

@@ -14,6 +14,7 @@ pub struct Pass {
pub too_large_for_stack: u64,
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `Box<T>` where an unboxed `T` would
/// work fine.
///
@@ -31,7 +32,6 @@ pub struct Pass {
/// println!("{}", *x);
/// }
/// ```
declare_clippy_lint! {
pub BOXED_LOCAL,
perf,
"using `Box<T>` where unnecessary"

View File

@@ -8,6 +8,7 @@ use rustc_errors::Applicability;
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
/// get adjusted are ignored.
@@ -27,7 +28,6 @@ pub struct EtaPass;
/// ```
/// where `foo(_)` is a plain function that takes the exact argument type of
/// `x`.
declare_clippy_lint! {
pub REDUNDANT_CLOSURE,
style,
"redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)"

View File

@@ -7,6 +7,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
declare_clippy_lint! {
/// **What it does:** Checks for a read and a write to the same variable where
/// whether the read occurs before or after the write depends on the evaluation
/// order of sub-expressions.
@@ -26,12 +27,12 @@ use syntax::ast;
/// } + x;
/// // Unclear whether a is 1 or 2.
/// ```
declare_clippy_lint! {
pub EVAL_ORDER_DEPENDENCE,
complexity,
"whether a variable read occurs before a write depends on sub-expression evaluation order"
}
declare_clippy_lint! {
/// **What it does:** Checks for diverging calls that are not match arms or
/// statements.
///
@@ -48,7 +49,6 @@ declare_clippy_lint! {
/// let x = (a, b, c, panic!());
/// // can simply be replaced by `panic!()`
/// ```
declare_clippy_lint! {
pub DIVERGING_SUB_EXPRESSION,
complexity,
"whether an expression contains a diverging sub expression"

View File

@@ -11,6 +11,7 @@ use std::fmt;
use syntax::ast::*;
use syntax_pos::symbol::Symbol;
declare_clippy_lint! {
/// **What it does:** Checks for float literals with a precision greater
/// than that supported by the underlying type
///
@@ -29,7 +30,6 @@ use syntax_pos::symbol::Symbol;
/// let v: f64 = 0.123_456_789_9;
/// println!("{}", v); // 0.123_456_789_9
/// ```
declare_clippy_lint! {
pub EXCESSIVE_PRECISION,
style,
"excessive precision for float literal"

View File

@@ -6,6 +6,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast::LitKind;
declare_clippy_lint! {
/// **What it does:** Checks for usage of `write!()` / `writeln()!` which can be
/// replaced with `(e)print!()` / `(e)println!()`
///
@@ -18,7 +19,6 @@ use syntax::ast::LitKind;
/// // this would be clearer as `eprintln!("foo: {:?}", bar);`
/// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap();
/// ```
declare_clippy_lint! {
pub EXPLICIT_WRITE,
complexity,
"using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work"

View File

@@ -7,6 +7,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()`
///
/// **Why is this bad?** `TryFrom` should be used if there's a possibility of failure.
@@ -22,7 +23,6 @@ use syntax_pos::Span;
/// }
/// }
/// ```
declare_clippy_lint! {
pub FALLIBLE_IMPL_FROM,
nursery,
"Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`"

View File

@@ -12,6 +12,7 @@ use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for the use of `format!("string literal with no
/// argument")` and `format!("{}", foo)` where `foo` is a string.
///
@@ -28,7 +29,6 @@ use syntax::source_map::Span;
/// format!("foo")
/// format!("{}", foo)
/// ```
declare_clippy_lint! {
pub USELESS_FORMAT,
complexity,
"useless use of `format!`"

View File

@@ -4,6 +4,7 @@ use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
use syntax::ptr::P;
declare_clippy_lint! {
/// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-`
/// operators.
///
@@ -16,12 +17,12 @@ use syntax::ptr::P;
/// ```rust,ignore
/// a =- 42; // confusing, should it be `a -= 42` or `a = -42`?
/// ```
declare_clippy_lint! {
pub SUSPICIOUS_ASSIGNMENT_FORMATTING,
style,
"suspicious formatting of `*=`, `-=` or `!=`"
}
declare_clippy_lint! {
/// **What it does:** Checks for formatting of `else`. It lints if the `else`
/// is followed immediately by a newline or the `else` seems to be missing.
///
@@ -52,12 +53,12 @@ declare_clippy_lint! {
/// if bar { // this is the `else` block of the previous `if`, but should it be?
/// }
/// ```
declare_clippy_lint! {
pub SUSPICIOUS_ELSE_FORMATTING,
style,
"suspicious formatting of `else`"
}
declare_clippy_lint! {
/// **What it does:** Checks for possible missing comma in an array. It lints if
/// an array element is a binary operator expression and it lies on two lines.
///
@@ -72,7 +73,6 @@ declare_clippy_lint! {
/// -4, -5, -6
/// ];
/// ```
declare_clippy_lint! {
pub POSSIBLE_MISSING_COMMA,
correctness,
"possible missing comma in array"

View File

@@ -11,6 +11,7 @@ use rustc_target::spec::abi::Abi;
use syntax::ast;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for functions with too many parameters.
///
/// **Why is this bad?** Functions with lots of parameters are considered bad
@@ -25,12 +26,12 @@ use syntax::source_map::Span;
/// ..
/// }
/// ```
declare_clippy_lint! {
pub TOO_MANY_ARGUMENTS,
complexity,
"functions with too many arguments"
}
declare_clippy_lint! {
/// **What it does:** Checks for functions with a large amount of lines.
///
/// **Why is this bad?** Functions with a lot of lines are harder to understand
@@ -48,12 +49,12 @@ declare_clippy_lint! {
/// println!("");
/// }
/// ```
declare_clippy_lint! {
pub TOO_MANY_LINES,
pedantic,
"functions with too many lines"
}
declare_clippy_lint! {
/// **What it does:** Checks for public functions that dereferences raw pointer
/// arguments but are not marked unsafe.
///
@@ -76,7 +77,6 @@ declare_clippy_lint! {
/// println!("{}", unsafe { *x });
/// }
/// ```
declare_clippy_lint! {
pub NOT_UNSAFE_PTR_ARG_DEREF,
correctness,
"public functions dereferencing raw pointer arguments but not marked `unsafe`"

View File

@@ -7,6 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions.
///
/// **Why is this bad?** Redundant code.
@@ -18,7 +19,6 @@ use rustc_errors::Applicability;
/// // format!() returns a `String`
/// let s: String = format!("hello").into();
/// ```
declare_clippy_lint! {
pub IDENTITY_CONVERSION,
complexity,
"using always-identical `Into`/`From`/`IntoIter` conversions"

View File

@@ -6,6 +6,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for identity operations, e.g. `x + 0`.
///
/// **Why is this bad?** This code can be removed without changing the
@@ -17,7 +18,6 @@ use syntax::source_map::Span;
/// ```rust
/// x / 1 + 0 * 1 - 0 | 0
/// ```
declare_clippy_lint! {
pub IDENTITY_OP,
complexity,
"using identity operations, e.g. `x + 0` or `y / 1`"

View File

@@ -7,6 +7,7 @@ use syntax::ast::*;
use crate::utils::span_help_and_lint;
declare_clippy_lint! {
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
/// else branch.
///
@@ -32,7 +33,6 @@ use crate::utils::span_help_and_lint;
/// a()
/// }
/// ```
declare_clippy_lint! {
pub IF_NOT_ELSE,
pedantic,
"`if` branches that could be swapped so no negation operation is necessary on the condition"

View File

@@ -5,6 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for missing return statements at the end of a block.
///
/// **Why is this bad?** Actually omitting the return keyword is idiomatic Rust code. Programmers
@@ -27,7 +28,6 @@ use syntax::source_map::Span;
/// return x;
/// }
/// ```
declare_clippy_lint! {
pub IMPLICIT_RETURN,
restriction,
"use a return statement like `return expr` instead of an expression"

View File

@@ -10,6 +10,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::RangeLimits;
declare_clippy_lint! {
/// **What it does:** Checks for out of bounds array indexing with a constant
/// index.
///
@@ -29,12 +30,12 @@ use syntax::ast::RangeLimits;
/// x[0];
/// x[3];
/// ```
declare_clippy_lint! {
pub OUT_OF_BOUNDS_INDEXING,
correctness,
"out of bounds constant indexing"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of indexing or slicing. Arrays are special cased, this lint
/// does report on arrays if we can tell that slicing operations are in bounds and does not
/// lint on constant `usize` indexing on arrays because that is handled by rustc's `const_err` lint.
@@ -78,7 +79,6 @@ declare_clippy_lint! {
/// y.get(10..);
/// y.get(..100);
/// ```
declare_clippy_lint! {
pub INDEXING_SLICING,
restriction,
"indexing/slicing usage"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for matches being used to destructure a single-variant enum
/// or tuple struct where a `let` will suffice.
///
@@ -34,7 +35,6 @@ use rustc_errors::Applicability;
/// let wrapper = Wrapper::Data(42);
/// let Wrapper::Data(data) = wrapper;
/// ```
declare_clippy_lint! {
pub INFALLIBLE_DESTRUCTURING_MATCH,
style,
"a match statement with a single infallible arm instead of a `let`"

View File

@@ -3,6 +3,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for iteration that is guaranteed to be infinite.
///
/// **Why is this bad?** While there may be places where this is acceptable
@@ -14,12 +15,12 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// repeat(1_u8).iter().collect::<Vec<_>>()
/// ```
declare_clippy_lint! {
pub INFINITE_ITER,
correctness,
"infinite iteration"
}
declare_clippy_lint! {
/// **What it does:** Checks for iteration that may be infinite.
///
/// **Why is this bad?** While there may be places where this is acceptable
@@ -32,7 +33,6 @@ declare_clippy_lint! {
/// ```rust
/// [0..].iter().zip(infinite_iter.take_while(|x| x > 5))
/// ```
declare_clippy_lint! {
pub MAYBE_INFINITE_ITER,
pedantic,
"possible infinite iteration"

View File

@@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashMap;
use std::default::Default;
use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for multiple inherent implementations of a struct
///
/// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate.
@@ -34,7 +35,6 @@ use syntax_pos::Span;
/// fn other() {}
/// }
/// ```
declare_clippy_lint! {
pub MULTIPLE_INHERENT_IMPL,
restriction,
"Multiple inherent impl that could be grouped"

View File

@@ -8,6 +8,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast::{Attribute, Name};
declare_clippy_lint! {
/// **What it does:** Checks for `#[inline]` on trait methods without bodies
///
/// **Why is this bad?** Only implementations of trait methods may be inlined.
@@ -22,7 +23,6 @@ use syntax::ast::{Attribute, Name};
/// fn name(&self) -> &'static str;
/// }
/// ```
declare_clippy_lint! {
pub INLINE_FN_WITHOUT_BODY,
correctness,
"use of `#[inline]` on trait methods without bodies"

View File

@@ -7,6 +7,7 @@ use syntax::ast::*;
use crate::utils::{snippet_opt, span_lint_and_then};
declare_clippy_lint! {
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
///
///
@@ -24,7 +25,6 @@ use crate::utils::{snippet_opt, span_lint_and_then};
/// ```rust
/// x > y
/// ```
declare_clippy_lint! {
pub INT_PLUS_ONE,
complexity,
"instead of using x >= y + 1, use x > y"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for creation of references to zeroed or uninitialized memory.
///
/// **Why is this bad?** Creation of null references is undefined behavior.
@@ -15,7 +16,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// let bad_ref: &usize = std::mem::zeroed();
/// ```
declare_clippy_lint! {
pub INVALID_REF,
correctness,
"creation of invalid reference"

View File

@@ -6,6 +6,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::*;
declare_clippy_lint! {
/// **What it does:** Checks for items declared after some statement in a block.
///
/// **Why is this bad?** Items live for the entire scope they are declared
@@ -28,7 +29,6 @@ use syntax::ast::*;
/// foo(); // prints "foo"
/// }
/// ```
declare_clippy_lint! {
pub ITEMS_AFTER_STATEMENTS,
pedantic,
"blocks where an item comes after a statement"

View File

@@ -7,6 +7,7 @@ use rustc::ty::layout::LayoutOf;
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for large size differences between variants on
/// `enum`s.
///
@@ -23,7 +24,6 @@ use rustc_errors::Applicability;
/// B([i32; 8000]),
/// }
/// ```
declare_clippy_lint! {
pub LARGE_ENUM_VARIANT,
perf,
"large size difference between variants on an enum"

View File

@@ -9,6 +9,7 @@ use rustc_errors::Applicability;
use syntax::ast::{Lit, LitKind, Name};
use syntax::source_map::{Span, Spanned};
declare_clippy_lint! {
/// **What it does:** Checks for getting the length of something via `.len()`
/// just to compare to zero, and suggests using `.is_empty()` where applicable.
///
@@ -38,13 +39,12 @@ use syntax::source_map::{Span, Spanned};
/// ..
/// }
/// ```
declare_clippy_lint! {
pub LEN_ZERO,
style,
"checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` \
could be used instead"
"checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` could be used instead"
}
declare_clippy_lint! {
/// **What it does:** Checks for items that implement `.len()` but not
/// `.is_empty()`.
///
@@ -64,7 +64,6 @@ style,
/// }
/// }
/// ```
declare_clippy_lint! {
pub LEN_WITHOUT_IS_EMPTY,
style,
"traits or impls with a public `len` method but no corresponding `is_empty` method"

View File

@@ -8,6 +8,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast;
declare_clippy_lint! {
/// **What it does:** Checks for variable declarations immediately followed by a
/// conditional affectation.
///
@@ -47,7 +48,6 @@ use syntax::ast;
/// None
/// };
/// ```
declare_clippy_lint! {
pub USELESS_LET_IF_SEQ,
style,
"unidiomatic `let mut` declaration followed by initialization in `if`"

View File

@@ -39,7 +39,7 @@ use toml;
///
/// Every lint declaration consists of 4 parts:
///
/// 1. The documentation above the lint, which is used for the website
/// 1. The documentation, which is used for the website
/// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
/// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
/// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
@@ -60,6 +60,7 @@ use toml;
/// # use clippy_lints::declare_clippy_lint;
/// use rustc::declare_tool_lint;
///
/// declare_clippy_lint! {
/// /// **What it does:** Checks for ... (describe what the lint matches).
/// ///
/// /// **Why is this bad?** Supply the reason for linting the code.
@@ -75,7 +76,6 @@ use toml;
/// /// // Good
/// /// Insert a short example of improved code that doesn't trigger the lint
/// /// ```
/// declare_clippy_lint! {
/// pub LINT_NAME,
/// pedantic,
/// "description"
@@ -84,35 +84,55 @@ use toml;
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
#[macro_export]
macro_rules! declare_clippy_lint {
{ pub $name:tt, style, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
declare_tool_lint! {
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
}
};
{ pub $name:tt, correctness, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Deny, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
declare_tool_lint! {
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
}
};
{ pub $name:tt, complexity, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Warn, $description, report_in_external_macro: true
}
};
{ pub $name:tt, perf, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Warn, $description, report_in_external_macro: true
}
};
{ pub $name:tt, pedantic, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
};
{ pub $name:tt, restriction, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
};
{ pub $name:tt, cargo, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
};
{ pub $name:tt, nursery, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
};
{ pub $name:tt, internal, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
};
{ pub $name:tt, internal_warn, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
declare_tool_lint! {
pub clippy::$name, Warn, $description, report_in_external_macro: true
}
};
}

View File

@@ -10,6 +10,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use syntax::source_map::Span;
use syntax::symbol::keywords;
declare_clippy_lint! {
/// **What it does:** Checks for lifetime annotations which can be removed by
/// relying on lifetime elision.
///
@@ -26,13 +27,13 @@ use syntax::symbol::keywords;
/// x
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_LIFETIMES,
complexity,
"using explicit lifetimes for references in function arguments when elision rules \
would allow omitting them"
}
declare_clippy_lint! {
/// **What it does:** Checks for lifetimes in generics that are never used
/// anywhere else.
///
@@ -48,7 +49,6 @@ complexity,
/// ..
/// }
/// ```
declare_clippy_lint! {
pub EXTRA_UNUSED_LIFETIMES,
complexity,
"unused lifetimes in function definitions"

View File

@@ -9,6 +9,7 @@ use rustc_errors::Applicability;
use syntax::ast::*;
use syntax_pos;
declare_clippy_lint! {
/// **What it does:** Warns if a long integral or floating-point constant does
/// not contain underscores.
///
@@ -21,12 +22,12 @@ use syntax_pos;
/// ```rust
/// 61864918973511
/// ```
declare_clippy_lint! {
pub UNREADABLE_LITERAL,
style,
"long integer literal without underscores"
}
declare_clippy_lint! {
/// **What it does:** Warns for mistyped suffix in literals
///
/// **Why is this bad?** This is most probably a typo
@@ -41,12 +42,12 @@ declare_clippy_lint! {
/// ```rust
/// 2_32
/// ```
declare_clippy_lint! {
pub MISTYPED_LITERAL_SUFFIXES,
correctness,
"mistyped literal suffix"
}
declare_clippy_lint! {
/// **What it does:** Warns if an integral or floating-point constant is
/// grouped inconsistently with underscores.
///
@@ -60,12 +61,12 @@ declare_clippy_lint! {
/// ```rust
/// 618_64_9189_73_511
/// ```
declare_clippy_lint! {
pub INCONSISTENT_DIGIT_GROUPING,
style,
"integer literals with digits grouped inconsistently"
}
declare_clippy_lint! {
/// **What it does:** Warns if the digits of an integral or floating-point
/// constant are grouped into groups that
/// are too large.
@@ -79,12 +80,12 @@ declare_clippy_lint! {
/// ```rust
/// 6186491_8973511
/// ```
declare_clippy_lint! {
pub LARGE_DIGIT_GROUPS,
pedantic,
"grouping digits into groups that are too large"
}
declare_clippy_lint! {
/// **What it does:** Warns if there is a better representation for a numeric literal.
///
/// **Why is this bad?** Especially for big powers of 2 a hexadecimal representation is more
@@ -97,7 +98,6 @@ declare_clippy_lint! {
/// `255` => `0xFF`
/// `65_535` => `0xFFFF`
/// `4_042_322_160` => `0xF0F0_F0F0`
declare_clippy_lint! {
pub DECIMAL_LITERAL_REPRESENTATION,
restriction,
"using decimal representation when hexadecimal would be better"

View File

@@ -32,6 +32,7 @@ use crate::utils::{
span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, SpanlessEq,
};
declare_clippy_lint! {
/// **What it does:** Checks for for-loops that manually copy items between
/// slices that could be optimized by having a memcpy.
///
@@ -45,12 +46,12 @@ use crate::utils::{
/// dst[i + 64] = src[i];
/// }
/// ```
declare_clippy_lint! {
pub MANUAL_MEMCPY,
perf,
"manually copying items between slices"
}
declare_clippy_lint! {
/// **What it does:** Checks for looping over the range of `0..len` of some
/// collection just to get the values by index.
///
@@ -65,12 +66,12 @@ declare_clippy_lint! {
/// println!("{}", vec[i]);
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_RANGE_LOOP,
style,
"for-looping over a range of indices where an iterator over items would do"
}
declare_clippy_lint! {
/// **What it does:** Checks for loops on `x.iter()` where `&x` will do, and
/// suggests the latter.
///
@@ -92,12 +93,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub EXPLICIT_ITER_LOOP,
pedantic,
"for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do"
}
declare_clippy_lint! {
/// **What it does:** Checks for loops on `y.into_iter()` where `y` will do, and
/// suggests the latter.
///
@@ -118,12 +119,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub EXPLICIT_INTO_ITER_LOOP,
pedantic,
"for-looping over `_.into_iter()` when `_` would do"
}
declare_clippy_lint! {
/// **What it does:** Checks for loops on `x.next()`.
///
/// **Why is this bad?** `next()` returns either `Some(value)` if there was a
@@ -141,12 +142,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub ITER_NEXT_LOOP,
correctness,
"for-looping over `_.next()` which is probably not intended"
}
declare_clippy_lint! {
/// **What it does:** Checks for `for` loops over `Option` values.
///
/// **Why is this bad?** Readability. This is more clearly expressed as an `if
@@ -167,12 +168,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub FOR_LOOP_OVER_OPTION,
correctness,
"for-looping over an `Option`, which is more clearly expressed as an `if let`"
}
declare_clippy_lint! {
/// **What it does:** Checks for `for` loops over `Result` values.
///
/// **Why is this bad?** Readability. This is more clearly expressed as an `if
@@ -193,12 +194,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub FOR_LOOP_OVER_RESULT,
correctness,
"for-looping over a `Result`, which is more clearly expressed as an `if let`"
}
declare_clippy_lint! {
/// **What it does:** Detects `loop + match` combinations that are easier
/// written as a `while let` loop.
///
@@ -221,12 +222,12 @@ declare_clippy_lint! {
/// // .. do something with x
/// }
/// ```
declare_clippy_lint! {
pub WHILE_LET_LOOP,
complexity,
"`loop { if let { ... } else break }`, which can be written as a `while let` loop"
}
declare_clippy_lint! {
/// **What it does:** Checks for using `collect()` on an iterator without using
/// the result.
///
@@ -239,12 +240,12 @@ declare_clippy_lint! {
/// ```rust
/// vec.iter().map(|x| /* some operation returning () */).collect::<Vec<_>>();
/// ```
declare_clippy_lint! {
pub UNUSED_COLLECT,
perf,
"`collect()`ing an iterator without using the result; this is usually better written as a for loop"
}
declare_clippy_lint! {
/// **What it does:** Checks for functions collecting an iterator when collect
/// is not needed.
///
@@ -260,12 +261,12 @@ declare_clippy_lint! {
/// // should be
/// let len = iterator.count();
/// ```
declare_clippy_lint! {
pub NEEDLESS_COLLECT,
perf,
"collecting an iterator when collect is not needed"
}
declare_clippy_lint! {
/// **What it does:** Checks for loops over ranges `x..y` where both `x` and `y`
/// are constant and `x` is greater or equal to `y`, unless the range is
/// reversed or has a negative `.step_by(_)`.
@@ -284,12 +285,12 @@ declare_clippy_lint! {
/// ..
/// } // oops, stray `-`
/// ```
declare_clippy_lint! {
pub REVERSE_RANGE_LOOP,
correctness,
"iteration over an empty range, such as `10..0` or `5..5`"
}
declare_clippy_lint! {
/// **What it does:** Checks `for` loops over slices with an explicit counter
/// and suggests the use of `.enumerate()`.
///
@@ -304,12 +305,12 @@ declare_clippy_lint! {
/// for i in 0..v.len() { foo(v[i]);
/// for i in 0..v.len() { bar(i, v[i]); }
/// ```
declare_clippy_lint! {
pub EXPLICIT_COUNTER_LOOP,
complexity,
"for-looping with an explicit counter when `_.enumerate()` would do"
}
declare_clippy_lint! {
/// **What it does:** Checks for empty `loop` expressions.
///
/// **Why is this bad?** Those busy loops burn CPU cycles without doing
@@ -322,12 +323,12 @@ declare_clippy_lint! {
/// ```rust
/// loop {}
/// ```
declare_clippy_lint! {
pub EMPTY_LOOP,
style,
"empty `loop {}`, which should block or sleep"
}
declare_clippy_lint! {
/// **What it does:** Checks for `while let` expressions on iterators.
///
/// **Why is this bad?** Readability. A simple `for` loop is shorter and conveys
@@ -341,12 +342,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub WHILE_LET_ON_ITERATOR,
style,
"using a while-let loop instead of a for loop on an iterator"
}
declare_clippy_lint! {
/// **What it does:** Checks for iterating a map (`HashMap` or `BTreeMap`) and
/// ignoring either the keys or values.
///
@@ -369,12 +370,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub FOR_KV_MAP,
style,
"looping on a map using `iter` when `keys` or `values` would do"
}
declare_clippy_lint! {
/// **What it does:** Checks for loops that will always `break`, `return` or
/// `continue` an outer loop.
///
@@ -390,12 +391,12 @@ declare_clippy_lint! {
/// break;
/// }
/// ```
declare_clippy_lint! {
pub NEVER_LOOP,
correctness,
"any loop that will always `break` or `return`"
}
declare_clippy_lint! {
/// **What it does:** Checks for loops which have a range bound that is a mutable variable
///
/// **Why is this bad?** One might think that modifying the mutable variable changes the loop bounds
@@ -410,12 +411,12 @@ declare_clippy_lint! {
/// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21
/// }
/// ```
declare_clippy_lint! {
pub MUT_RANGE_BOUND,
complexity,
"for loop over a range where one of the bounds is a mutable variable"
}
declare_clippy_lint! {
/// **What it does:** Checks whether variables used within while loop condition
/// can be (and are) mutated in the body.
///
@@ -433,7 +434,6 @@ declare_clippy_lint! {
/// println!("let me loop forever!");
/// }
/// ```
declare_clippy_lint! {
pub WHILE_IMMUTABLE_CONDITION,
correctness,
"variables used within while expression are not mutated in the body"

View File

@@ -14,6 +14,7 @@ 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
///
@@ -36,7 +37,6 @@ pub struct Pass;
/// let y = x.iter();
/// let z = y.cloned();
/// ```
declare_clippy_lint! {
pub MAP_CLONE,
style,
"using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types"

View File

@@ -11,6 +11,7 @@ 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.
///
@@ -38,12 +39,12 @@ pub struct Pass;
/// log_err_msg(format_msg(msg))
/// }
/// ```
declare_clippy_lint! {
pub OPTION_MAP_UNIT_FN,
complexity,
"using `option.map(f)`, where f is a function or closure that returns ()"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `result.map(f)` where f is a function
/// or closure that returns the unit type.
///
@@ -71,7 +72,6 @@ declare_clippy_lint! {
/// log_err_msg(format_msg(msg))
/// }
/// ```
declare_clippy_lint! {
pub RESULT_MAP_UNIT_FN,
complexity,
"using `result.map(f)`, where f is a function or closure that returns ()"

View File

@@ -18,6 +18,7 @@ use std::ops::Deref;
use syntax::ast::LitKind;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for matches with a single arm where an `if let`
/// will usually suffice.
///
@@ -32,12 +33,12 @@ use syntax::source_map::Span;
/// _ => (),
/// }
/// ```
declare_clippy_lint! {
pub SINGLE_MATCH,
style,
"a match statement with a single nontrivial arm (i.e. where the other arm is `_ => {}`) instead of `if let`"
}
declare_clippy_lint! {
/// **What it does:** Checks for matches with a two arms where an `if let else` will
/// usually suffice.
///
@@ -65,12 +66,12 @@ declare_clippy_lint! {
/// bar(other_ref);
/// }
/// ```
declare_clippy_lint! {
pub SINGLE_MATCH_ELSE,
pedantic,
"a match statement with a two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
}
declare_clippy_lint! {
/// **What it does:** Checks for matches where all arms match a reference,
/// suggesting to remove the reference and deref the matched expression
/// instead. It also checks for `if let &foo = bar` blocks.
@@ -88,12 +89,12 @@ declare_clippy_lint! {
/// _ => frob(&x),
/// }
/// ```
declare_clippy_lint! {
pub MATCH_REF_PATS,
style,
"a match or `if let` with all arms prefixed with `&` instead of deref-ing the match expression"
}
declare_clippy_lint! {
/// **What it does:** Checks for matches where match expression is a `bool`. It
/// suggests to replace the expression with an `if...else` block.
///
@@ -118,12 +119,12 @@ declare_clippy_lint! {
/// bar();
/// }
/// ```
declare_clippy_lint! {
pub MATCH_BOOL,
style,
"a match on a boolean expression instead of an `if..else` block"
}
declare_clippy_lint! {
/// **What it does:** Checks for overlapping match arms.
///
/// **Why is this bad?** It is likely to be an error and if not, makes the code
@@ -140,12 +141,12 @@ declare_clippy_lint! {
/// _ => (),
/// }
/// ```
declare_clippy_lint! {
pub MATCH_OVERLAPPING_ARM,
style,
"a match with overlapping arms"
}
declare_clippy_lint! {
/// **What it does:** Checks for arm which matches all errors with `Err(_)`
/// and take drastic actions like `panic!`.
///
@@ -162,12 +163,12 @@ declare_clippy_lint! {
/// Err(_) => panic!("err"),
/// }
/// ```
declare_clippy_lint! {
pub MATCH_WILD_ERR_ARM,
style,
"a match with `Err(_)` arm and take drastic actions"
}
declare_clippy_lint! {
/// **What it does:** Checks for match which is used to add a reference to an
/// `Option` value.
///
@@ -183,12 +184,12 @@ declare_clippy_lint! {
/// Some(ref v) => Some(v),
/// };
/// ```
declare_clippy_lint! {
pub MATCH_AS_REF,
complexity,
"a match on an Option value instead of using `as_ref()` or `as_mut`"
}
declare_clippy_lint! {
/// **What it does:** Checks for wildcard enum matches using `_`.
///
/// **Why is this bad?** New enum variants added by library updates can be missed.
@@ -203,7 +204,6 @@ declare_clippy_lint! {
/// _ => {},
/// }
/// ```
declare_clippy_lint! {
pub WILDCARD_ENUM_MATCH_ARM,
restriction,
"a wildcard enum match arm using `_`"

View File

@@ -7,6 +7,7 @@ use rustc_errors::Applicability;
use std::iter;
declare_clippy_lint! {
/// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type.
///
/// **Why is this bad?** The value of `mem::discriminant()` on non-enum types
@@ -19,7 +20,6 @@ use std::iter;
/// mem::discriminant(&"hello");
/// mem::discriminant(&&Some(2));
/// ```
declare_clippy_lint! {
pub MEM_DISCRIMINANT_NON_ENUM,
correctness,
"calling mem::descriminant on non-enum type"

View File

@@ -3,6 +3,7 @@ use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is
/// `Drop`.
///
@@ -15,7 +16,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// mem::forget(Rc::new(55))
/// ```
declare_clippy_lint! {
pub MEM_FORGET,
restriction,
"`mem::forget` usage on `Drop` types, likely to cause memory leaks"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for `mem::replace()` on an `Option` with
/// `None`.
///
@@ -24,7 +25,6 @@ use rustc_errors::Applicability;
/// let mut an_option = Some(0);
/// let taken = an_option.take();
/// ```
declare_clippy_lint! {
pub MEM_REPLACE_OPTION_WITH_NONE,
style,
"replacing an `Option` with `None` instead of `take()`"

View File

@@ -28,6 +28,7 @@ mod unnecessary_filter_map;
#[derive(Clone)]
pub struct Pass;
declare_clippy_lint! {
/// **What it does:** Checks for `.unwrap()` calls on `Option`s.
///
/// **Why is this bad?** Usually it is better to handle the `None` case, or to
@@ -41,12 +42,12 @@ pub struct Pass;
/// ```rust
/// x.unwrap()
/// ```
declare_clippy_lint! {
pub OPTION_UNWRAP_USED,
restriction,
"using `Option.unwrap()`, which should at least get a better message using `expect()`"
}
declare_clippy_lint! {
/// **What it does:** Checks for `.unwrap()` calls on `Result`s.
///
/// **Why is this bad?** `result.unwrap()` will let the thread panic on `Err`
@@ -63,12 +64,12 @@ declare_clippy_lint! {
/// ```rust
/// x.unwrap()
/// ```
declare_clippy_lint! {
pub RESULT_UNWRAP_USED,
restriction,
"using `Result.unwrap()`, which might be better handled"
}
declare_clippy_lint! {
/// **What it does:** Checks for methods that should live in a trait
/// implementation of a `std` trait (see [llogiq's blog
/// post](http://llogiq.github.io/2015/07/30/traits.html) for further
@@ -91,12 +92,12 @@ declare_clippy_lint! {
/// }
/// }
/// ```
declare_clippy_lint! {
pub SHOULD_IMPLEMENT_TRAIT,
style,
"defining a method that should be implementing a std trait"
}
declare_clippy_lint! {
/// **What it does:** Checks for methods with certain name prefixes and which
/// doesn't match how self is taken. The actual rules are:
///
@@ -122,12 +123,12 @@ declare_clippy_lint! {
/// }
/// }
/// ```
declare_clippy_lint! {
pub WRONG_SELF_CONVENTION,
style,
"defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
}
declare_clippy_lint! {
/// **What it does:** This is the same as
/// [`wrong_self_convention`](#wrong_self_convention), but for public items.
///
@@ -145,12 +146,12 @@ declare_clippy_lint! {
/// }
/// }
/// ```
declare_clippy_lint! {
pub WRONG_PUB_SELF_CONVENTION,
restriction,
"defining a public method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `ok().expect(..)`.
///
/// **Why is this bad?** Because you usually call `expect()` on the `Result`
@@ -162,12 +163,12 @@ declare_clippy_lint! {
/// ```rust
/// x.ok().expect("why did I do this again?")
/// ```
declare_clippy_lint! {
pub OK_EXPECT,
style,
"using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.map(_).unwrap_or(_)`.
///
/// **Why is this bad?** Readability, this can be written more concisely as
@@ -179,13 +180,12 @@ declare_clippy_lint! {
/// ```rust
/// x.map(|a| a + 1).unwrap_or(0)
/// ```
declare_clippy_lint! {
pub OPTION_MAP_UNWRAP_OR,
pedantic,
"using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as \
`map_or(a, f)`"
"using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as `map_or(a, f)`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.map(_).unwrap_or_else(_)`.
///
/// **Why is this bad?** Readability, this can be written more concisely as
@@ -197,12 +197,12 @@ pedantic,
/// ```rust
/// x.map(|a| a + 1).unwrap_or_else(some_function)
/// ```
declare_clippy_lint! {
pub OPTION_MAP_UNWRAP_OR_ELSE,
pedantic,
"using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `map_or_else(g, f)`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `result.map(_).unwrap_or_else(_)`.
///
/// **Why is this bad?** Readability, this can be written more concisely as
@@ -214,12 +214,12 @@ declare_clippy_lint! {
/// ```rust
/// x.map(|a| a + 1).unwrap_or_else(some_function)
/// ```
declare_clippy_lint! {
pub RESULT_MAP_UNWRAP_OR_ELSE,
pedantic,
"using `Result.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `.ok().map_or_else(g, f)`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.map_or(None, _)`.
///
/// **Why is this bad?** Readability, this can be written more concisely as
@@ -231,12 +231,12 @@ declare_clippy_lint! {
/// ```rust
/// opt.map_or(None, |a| a + 1)
/// ```
declare_clippy_lint! {
pub OPTION_MAP_OR_NONE,
style,
"using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.filter(_).next()`.
///
/// **Why is this bad?** Readability, this can be written more concisely as
@@ -248,12 +248,12 @@ declare_clippy_lint! {
/// ```rust
/// iter.filter(|x| x == 0).next()
/// ```
declare_clippy_lint! {
pub FILTER_NEXT,
complexity,
"using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.map(_).flatten(_)`,
///
/// **Why is this bad?** Readability, this can be written more concisely as a
@@ -265,12 +265,12 @@ declare_clippy_lint! {
/// ```rust
/// iter.map(|x| x.iter()).flatten()
/// ```
declare_clippy_lint! {
pub MAP_FLATTEN,
pedantic,
"using combinations of `flatten` and `map` which can usually be written as a single method call"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.filter(_).map(_)`,
/// `_.filter(_).flat_map(_)`, `_.filter_map(_).flat_map(_)` and similar.
///
@@ -284,12 +284,12 @@ declare_clippy_lint! {
/// ```rust
/// iter.filter(|x| x == 0).map(|x| x * 2)
/// ```
declare_clippy_lint! {
pub FILTER_MAP,
pedantic,
"using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call"
}
declare_clippy_lint! {
/// **What it does:** Checks for an iterator search (such as `find()`,
/// `position()`, or `rposition()`) followed by a call to `is_some()`.
///
@@ -302,12 +302,12 @@ declare_clippy_lint! {
/// ```rust
/// iter.find(|x| x == 0).is_some()
/// ```
declare_clippy_lint! {
pub SEARCH_IS_SOME,
complexity,
"using an iterator search followed by `is_some()`, which is more succinctly expressed as a call to `any()`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `.chars().next()` on a `str` to check
/// if it starts with a given char.
///
@@ -320,12 +320,12 @@ declare_clippy_lint! {
/// ```rust
/// name.chars().next() == Some('_')
/// ```
declare_clippy_lint! {
pub CHARS_NEXT_CMP,
complexity,
"using `.chars().next()` to check if a string starts with a char"
}
declare_clippy_lint! {
/// **What it does:** Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`,
/// etc., and suggests to use `or_else`, `unwrap_or_else`, etc., or
/// `unwrap_or_default` instead.
@@ -348,12 +348,12 @@ declare_clippy_lint! {
/// ```rust
/// foo.unwrap_or_default()
/// ```
declare_clippy_lint! {
pub OR_FUN_CALL,
perf,
"using any `*or` method with a function call, which suggests `*or_else`"
}
declare_clippy_lint! {
/// **What it does:** Checks for calls to `.expect(&format!(...))`, `.expect(foo(..))`,
/// etc., and suggests to use `unwrap_or_else` instead
///
@@ -374,12 +374,12 @@ declare_clippy_lint! {
/// ```rust
/// foo.unwrap_or_else(|_| panic!("Err {}: {}", err_code, err_msg))
/// ```
declare_clippy_lint! {
pub EXPECT_FUN_CALL,
perf,
"using any `expect` method with a function call"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `.clone()` on a `Copy` type.
///
/// **Why is this bad?** The only reason `Copy` types implement `Clone` is for
@@ -391,12 +391,12 @@ declare_clippy_lint! {
/// ```rust
/// 42u64.clone()
/// ```
declare_clippy_lint! {
pub CLONE_ON_COPY,
complexity,
"using `clone` on a `Copy` type"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `.clone()` on a ref-counted pointer,
/// (`Rc`, `Arc`, `rc::Weak`, or `sync::Weak`), and suggests calling Clone via unified
/// function syntax instead (e.g. `Rc::clone(foo)`).
@@ -409,12 +409,12 @@ declare_clippy_lint! {
/// ```rust
/// x.clone()
/// ```
declare_clippy_lint! {
pub CLONE_ON_REF_PTR,
restriction,
"using 'clone' on a ref-counted pointer"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `.clone()` on an `&&T`.
///
/// **Why is this bad?** Cloning an `&&T` copies the inner `&T`, instead of
@@ -431,12 +431,12 @@ declare_clippy_lint! {
/// println!("{:p} {:p}", *y, z); // prints out the same pointer
/// }
/// ```
declare_clippy_lint! {
pub CLONE_DOUBLE_REF,
correctness,
"using `clone` on `&&T`"
}
declare_clippy_lint! {
/// **What it does:** Checks for `new` not returning `Self`.
///
/// **Why is this bad?** As a convention, `new` methods are used to make a new
@@ -451,12 +451,12 @@ declare_clippy_lint! {
/// }
/// }
/// ```
declare_clippy_lint! {
pub NEW_RET_NO_SELF,
style,
"not returning `Self` in a `new` method"
}
declare_clippy_lint! {
/// **What it does:** Checks for string methods that receive a single-character
/// `str` as an argument, e.g. `_.split("x")`.
///
@@ -467,12 +467,12 @@ declare_clippy_lint! {
///
/// **Example:**
/// `_.split("x")` could be `_.split('x')`
declare_clippy_lint! {
pub SINGLE_CHAR_PATTERN,
perf,
"using a single-character str where a char could be used, e.g. `_.split(\"x\")`"
}
declare_clippy_lint! {
/// **What it does:** Checks for getting the inner pointer of a temporary
/// `CString`.
///
@@ -495,12 +495,12 @@ declare_clippy_lint! {
/// call_some_ffi_func(c_str.as_ptr());
/// }
/// ```
declare_clippy_lint! {
pub TEMPORARY_CSTRING_AS_PTR,
correctness,
"getting the inner pointer of a temporary `CString`"
}
declare_clippy_lint! {
/// **What it does:** Checks for use of `.iter().nth()` (and the related
/// `.iter_mut().nth()`) on standard library types with O(1) element access.
///
@@ -521,12 +521,12 @@ declare_clippy_lint! {
/// let bad_vec = some_vec.get(3);
/// let bad_slice = &some_vec[..].get(3);
/// ```
declare_clippy_lint! {
pub ITER_NTH,
perf,
"using `.iter().nth()` on a standard library type with O(1) element access"
}
declare_clippy_lint! {
/// **What it does:** Checks for use of `.skip(x).next()` on iterators.
///
/// **Why is this bad?** `.nth(x)` is cleaner
@@ -545,12 +545,12 @@ declare_clippy_lint! {
/// let bad_vec = some_vec.iter().nth(3);
/// let bad_slice = &some_vec[..].iter().nth(3);
/// ```
declare_clippy_lint! {
pub ITER_SKIP_NEXT,
style,
"using `.skip(x).next()` on an iterator"
}
declare_clippy_lint! {
/// **What it does:** Checks for use of `.get().unwrap()` (or
/// `.get_mut().unwrap`) on a standard library type which implements `Index`
///
@@ -578,12 +578,12 @@ declare_clippy_lint! {
/// let last = some_vec[3];
/// some_vec[0] = 1;
/// ```
declare_clippy_lint! {
pub GET_UNWRAP,
style,
"using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead"
}
declare_clippy_lint! {
/// **What it does:** Checks for the use of `.extend(s.chars())` where s is a
/// `&str` or `String`.
///
@@ -607,12 +607,12 @@ declare_clippy_lint! {
/// s.push_str(abc);
/// s.push_str(&def));
/// ```
declare_clippy_lint! {
pub STRING_EXTEND_CHARS,
style,
"using `x.extend(s.chars())` where s is a `&str` or `String`"
}
declare_clippy_lint! {
/// **What it does:** Checks for the use of `.cloned().collect()` on slice to
/// create a `Vec`.
///
@@ -630,12 +630,12 @@ declare_clippy_lint! {
/// let s = [1, 2, 3, 4, 5];
/// let s2: Vec<isize> = s.to_vec();
/// ```
declare_clippy_lint! {
pub ITER_CLONED_COLLECT,
style,
"using `.cloned().collect()` on slice to create a `Vec`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `.chars().last()` or
/// `.chars().next_back()` on a `str` to check if it ends with a given char.
///
@@ -648,12 +648,12 @@ declare_clippy_lint! {
/// ```rust
/// name.chars().last() == Some('_') || name.chars().next_back() == Some('-')
/// ```
declare_clippy_lint! {
pub CHARS_LAST_CMP,
style,
"using `.chars().last()` or `.chars().next_back()` to check if a string ends with a char"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `.as_ref()` or `.as_mut()` where the
/// types before and after the call are the same.
///
@@ -671,12 +671,12 @@ declare_clippy_lint! {
/// let x: &[i32] = &[1, 2, 3, 4, 5];
/// do_stuff(x);
/// ```
declare_clippy_lint! {
pub USELESS_ASREF,
complexity,
"using `as_ref` where the types before and after the call are the same"
}
declare_clippy_lint! {
/// **What it does:** Checks for using `fold` when a more succinct alternative exists.
/// Specifically, this checks for `fold`s which could be replaced by `any`, `all`,
/// `sum` or `product`.
@@ -694,12 +694,12 @@ declare_clippy_lint! {
/// ```rust
/// let _ = (0..3).any(|x| x > 2);
/// ```
declare_clippy_lint! {
pub UNNECESSARY_FOLD,
style,
"using `fold` when a more succinct alternative exists"
}
declare_clippy_lint! {
/// **What it does:** Checks for `filter_map` calls which could be replaced by `filter` or `map`.
/// More specifically it checks if the closure provided is only performing one of the
/// filter or map operations and suggests the appropriate option.
@@ -725,12 +725,12 @@ declare_clippy_lint! {
/// ```rust
/// let _ = (0..4).map(i32::checked_abs);
/// ```
declare_clippy_lint! {
pub UNNECESSARY_FILTER_MAP,
complexity,
"using `filter_map` when a more succinct alternative exists"
}
declare_clippy_lint! {
/// **What it does:** Checks for `into_iter` calls on types which should be replaced by `iter` or
/// `iter_mut`.
///
@@ -750,12 +750,12 @@ declare_clippy_lint! {
/// ```
///
/// [25725]: https://github.com/rust-lang/rust/issues/25725
declare_clippy_lint! {
pub INTO_ITER_ON_ARRAY,
correctness,
"using `.into_iter()` on an array"
}
declare_clippy_lint! {
/// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter`
/// or `iter_mut`.
///
@@ -770,7 +770,6 @@ declare_clippy_lint! {
/// ```rust
/// let _ = (&vec![3, 4, 5]).into_iter();
/// ```
declare_clippy_lint! {
pub INTO_ITER_ON_REF,
style,
"using `.into_iter()` on a reference"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use std::cmp::Ordering;
declare_clippy_lint! {
/// **What it does:** Checks for expressions where `std::cmp::min` and `max` are
/// used to clamp values, but switched so that the result is constant.
///
@@ -19,7 +20,6 @@ use std::cmp::Ordering;
/// ```
/// It will always be equal to `0`. Probably the author meant to clamp the value
/// between 0 and 100, but has erroneously swapped `min` and `max`.
declare_clippy_lint! {
pub MIN_MAX,
correctness,
"`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant"

View File

@@ -16,6 +16,7 @@ use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::{ExpnFormat, Span};
declare_clippy_lint! {
/// **What it does:** Checks for function arguments and let bindings denoted as
/// `ref`.
///
@@ -38,12 +39,12 @@ use syntax::source_map::{ExpnFormat, Span};
/// ..
/// }
/// ```
declare_clippy_lint! {
pub TOPLEVEL_REF_ARG,
style,
"an entire binding declared as `ref`, in a function argument or a `let` statement"
}
declare_clippy_lint! {
/// **What it does:** Checks for comparisons to NaN.
///
/// **Why is this bad?** NaN does not compare meaningfully to anything not
@@ -55,12 +56,12 @@ declare_clippy_lint! {
/// ```rust
/// x == NAN
/// ```
declare_clippy_lint! {
pub CMP_NAN,
correctness,
"comparisons to NAN, which will always return false, probably not intended"
}
declare_clippy_lint! {
/// **What it does:** Checks for (in-)equality comparisons on floating-point
/// values (apart from zero), except in functions called `*eq*` (which probably
/// implement equality for a type involving floats).
@@ -77,12 +78,12 @@ declare_clippy_lint! {
/// y == 1.23f64
/// y != x // where both are floats
/// ```
declare_clippy_lint! {
pub FLOAT_CMP,
correctness,
"using `==` or `!=` on float values instead of comparing difference with an epsilon"
}
declare_clippy_lint! {
/// **What it does:** Checks for conversions to owned values just for the sake
/// of a comparison.
///
@@ -96,12 +97,12 @@ declare_clippy_lint! {
/// ```rust
/// x.to_owned() == y
/// ```
declare_clippy_lint! {
pub CMP_OWNED,
perf,
"creating owned instances for comparing with others, e.g. `x == \"foo\".to_string()`"
}
declare_clippy_lint! {
/// **What it does:** Checks for getting the remainder of a division by one.
///
/// **Why is this bad?** The result can only ever be zero. No one will write
@@ -115,12 +116,12 @@ declare_clippy_lint! {
/// ```rust
/// x % 1
/// ```
declare_clippy_lint! {
pub MODULO_ONE,
correctness,
"taking a number modulo 1, which always returns 0"
}
declare_clippy_lint! {
/// **What it does:** Checks for patterns in the form `name @ _`.
///
/// **Why is this bad?** It's almost always more readable to just use direct
@@ -135,12 +136,12 @@ declare_clippy_lint! {
/// y @ _ => (), // easier written as `y`,
/// }
/// ```
declare_clippy_lint! {
pub REDUNDANT_PATTERN,
style,
"using `name @ _` in a pattern"
}
declare_clippy_lint! {
/// **What it does:** Checks for the use of bindings with a single leading
/// underscore.
///
@@ -157,12 +158,12 @@ declare_clippy_lint! {
/// let y = _x + 1; // Here we are using `_x`, even though it has a leading
/// // underscore. We should rename `_x` to `x`
/// ```
declare_clippy_lint! {
pub USED_UNDERSCORE_BINDING,
pedantic,
"using a binding which is prefixed with an underscore"
}
declare_clippy_lint! {
/// **What it does:** Checks for the use of short circuit boolean conditions as
/// a
/// statement.
@@ -177,12 +178,12 @@ declare_clippy_lint! {
/// ```rust
/// f() && g(); // We should write `if f() { g(); }`.
/// ```
declare_clippy_lint! {
pub SHORT_CIRCUIT_STATEMENT,
complexity,
"using a short circuit boolean condition as a statement"
}
declare_clippy_lint! {
/// **What it does:** Catch casts from `0` to some pointer type
///
/// **Why is this bad?** This generally means `null` and is better expressed as
@@ -195,12 +196,12 @@ declare_clippy_lint! {
/// ```rust
/// 0 as *const u32
/// ```
declare_clippy_lint! {
pub ZERO_PTR,
style,
"using 0 as *{const, mut} T"
}
declare_clippy_lint! {
/// **What it does:** Checks for (in-)equality comparisons on floating-point
/// value and constant, except in functions called `*eq*` (which probably
/// implement equality for a type involving floats).
@@ -217,7 +218,6 @@ declare_clippy_lint! {
/// const ONE = 1.00f64;
/// x == ONE // where both are floats
/// ```
declare_clippy_lint! {
pub FLOAT_CMP_CONST,
restriction,
"using `==` or `!=` on float constants instead of comparing difference with an epsilon"

View File

@@ -9,6 +9,7 @@ use syntax::ast::*;
use syntax::source_map::Span;
use syntax::visit::{walk_expr, FnKind, Visitor};
declare_clippy_lint! {
/// **What it does:** Checks for structure field patterns bound to wildcards.
///
/// **Why is this bad?** Using `..` instead is shorter and leaves the focus on
@@ -20,12 +21,12 @@ use syntax::visit::{walk_expr, FnKind, Visitor};
/// ```rust
/// let { a: _, b: ref b, c: _ } = ..
/// ```
declare_clippy_lint! {
pub UNNEEDED_FIELD_PATTERN,
style,
"struct fields bound to a wildcard instead of using `..`"
}
declare_clippy_lint! {
/// **What it does:** Checks for function arguments having the similar names
/// differing by an underscore.
///
@@ -37,12 +38,12 @@ declare_clippy_lint! {
/// ```rust
/// fn foo(a: i32, _a: i32) {}
/// ```
declare_clippy_lint! {
pub DUPLICATE_UNDERSCORE_ARGUMENT,
style,
"function arguments having names which only differ by an underscore"
}
declare_clippy_lint! {
/// **What it does:** Detects closures called in the same expression where they
/// are defined.
///
@@ -55,12 +56,12 @@ declare_clippy_lint! {
/// ```rust
/// (|| 42)()
/// ```
declare_clippy_lint! {
pub REDUNDANT_CLOSURE_CALL,
complexity,
"throwaway closures called in the expression they are defined"
}
declare_clippy_lint! {
/// **What it does:** Detects expressions of the form `--x`.
///
/// **Why is this bad?** It can mislead C/C++ programmers to think `x` was
@@ -72,12 +73,12 @@ declare_clippy_lint! {
/// ```rust
/// --x;
/// ```
declare_clippy_lint! {
pub DOUBLE_NEG,
style,
"`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++"
}
declare_clippy_lint! {
/// **What it does:** Warns on hexadecimal literals with mixed-case letter
/// digits.
///
@@ -89,12 +90,12 @@ declare_clippy_lint! {
/// ```rust
/// let y = 0x1a9BAcD;
/// ```
declare_clippy_lint! {
pub MIXED_CASE_HEX_LITERALS,
style,
"hex literals whose letter digits are not consistently upper- or lowercased"
}
declare_clippy_lint! {
/// **What it does:** Warns if literal suffixes are not separated by an
/// underscore.
///
@@ -106,12 +107,12 @@ declare_clippy_lint! {
/// ```rust
/// let y = 123832i32;
/// ```
declare_clippy_lint! {
pub UNSEPARATED_LITERAL_SUFFIX,
pedantic,
"literals whose suffix is not separated by an underscore"
}
declare_clippy_lint! {
/// **What it does:** Warns if an integral constant literal starts with `0`.
///
/// **Why is this bad?** In some languages (including the infamous C language
@@ -144,12 +145,12 @@ declare_clippy_lint! {
/// ```
///
/// prints `83` (as `83 == 0o123` while `123 == 0o173`).
declare_clippy_lint! {
pub ZERO_PREFIXED_LITERAL,
complexity,
"integer literals starting with `0`"
}
declare_clippy_lint! {
/// **What it does:** Warns if a generic shadows a built-in type.
///
/// **Why is this bad?** This gives surprising type errors.
@@ -165,7 +166,6 @@ declare_clippy_lint! {
/// }
/// }
/// ```
declare_clippy_lint! {
pub BUILTIN_TYPE_SHADOW,
style,
"shadowing a builtin type"

View File

@@ -8,6 +8,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:**
///
/// Suggests the use of `const` in functions and methods where possible.
@@ -52,7 +53,6 @@ use syntax_pos::Span;
/// Self { random_number: 42 }
/// }
/// ```
declare_clippy_lint! {
pub MISSING_CONST_FOR_FN,
nursery,
"Lint functions definitions that could be made `const fn`"

View File

@@ -14,6 +14,7 @@ use syntax::ast;
use syntax::attr;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Warns if there is missing doc for any documentable item
/// (public or private).
///
@@ -23,7 +24,6 @@ use syntax::source_map::Span;
/// This lint fixes that.
///
/// **Known problems:** None.
declare_clippy_lint! {
pub MISSING_DOCS_IN_PRIVATE_ITEMS,
restriction,
"detects missing documentation for public and private members"

View File

@@ -5,6 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** it lints if an exported function, method, trait method with default impl,
/// or trait method impl is not `#[inline]`.
///
@@ -50,7 +51,6 @@ use syntax::source_map::Span;
/// fn def_bar() {} // missing #[inline]
/// }
/// ```
declare_clippy_lint! {
pub MISSING_INLINE_IN_PUBLIC_ITEMS,
restriction,
"detects missing #[inline] attribute for public callables (functions, trait methods, methods...)"

View File

@@ -8,6 +8,7 @@ use syntax::{ast::*, source_map::DUMMY_SP};
use cargo_metadata;
use itertools::Itertools;
declare_clippy_lint! {
/// **What it does:** Checks to see if multiple versions of a crate are being
/// used.
///
@@ -25,7 +26,6 @@ use itertools::Itertools;
/// ctrlc = "3.1.0"
/// ansi_term = "0.11.0"
/// ```
declare_clippy_lint! {
pub MULTIPLE_CRATE_VERSIONS,
cargo,
"multiple versions of the same crate being used"

View File

@@ -5,6 +5,7 @@ use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintC
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for instances of `mut mut` references.
///
/// **Why is this bad?** Multiple `mut`s don't add anything meaningful to the
@@ -17,7 +18,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// let x = &mut &mut y;
/// ```
declare_clippy_lint! {
pub MUT_MUT,
pedantic,
"usage of double-mut refs, e.g. `&mut &mut ...`"

View File

@@ -5,6 +5,7 @@ use rustc::ty::subst::Subst;
use rustc::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Detects giving a mutable reference to a function that only
/// requires an immutable reference.
///
@@ -17,7 +18,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// my_vec.push(&mut value)
/// ```
declare_clippy_lint! {
pub UNNECESSARY_MUT_PASSED,
style,
"an argument passed as a mutable reference although the callee only demands an immutable reference"

View File

@@ -9,6 +9,7 @@ use rustc::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
declare_clippy_lint! {
/// **What it does:** Checks for usages of `Mutex<X>` where an atomic will do.
///
/// **Why is this bad?** Using a mutex just to make access to a plain bool or
@@ -23,12 +24,12 @@ use syntax::ast;
/// ```rust
/// let x = Mutex::new(&y);
/// ```
declare_clippy_lint! {
pub MUTEX_ATOMIC,
perf,
"using a mutex where an atomic value could be used instead"
}
declare_clippy_lint! {
/// **What it does:** Checks for usages of `Mutex<X>` where `X` is an integral
/// type.
///
@@ -43,7 +44,6 @@ declare_clippy_lint! {
/// ```rust
/// let x = Mutex::new(0usize);
/// ```
declare_clippy_lint! {
pub MUTEX_INTEGER,
nursery,
"using a mutex for an integer type"

View File

@@ -11,6 +11,7 @@ use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::Spanned;
declare_clippy_lint! {
/// **What it does:** Checks for expressions of the form `if c { true } else {
/// false }`
/// (or vice versa) and suggest using the condition directly.
@@ -30,12 +31,12 @@ use syntax::source_map::Spanned;
/// true
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_BOOL,
complexity,
"if-statements with plain booleans in the then- and else-clause, e.g. `if p { true } else { false }`"
}
declare_clippy_lint! {
/// **What it does:** Checks for expressions of the form `x == true`,
/// `x != true` and order comparisons such as `x < true` (or vice versa) and
/// suggest using the variable directly.
@@ -48,7 +49,6 @@ declare_clippy_lint! {
/// ```rust
/// if x == true {} // could be `if x { }`
/// ```
declare_clippy_lint! {
pub BOOL_COMPARISON,
complexity,
"comparing a variable to a boolean, e.g. `if x == true` or `if x != true`"

View File

@@ -11,6 +11,7 @@ use rustc::ty::adjustment::{Adjust, Adjustment};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for address of operations (`&`) that are going to
/// be dereferenced immediately by the compiler.
///
@@ -23,7 +24,6 @@ use rustc_errors::Applicability;
/// ```
///
/// **Known problems:** None.
declare_clippy_lint! {
pub NEEDLESS_BORROW,
nursery,
"taking a reference that is going to be automatically dereferenced"

View File

@@ -9,6 +9,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for useless borrowed references.
///
/// **Why is this bad?** It is mostly useless and make the code look more
@@ -45,7 +46,6 @@ use rustc_errors::Applicability;
/// reference and
/// de-referenced.
/// As such, it could just be |a| a.is_empty()
declare_clippy_lint! {
pub NEEDLESS_BORROWED_REFERENCE,
complexity,
"taking a needless borrowed reference"

View File

@@ -35,6 +35,7 @@ use syntax::source_map::{original_sp, DUMMY_SP};
use crate::utils::{in_macro, snippet, snippet_block, span_help_and_lint, trim_multiline};
declare_clippy_lint! {
/// **What it does:** The lint checks for `if`-statements appearing in loops
/// that contain a `continue` statement in either their main blocks or their
/// `else`-blocks, when omitting the `else`-block possibly with some
@@ -94,7 +95,6 @@ use crate::utils::{in_macro, snippet, snippet_block, span_help_and_lint, trim_mu
/// // Do something useful
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_CONTINUE,
pedantic,
"`continue` statements that can be replaced by a rearrangement of code"

View File

@@ -20,6 +20,7 @@ use std::borrow::Cow;
use syntax::errors::DiagnosticBuilder;
use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for functions taking arguments by value, but not
/// consuming them in its
/// body.
@@ -43,7 +44,6 @@ use syntax_pos::Span;
/// assert_eq!(v.len(), 42);
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_PASS_BY_VALUE,
pedantic,
"functions taking arguments by value, but not consuming them in its body"

View File

@@ -4,6 +4,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for needlessly including a base struct on update
/// when all fields are changed anyway.
///
@@ -20,7 +21,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ..zero_point
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_UPDATE,
complexity,
"using `Foo { ..base }` when there are no missing fields"

View File

@@ -5,6 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use crate::utils::{self, paths, span_lint};
declare_clippy_lint! {
/// **What it does:**
/// Checks for the usage of negated comparison operators on types which only implement
/// `PartialOrd` (e.g. `f64`).
@@ -36,7 +37,6 @@ use crate::utils::{self, paths, span_lint};
/// _ => false,
/// };
/// ```
declare_clippy_lint! {
pub NEG_CMP_OP_ON_PARTIAL_ORD,
complexity,
"The use of negated comparison operators on partially ordered types may produce confusing code."

View File

@@ -7,6 +7,7 @@ use syntax::source_map::{Span, Spanned};
use crate::consts::{self, Constant};
use crate::utils::span_lint;
declare_clippy_lint! {
/// **What it does:** Checks for multiplication by -1 as a form of negation.
///
/// **Why is this bad?** It's more readable to just negate.
@@ -17,7 +18,6 @@ use crate::utils::span_lint;
/// ```rust
/// x * -1
/// ```
declare_clippy_lint! {
pub NEG_MULTIPLY,
style,
"multiplying integers with -1"

View File

@@ -11,6 +11,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for types with a `fn new() -> Self` method and no
/// implementation of
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html).
@@ -78,7 +79,6 @@ use syntax::source_map::Span;
/// ```
///
/// You can also have `new()` call `Default::default()`.
declare_clippy_lint! {
pub NEW_WITHOUT_DEFAULT,
style,
"`fn new() -> Self` method without `Default` implementation"

View File

@@ -6,6 +6,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use std::ops::Deref;
declare_clippy_lint! {
/// **What it does:** Checks for statements which have no effect.
///
/// **Why is this bad?** Similar to dead code, these statements are actually
@@ -18,12 +19,12 @@ use std::ops::Deref;
/// ```rust
/// 0;
/// ```
declare_clippy_lint! {
pub NO_EFFECT,
complexity,
"statements with no effect"
}
declare_clippy_lint! {
/// **What it does:** Checks for expression statements that can be reduced to a
/// sub-expression.
///
@@ -36,7 +37,6 @@ declare_clippy_lint! {
/// ```rust
/// compute_array()[0];
/// ```
declare_clippy_lint! {
pub UNNECESSARY_OPERATION,
complexity,
"outer expressions with no effect"

View File

@@ -14,6 +14,7 @@ use rustc_typeck::hir_ty_to_ty;
use std::ptr;
use syntax_pos::{Span, DUMMY_SP};
declare_clippy_lint! {
/// **What it does:** Checks for declaration of `const` items which is interior
/// mutable (e.g. contains a `Cell`, `Mutex`, `AtomicXxxx` etc).
///
@@ -44,12 +45,12 @@ use syntax_pos::{Span, DUMMY_SP};
/// STATIC_ATOM.store(9, SeqCst);
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
/// ```
declare_clippy_lint! {
pub DECLARE_INTERIOR_MUTABLE_CONST,
correctness,
"declaring const with interior mutability"
}
declare_clippy_lint! {
/// **What it does:** Checks if `const` items which is interior mutable (e.g.
/// contains a `Cell`, `Mutex`, `AtomicXxxx` etc) has been borrowed directly.
///
@@ -76,7 +77,6 @@ declare_clippy_lint! {
/// STATIC_ATOM.store(9, SeqCst);
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
/// ```
declare_clippy_lint! {
pub BORROW_INTERIOR_MUTABLE_CONST,
correctness,
"referencing const with interior mutability"

View File

@@ -7,6 +7,7 @@ use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;
use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor};
declare_clippy_lint! {
/// **What it does:** Checks for names that are very similar and thus confusing.
///
/// **Why is this bad?** It's hard to distinguish between names that differ only
@@ -19,12 +20,12 @@ use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor};
/// let checked_exp = something;
/// let checked_expr = something_else;
/// ```
declare_clippy_lint! {
pub SIMILAR_NAMES,
pedantic,
"similarly named items and bindings"
}
declare_clippy_lint! {
/// **What it does:** Checks for too many variables whose name consists of a
/// single character.
///
@@ -37,12 +38,12 @@ declare_clippy_lint! {
/// ```rust
/// let (a, b, c, d, e, f, g) = (...);
/// ```
declare_clippy_lint! {
pub MANY_SINGLE_CHAR_NAMES,
style,
"too many single character bindings"
}
declare_clippy_lint! {
/// **What it does:** Checks if you have variables whose name consists of just
/// underscores and digits.
///
@@ -57,7 +58,6 @@ declare_clippy_lint! {
/// let ___1 = 1;
/// let __1___2 = 11;
/// ```
declare_clippy_lint! {
pub JUST_UNDERSCORES_AND_DIGITS,
style,
"unclear name"

View File

@@ -4,6 +4,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:*** Checks for unnecessary `ok()` in if let.
///
/// **Why is this bad?** Calling `ok()` in if let is unnecessary, instead match
@@ -28,7 +29,6 @@ use rustc::{declare_tool_lint, lint_array};
/// }
/// }
/// ```
declare_clippy_lint! {
pub IF_LET_SOME_RESULT,
style,
"usage of `ok()` in `if let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead"

View File

@@ -5,6 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use syntax::ast::LitKind;
use syntax::source_map::{Span, Spanned};
declare_clippy_lint! {
/// **What it does:** Checks for duplicate open options as well as combinations
/// that make no sense.
///
@@ -17,7 +18,6 @@ use syntax::source_map::{Span, Spanned};
/// ```rust
/// OpenOptions::new().read(true).truncate(true)
/// ```
declare_clippy_lint! {
pub NONSENSICAL_OPEN_OPTIONS,
correctness,
"nonsensical combination of options for opening a file"

View File

@@ -4,6 +4,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Detects classic underflow/overflow checks.
///
/// **Why is this bad?** Most classic C underflow/overflow checks will fail in
@@ -15,7 +16,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust
/// a + b < a
/// ```
declare_clippy_lint! {
pub OVERFLOW_CHECK_CONDITIONAL,
complexity,
"overflow checks inspired by C which are likely to panic"

View File

@@ -7,6 +7,7 @@ use syntax::ast::LitKind;
use syntax::ptr::P;
use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for missing parameters in `panic!`.
///
/// **Why is this bad?** Contrary to the `format!` family of macros, there are
@@ -20,12 +21,12 @@ use syntax_pos::Span;
/// ```rust
/// panic!("This `panic!` is probably missing a parameter there: {}");
/// ```
declare_clippy_lint! {
pub PANIC_PARAMS,
style,
"missing parameters in `panic!` calls"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `unimplemented!`.
///
/// **Why is this bad?** This macro should not be present in production code
@@ -36,7 +37,6 @@ declare_clippy_lint! {
/// ```rust
/// unimplemented!();
/// ```
declare_clippy_lint! {
pub UNIMPLEMENTED,
restriction,
"`unimplemented!` should not be present in production code"

View File

@@ -4,6 +4,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
///
/// **Why is this bad?** `PartialEq::ne` is required to always return the
@@ -22,7 +23,6 @@ use rustc::{declare_tool_lint, lint_array};
/// fn ne(&self, other: &Foo) -> bool { !(self == other) }
/// }
/// ```
declare_clippy_lint! {
pub PARTIALEQ_NE_IMPL,
complexity,
"re-implementing `PartialEq::ne`"

View File

@@ -5,6 +5,7 @@ use rustc_errors::Applicability;
use syntax::ast::*;
use syntax::source_map::Spanned;
declare_clippy_lint! {
/// **What it does:** Checks for operations where precedence may be unclear
/// and suggests to add parentheses. Currently it catches the following:
/// * mixed usage of arithmetic and bit shifting/combining operators without
@@ -22,7 +23,6 @@ use syntax::source_map::Spanned;
/// **Example:**
/// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7
/// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1
declare_clippy_lint! {
pub PRECEDENCE,
complexity,
"operations where precedence may be unclear"

View File

@@ -13,6 +13,7 @@ use std::borrow::Cow;
use syntax::source_map::Span;
use syntax_pos::MultiSpan;
declare_clippy_lint! {
/// **What it does:** This lint checks for function arguments of type `&String`
/// or `&Vec` unless the references are mutable. It will also suggest you
/// replace `.clone()` calls with the appropriate `.to_owned()`/`to_string()`
@@ -43,12 +44,12 @@ use syntax_pos::MultiSpan;
/// ```rust
/// fn foo(&Vec<u32>) { .. }
/// ```
declare_clippy_lint! {
pub PTR_ARG,
style,
"fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively"
}
declare_clippy_lint! {
/// **What it does:** This lint checks for equality comparisons with `ptr::null`
///
/// **Why is this bad?** It's easier and more readable to use the inherent
@@ -63,12 +64,12 @@ declare_clippy_lint! {
/// ..
/// }
/// ```
declare_clippy_lint! {
pub CMP_NULL,
style,
"comparing a pointer to a null pointer, suggesting to use `.is_null()` instead."
}
declare_clippy_lint! {
/// **What it does:** This lint checks for functions that take immutable
/// references and return
/// mutable ones.
@@ -88,7 +89,6 @@ declare_clippy_lint! {
/// ```rust
/// fn foo(&Foo) -> &mut Bar { .. }
/// ```
declare_clippy_lint! {
pub MUT_FROM_REF,
correctness,
"fns that create mutable refs from immutable ref args"

View File

@@ -3,6 +3,7 @@ use rustc::{declare_tool_lint, hir, lint, lint_array};
use rustc_errors::Applicability;
use std::fmt;
declare_clippy_lint! {
/// **What it does:** Checks for usage of the `offset` pointer method with a `usize` casted to an
/// `isize`.
///
@@ -33,7 +34,6 @@ use std::fmt;
/// ptr.add(offset);
/// }
/// ```
declare_clippy_lint! {
pub PTR_OFFSET_WITH_CAST,
complexity,
"unneeded pointer offset cast"

View File

@@ -10,6 +10,7 @@ use crate::utils::paths::*;
use crate::utils::{match_def_path, match_type, span_lint_and_then, SpanlessEq};
use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for expressions that could be replaced by the question mark operator
///
/// **Why is this bad?** Question mark usage is more idiomatic
@@ -28,7 +29,6 @@ use rustc_errors::Applicability;
/// ```rust
/// option?;
/// ```
declare_clippy_lint! {
pub QUESTION_MARK,
style,
"checks for expressions that could be replaced by the question mark operator"

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