1
Fork 0

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
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
132 changed files with 5405 additions and 5390 deletions

View file

@ -12,8 +12,9 @@ use walkdir::WalkDir;
lazy_static! { lazy_static! {
static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new( static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new(
r#"(?x) r#"(?x)
declare_clippy_lint!\s*[\{(]\s* declare_clippy_lint!\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<cat>[a-z_]+)\s*,\s* (?P<cat>[a-z_]+)\s*,\s*
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})] "(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
"# "#
@ -22,7 +23,8 @@ lazy_static! {
static ref DEC_DEPRECATED_LINT_RE: Regex = Regex::new( static ref DEC_DEPRECATED_LINT_RE: Regex = Regex::new(
r#"(?x) r#"(?x)
declare_deprecated_lint!\s*[{(]\s* 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*[})] "(?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::ast::{FloatTy, Lit, LitKind};
use syntax::symbol; use syntax::symbol;
declare_clippy_lint! {
/// **What it does:** Checks for floating point literals that approximate /// **What it does:** Checks for floating point literals that approximate
/// constants which are defined in /// constants which are defined in
/// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants) /// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
@ -27,7 +28,6 @@ use syntax::symbol;
/// ```rust /// ```rust
/// let x = 3.14; /// let x = 3.14;
/// ``` /// ```
declare_clippy_lint! {
pub APPROX_CONSTANT, pub APPROX_CONSTANT,
correctness, correctness,
"the approximate of a known float constant (in `std::fXX::consts`)" "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 rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for plain integer arithmetic. /// **What it does:** Checks for plain integer arithmetic.
/// ///
/// **Why is this bad?** This is only checked against overflow in debug builds. /// **Why is this bad?** This is only checked against overflow in debug builds.
@ -17,12 +18,12 @@ use syntax::source_map::Span;
/// ```rust /// ```rust
/// a + 1 /// a + 1
/// ``` /// ```
declare_clippy_lint! {
pub INTEGER_ARITHMETIC, pub INTEGER_ARITHMETIC,
restriction, restriction,
"any integer arithmetic statement" "any integer arithmetic statement"
} }
declare_clippy_lint! {
/// **What it does:** Checks for float arithmetic. /// **What it does:** Checks for float arithmetic.
/// ///
/// **Why is this bad?** For some embedded systems or kernel development, it /// **Why is this bad?** For some embedded systems or kernel development, it
@ -34,7 +35,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// a + 1.0 /// a + 1.0
/// ``` /// ```
declare_clippy_lint! {
pub FLOAT_ARITHMETIC, pub FLOAT_ARITHMETIC,
restriction, restriction,
"any floating-point arithmetic statement" "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 crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
use if_chain::if_chain; use if_chain::if_chain;
declare_clippy_lint! {
/// **What it does:** Check to call assert!(true/false) /// **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 /// **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; /// const B: bool = false;
/// assert!(B) /// assert!(B)
/// ``` /// ```
declare_clippy_lint! {
pub ASSERTIONS_ON_CONSTANTS, pub ASSERTIONS_ON_CONSTANTS,
style, style,
"assert!(true/false) will be optimized out by the compiler/should probably be replaced by a panic!() or unreachable!()" "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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` /// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
/// patterns. /// patterns.
/// ///
@ -21,12 +22,12 @@ use rustc_errors::Applicability;
/// ... /// ...
/// a = a + b; /// a = a + b;
/// ``` /// ```
declare_clippy_lint! {
pub ASSIGN_OP_PATTERN, pub ASSIGN_OP_PATTERN,
style, style,
"assigning the result of an operation on a variable to that same variable" "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. /// **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 /// **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; /// a += a + b;
/// ``` /// ```
declare_clippy_lint! {
pub MISREFACTORED_ASSIGN_OP, pub MISREFACTORED_ASSIGN_OP,
complexity, complexity,
"having a variable on both sides of an assign op" "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::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for items annotated with `#[inline(always)]`, /// **What it does:** Checks for items annotated with `#[inline(always)]`,
/// unless the annotated function is empty or simply panics. /// unless the annotated function is empty or simply panics.
/// ///
@ -37,12 +38,12 @@ use syntax::source_map::Span;
/// #[inline(always)] /// #[inline(always)]
/// fn not_quite_hot_code(..) { ... } /// fn not_quite_hot_code(..) { ... }
/// ``` /// ```
declare_clippy_lint! {
pub INLINE_ALWAYS, pub INLINE_ALWAYS,
pedantic, pedantic,
"use of `#[inline(always)]`" "use of `#[inline(always)]`"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `extern crate` and `use` items annotated with /// **What it does:** Checks for `extern crate` and `use` items annotated with
/// lint attributes. /// lint attributes.
/// ///
@ -70,12 +71,12 @@ declare_clippy_lint! {
/// #[macro_use] /// #[macro_use]
/// extern crate baz; /// extern crate baz;
/// ``` /// ```
declare_clippy_lint! {
pub USELESS_ATTRIBUTE, pub USELESS_ATTRIBUTE,
correctness, correctness,
"use of lint attributes on `extern crate` items" "use of lint attributes on `extern crate` items"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `#[deprecated]` annotations with a `since` /// **What it does:** Checks for `#[deprecated]` annotations with a `since`
/// field that is not a valid semantic version. /// field that is not a valid semantic version.
/// ///
@ -89,12 +90,12 @@ declare_clippy_lint! {
/// #[deprecated(since = "forever")] /// #[deprecated(since = "forever")]
/// fn something_else(..) { ... } /// fn something_else(..) { ... }
/// ``` /// ```
declare_clippy_lint! {
pub DEPRECATED_SEMVER, pub DEPRECATED_SEMVER,
correctness, correctness,
"use of `#[deprecated(since = \"x\")]` where x is not semver" "use of `#[deprecated(since = \"x\")]` where x is not semver"
} }
declare_clippy_lint! {
/// **What it does:** Checks for empty lines after outer attributes /// **What it does:** Checks for empty lines after outer attributes
/// ///
/// **Why is this bad?** /// **Why is this bad?**
@ -124,12 +125,12 @@ declare_clippy_lint! {
/// #[inline(always)] /// #[inline(always)]
/// fn this_is_fine_too(..) { ... } /// fn this_is_fine_too(..) { ... }
/// ``` /// ```
declare_clippy_lint! {
pub EMPTY_LINE_AFTER_OUTER_ATTR, pub EMPTY_LINE_AFTER_OUTER_ATTR,
nursery, nursery,
"empty line after outer attribute" "empty line after outer attribute"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy /// **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 /// 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 /// (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)] /// #![warn(if_not_else)]
/// #![deny(clippy::all)] /// #![deny(clippy::all)]
/// ``` /// ```
declare_clippy_lint! {
pub UNKNOWN_CLIPPY_LINTS, pub UNKNOWN_CLIPPY_LINTS,
style, style,
"unknown_lints for scoped Clippy lints" "unknown_lints for scoped Clippy lints"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it /// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
/// with `#[rustfmt::skip]`. /// with `#[rustfmt::skip]`.
/// ///
@ -180,7 +181,6 @@ declare_clippy_lint! {
/// #[rustfmt::skip] /// #[rustfmt::skip]
/// fn main() { } /// fn main() { }
/// ``` /// ```
declare_clippy_lint! {
pub DEPRECATED_CFG_ATTR, pub DEPRECATED_CFG_ATTR,
complexity, complexity,
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`" "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::ast::LitKind;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for incompatible bit masks in comparisons. /// **What it does:** Checks for incompatible bit masks in comparisons.
/// ///
/// The formula for detecting if an expression of the type `_ <bit_op> m /// The formula for detecting if an expression of the type `_ <bit_op> m
@ -39,12 +40,12 @@ use syntax::source_map::Span;
/// ```rust /// ```rust
/// if (x & 1 == 2) { … } /// if (x & 1 == 2) { … }
/// ``` /// ```
declare_clippy_lint! {
pub BAD_BIT_MASK, pub BAD_BIT_MASK,
correctness, correctness,
"expressions of the form `_ & mask == select` that will only ever return `true` or `false`" "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 /// **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 /// without changing the outcome. The basic structure can be seen in the
/// following table: /// following table:
@ -67,12 +68,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// if (x | 1 > 3) { … } /// if (x | 1 > 3) { … }
/// ``` /// ```
declare_clippy_lint! {
pub INEFFECTIVE_BIT_MASK, pub INEFFECTIVE_BIT_MASK,
correctness, correctness,
"expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`" "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 /// **What it does:** Checks for bit masks that can be replaced by a call
/// to `trailing_zeros` /// to `trailing_zeros`
/// ///
@ -85,7 +86,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// x & 0x1111 == 0 /// x & 0x1111 == 0
/// ``` /// ```
declare_clippy_lint! {
pub VERBOSE_BIT_MASK, pub VERBOSE_BIT_MASK,
style, style,
"expressions where a bit mask is less readable than the corresponding method call" "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::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
declare_clippy_lint! {
/// **What it does:** Checks for usage of blacklisted names for variables, such /// **What it does:** Checks for usage of blacklisted names for variables, such
/// as `foo`. /// as `foo`.
/// ///
@ -16,7 +17,6 @@ use rustc_data_structures::fx::FxHashSet;
/// ```rust /// ```rust
/// let foo = 3.14; /// let foo = 3.14;
/// ``` /// ```
declare_clippy_lint! {
pub BLACKLISTED_NAME, pub BLACKLISTED_NAME,
style, style,
"usage of a blacklisted/placeholder name" "usage of a blacklisted/placeholder name"

View file

@ -5,6 +5,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for `if` conditions that use blocks to contain an /// **What it does:** Checks for `if` conditions that use blocks to contain an
/// expression. /// expression.
/// ///
@ -17,12 +18,12 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust /// ```rust
/// if { true } .. /// if { true } ..
/// ``` /// ```
declare_clippy_lint! {
pub BLOCK_IN_IF_CONDITION_EXPR, pub BLOCK_IN_IF_CONDITION_EXPR,
style, style,
"braces that can be eliminated in conditions, e.g. `if { true } ...`" "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 /// **What it does:** Checks for `if` conditions that use blocks containing
/// statements, or conditions that use closures with blocks. /// statements, or conditions that use closures with blocks.
/// ///
@ -36,7 +37,6 @@ declare_clippy_lint! {
/// // or /// // or
/// if somefunc(|x| { x == 47 }) .. /// if somefunc(|x| { x == 47 }) ..
/// ``` /// ```
declare_clippy_lint! {
pub BLOCK_IN_IF_CONDITION_STMT, pub BLOCK_IN_IF_CONDITION_STMT,
style, style,
"complex blocks in conditions, e.g. `if { let x = true; x } ...`" "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::ast::LitKind;
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP}; use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
declare_clippy_lint! {
/// **What it does:** Checks for boolean expressions that can be written more /// **What it does:** Checks for boolean expressions that can be written more
/// concisely. /// concisely.
/// ///
@ -24,12 +25,12 @@ use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
/// if a && true // should be: if a /// if a && true // should be: if a
/// if !(a == b) // should be: if a != b /// if !(a == b) // should be: if a != b
/// ``` /// ```
declare_clippy_lint! {
pub NONMINIMAL_BOOL, pub NONMINIMAL_BOOL,
complexity, complexity,
"boolean expressions that can be written more concisely" "boolean expressions that can be written more concisely"
} }
declare_clippy_lint! {
/// **What it does:** Checks for boolean expressions that contain terminals that /// **What it does:** Checks for boolean expressions that contain terminals that
/// can be eliminated. /// can be eliminated.
/// ///
@ -42,7 +43,6 @@ declare_clippy_lint! {
/// if a && b || a { ... } /// if a && b || a { ... }
/// ``` /// ```
/// The `b` is unnecessary, the expression is equivalent to `if a`. /// The `b` is unnecessary, the expression is equivalent to `if a`.
declare_clippy_lint! {
pub LOGIC_BUG, pub LOGIC_BUG,
correctness, correctness,
"boolean expressions that contain terminals which can be eliminated" "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 rustc_errors::Applicability;
use syntax::ast::{Name, UintTy}; use syntax::ast::{Name, UintTy};
declare_clippy_lint! {
/// **What it does:** Checks for naive byte counts /// **What it does:** Checks for naive byte counts
/// ///
/// **Why is this bad?** The [`bytecount`](https://crates.io/crates/bytecount) /// **Why is this bad?** The [`bytecount`](https://crates.io/crates/bytecount)
@ -25,7 +26,6 @@ use syntax::ast::{Name, UintTy};
/// ```rust /// ```rust
/// &my_data.filter(|&x| x == 0u8).count() // use bytecount::count instead /// &my_data.filter(|&x| x == 0u8).count() // use bytecount::count instead
/// ``` /// ```
declare_clippy_lint! {
pub NAIVE_BYTECOUNT, pub NAIVE_BYTECOUNT,
perf, perf,
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values" "use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"

View file

@ -7,6 +7,7 @@ use syntax::{ast::*, source_map::DUMMY_SP};
use cargo_metadata; use cargo_metadata;
declare_clippy_lint! {
/// **What it does:** Checks to see if all common metadata is defined in /// **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 /// `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"] /// keywords = ["clippy", "lint", "plugin"]
/// categories = ["development-tools", "development-tools::cargo-plugins"] /// categories = ["development-tools", "development-tools::cargo-plugins"]
/// ``` /// ```
declare_clippy_lint! {
pub CARGO_COMMON_METADATA, pub CARGO_COMMON_METADATA,
cargo, cargo,
"common metadata is defined in `Cargo.toml`" "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 crate::utils::{in_macro, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for nested `if` statements which can be collapsed /// **What it does:** Checks for nested `if` statements which can be collapsed
/// by `&&`-combining their conditions and for `else { if ... }` expressions /// by `&&`-combining their conditions and for `else { if ... }` expressions
/// that /// that
@ -65,7 +66,6 @@ use rustc_errors::Applicability;
/// … /// …
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub COLLAPSIBLE_IF, pub COLLAPSIBLE_IF,
style, style,
"`if`s that can be collapsed (e.g. `if x { if y { ... } }` and `else { if x { ... } }`)" "`if`s that can be collapsed (e.g. `if x { if y { ... } }` and `else { if x { ... } }`)"

View file

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

View file

@ -10,6 +10,7 @@ use std::collections::hash_map::Entry;
use std::hash::BuildHasherDefault; use std::hash::BuildHasherDefault;
use syntax::symbol::LocalInternedString; use syntax::symbol::LocalInternedString;
declare_clippy_lint! {
/// **What it does:** Checks for consecutive `if`s with the same condition. /// **What it does:** Checks for consecutive `if`s with the same condition.
/// ///
/// **Why is this bad?** This is probably a copy & paste error. /// **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, pub IFS_SAME_COND,
correctness, correctness,
"consecutive `ifs` with the same condition" "consecutive `ifs` with the same condition"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `if/else` with the same body as the *then* part /// **What it does:** Checks for `if/else` with the same body as the *then* part
/// and the *else* part. /// and the *else* part.
/// ///
@ -56,12 +57,12 @@ declare_clippy_lint! {
/// 42 /// 42
/// }; /// };
/// ``` /// ```
declare_clippy_lint! {
pub IF_SAME_THEN_ELSE, pub IF_SAME_THEN_ELSE,
correctness, correctness,
"if with the same *then* and *else* blocks" "if with the same *then* and *else* blocks"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `match` with identical arm bodies. /// **What it does:** Checks for `match` with identical arm bodies.
/// ///
/// **Why is this bad?** This is probably a copy & paste error. If 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(), /// Quz => quz(),
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MATCH_SAME_ARMS, pub MATCH_SAME_ARMS,
pedantic, pedantic,
"`match` with identical arm bodies" "`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::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for types that implement `Copy` as well as /// **What it does:** Checks for types that implement `Copy` as well as
/// `Iterator`. /// `Iterator`.
/// ///
@ -23,7 +24,6 @@ use rustc::{declare_tool_lint, lint_array};
/// let a: Vec<_> = my_iterator.take(1).collect(); /// let a: Vec<_> = my_iterator.take(1).collect();
/// let b: Vec<_> = my_iterator.collect(); /// let b: Vec<_> = my_iterator.collect();
/// ``` /// ```
declare_clippy_lint! {
pub COPY_ITERATOR, pub COPY_ITERATOR,
pedantic, pedantic,
"implementing `Iterator` on a `Copy` type" "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}; 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. /// **What it does:** Checks for methods with high cyclomatic complexity.
/// ///
/// **Why is this bad?** Methods of high cyclomatic complexity tend to be badly /// **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. /// complexity.
/// ///
/// **Example:** No. You'll see it when you get the warning. /// **Example:** No. You'll see it when you get the warning.
declare_clippy_lint! {
pub CYCLOMATIC_COMPLEXITY, pub CYCLOMATIC_COMPLEXITY,
complexity, complexity,
"functions that should be split up into multiple functions" "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::source_map::Span;
use syntax::tokenstream::TokenStream; use syntax::tokenstream::TokenStream;
declare_clippy_lint! {
/// **What it does:** Checks for usage of dbg!() macro. /// **What it does:** Checks for usage of dbg!() macro.
/// ///
/// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It /// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It
@ -21,7 +22,6 @@ use syntax::tokenstream::TokenStream;
/// // Good /// // Good
/// true /// true
/// ``` /// ```
declare_clippy_lint! {
pub DBG_MACRO, pub DBG_MACRO,
restriction, restriction,
"`dbg!` macro is intended as a debugging tool" "`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}; 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()`. /// **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 /// **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 /// // Good
/// let s = String::default(); /// let s = String::default();
/// ``` /// ```
declare_clippy_lint! {
pub DEFAULT_TRAIT_ACCESS, pub DEFAULT_TRAIT_ACCESS,
pedantic, pedantic,
"checks for literal calls to Default::default()" "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 rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
/// explicitly or vice versa. /// explicitly or vice versa.
/// ///
@ -30,12 +31,12 @@ use syntax::source_map::Span;
/// ... /// ...
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub DERIVE_HASH_XOR_EQ, pub DERIVE_HASH_XOR_EQ,
correctness, correctness,
"deriving `Hash` but implementing `PartialEq` explicitly" "deriving `Hash` but implementing `PartialEq` explicitly"
} }
declare_clippy_lint! {
/// **What it does:** Checks for explicit `Clone` implementations for `Copy` /// **What it does:** Checks for explicit `Clone` implementations for `Copy`
/// types. /// types.
/// ///
@ -56,7 +57,6 @@ declare_clippy_lint! {
/// .. /// ..
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub EXPL_IMPL_CLONE_ON_COPY, pub EXPL_IMPL_CLONE_ON_COPY,
pedantic, pedantic,
"implementing `Clone` explicitly on `Copy` types" "implementing `Clone` explicitly on `Copy` types"

View file

@ -9,6 +9,7 @@ use syntax::source_map::{BytePos, Span};
use syntax_pos::Pos; use syntax_pos::Pos;
use url::Url; use url::Url;
declare_clippy_lint! {
/// **What it does:** Checks for the presence of `_`, `::` or camel-case words /// **What it does:** Checks for the presence of `_`, `::` or camel-case words
/// outside ticks in documentation. /// outside ticks in documentation.
/// ///
@ -27,7 +28,6 @@ use url::Url;
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked. /// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
/// fn doit(foo_bar) { .. } /// fn doit(foo_bar) { .. }
/// ``` /// ```
declare_clippy_lint! {
pub DOC_MARKDOWN, pub DOC_MARKDOWN,
pedantic, pedantic,
"presence of `_`, `::` or camel-case outside backticks in documentation" "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}; 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. /// **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 /// ```rust
/// x <= y /// x <= y
/// ``` /// ```
declare_clippy_lint! {
pub DOUBLE_COMPARISONS, pub DOUBLE_COMPARISONS,
complexity, complexity,
"unnecessary double comparisons that can be simplified" "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 rustc::{declare_tool_lint, lint_array};
use syntax::ast::*; use syntax::ast::*;
declare_clippy_lint! {
/// **What it does:** Checks for unnecessary double parentheses. /// **What it does:** Checks for unnecessary double parentheses.
/// ///
/// **Why is this bad?** This makes code harder to read and might indicate a /// **Why is this bad?** This makes code harder to read and might indicate a
@ -16,7 +17,6 @@ use syntax::ast::*;
/// foo((0)) /// foo((0))
/// ((1, 2)) /// ((1, 2))
/// ``` /// ```
declare_clippy_lint! {
pub DOUBLE_PARENS, pub DOUBLE_PARENS,
complexity, complexity,
"Warn on unnecessary double parentheses" "Warn on unnecessary double parentheses"

View file

@ -4,6 +4,7 @@ use rustc::hir::*;
use rustc::lint::{LateLintPass, LintArray, LintPass}; use rustc::lint::{LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for generics with `std::ops::Drop` as bounds. /// **What it does:** Checks for generics with `std::ops::Drop` as bounds.
/// ///
/// **Why is this bad?** `Drop` bounds do not really accomplish anything. /// **Why is this bad?** `Drop` bounds do not really accomplish anything.
@ -26,7 +27,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust /// ```rust
/// fn foo<T: Drop>() {} /// fn foo<T: Drop>() {}
/// ``` /// ```
declare_clippy_lint! {
pub DROP_BOUNDS, pub DROP_BOUNDS,
correctness, correctness,
"Bounds of the form `T: Drop` are useless" "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::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for calls to `std::mem::drop` with a reference /// **What it does:** Checks for calls to `std::mem::drop` with a reference
/// instead of an owned value. /// instead of an owned value.
/// ///
@ -22,12 +23,12 @@ use rustc::{declare_tool_lint, lint_array};
/// // still locked /// // still locked
/// operation_that_requires_mutex_to_be_unlocked(); /// operation_that_requires_mutex_to_be_unlocked();
/// ``` /// ```
declare_clippy_lint! {
pub DROP_REF, pub DROP_REF,
correctness, correctness,
"calls to `std::mem::drop` with a reference instead of an owned value" "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 /// **What it does:** Checks for calls to `std::mem::forget` with a reference
/// instead of an owned value. /// instead of an owned value.
/// ///
@ -43,12 +44,12 @@ declare_clippy_lint! {
/// let x = Box::new(1); /// let x = Box::new(1);
/// std::mem::forget(&x) // Should have been forget(x), x will still be dropped /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped
/// ``` /// ```
declare_clippy_lint! {
pub FORGET_REF, pub FORGET_REF,
correctness, correctness,
"calls to `std::mem::forget` with a reference instead of an owned value" "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 /// **What it does:** Checks for calls to `std::mem::drop` with a value
/// that derives the Copy trait /// 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 /// std::mem::drop(x) // A copy of x is passed to the function, leaving the
/// // original unaffected /// // original unaffected
/// ``` /// ```
declare_clippy_lint! {
pub DROP_COPY, pub DROP_COPY,
correctness, correctness,
"calls to `std::mem::drop` with a value that implements Copy" "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 /// **What it does:** Checks for calls to `std::mem::forget` with a value that
/// derives the Copy trait /// 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 /// std::mem::forget(x) // A copy of x is passed to the function, leaving the
/// // original unaffected /// // original unaffected
/// ``` /// ```
declare_clippy_lint! {
pub FORGET_COPY, pub FORGET_COPY,
correctness, correctness,
"calls to `std::mem::forget` with a value that implements Copy" "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::paths;
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg, walk_ptrs_ty}; 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 /// **What it does:** Checks for calculation of subsecond microseconds or milliseconds
/// from other `Duration` methods. /// 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 _micros = dur.subsec_nanos() / 1_000;
/// let _millis = dur.subsec_nanos() / 1_000_000; /// let _millis = dur.subsec_nanos() / 1_000_000;
/// ``` /// ```
declare_clippy_lint! {
pub DURATION_SUBSEC, pub DURATION_SUBSEC,
complexity, complexity,
"checks for calculation of subsecond microseconds or milliseconds" "checks for calculation of subsecond microseconds or milliseconds"

View file

@ -6,6 +6,7 @@ use syntax::ast::*;
use crate::utils::span_help_and_lint; use crate::utils::span_help_and_lint;
declare_clippy_lint! {
/// **What it does:** Checks for usage of if expressions with an `else if` branch, /// **What it does:** Checks for usage of if expressions with an `else if` branch,
/// but without a final `else` branch. /// but without a final `else` branch.
/// ///
@ -33,7 +34,6 @@ use crate::utils::span_help_and_lint;
/// // we don't care about zero /// // we don't care about zero
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub ELSE_IF_WITHOUT_ELSE, pub ELSE_IF_WITHOUT_ELSE,
restriction, restriction,
"if expression with an `else if`, but without a final `else` branch" "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::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for `enum`s with no variants. /// **What it does:** Checks for `enum`s with no variants.
/// ///
/// **Why is this bad?** Enum's with no variants should be replaced with `!`, /// **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 /// ```rust
/// enum Test {} /// enum Test {}
/// ``` /// ```
declare_clippy_lint! {
pub EMPTY_ENUM, pub EMPTY_ENUM,
pedantic, pedantic,
"enum with no variants" "enum with no variants"

View file

@ -8,6 +8,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap` /// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap`
/// or `BTreeMap`. /// or `BTreeMap`.
/// ///
@ -31,7 +32,6 @@ use syntax::source_map::Span;
/// ```rust /// ```rust
/// m.entry(k).or_insert(v); /// m.entry(k).or_insert(v);
/// ``` /// ```
declare_clippy_lint! {
pub MAP_ENTRY, pub MAP_ENTRY,
perf, perf,
"use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`" "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 rustc::{declare_tool_lint, lint_array};
use syntax::ast::{IntTy, UintTy}; use syntax::ast::{IntTy, UintTy};
declare_clippy_lint! {
/// **What it does:** Checks for C-like enumerations that are /// **What it does:** Checks for C-like enumerations that are
/// `repr(isize/usize)` and have values that don't fit into an `i32`. /// `repr(isize/usize)` and have values that don't fit into an `i32`.
/// ///
@ -28,7 +29,6 @@ use syntax::ast::{IntTy, UintTy};
/// Y = 0, /// Y = 0,
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub ENUM_CLIKE_UNPORTABLE_VARIANT, pub ENUM_CLIKE_UNPORTABLE_VARIANT,
correctness, correctness,
"C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`" "C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`"

View file

@ -7,6 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for `use Enum::*`. /// **What it does:** Checks for `use Enum::*`.
/// ///
/// **Why is this bad?** It is usually better style to use the prefixed name of /// **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 /// ```rust
/// use std::cmp::Ordering::*; /// use std::cmp::Ordering::*;
/// ``` /// ```
declare_clippy_lint! {
pub ENUM_GLOB_USE, pub ENUM_GLOB_USE,
pedantic, pedantic,
"use items that import all variants of an enum" "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::source_map::Span;
use syntax::symbol::{InternedString, LocalInternedString}; use syntax::symbol::{InternedString, LocalInternedString};
declare_clippy_lint! {
/// **What it does:** Detects enumeration variants that are prefixed or suffixed /// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters. /// by the same characters.
/// ///
@ -24,12 +25,12 @@ use syntax::symbol::{InternedString, LocalInternedString};
/// BattenbergCake, /// BattenbergCake,
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub ENUM_VARIANT_NAMES, pub ENUM_VARIANT_NAMES,
style, style,
"enums where all variants share a prefix/postfix" "enums where all variants share a prefix/postfix"
} }
declare_clippy_lint! {
/// **What it does:** Detects enumeration variants that are prefixed or suffixed /// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters. /// by the same characters.
/// ///
@ -46,12 +47,12 @@ declare_clippy_lint! {
/// BattenbergCake, /// BattenbergCake,
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub PUB_ENUM_VARIANT_NAMES, pub PUB_ENUM_VARIANT_NAMES,
pedantic, pedantic,
"enums where all variants share a prefix/postfix" "enums where all variants share a prefix/postfix"
} }
declare_clippy_lint! {
/// **What it does:** Detects type names that are prefixed or suffixed by the /// **What it does:** Detects type names that are prefixed or suffixed by the
/// containing module's name. /// containing module's name.
/// ///
@ -65,12 +66,12 @@ declare_clippy_lint! {
/// struct BlackForestCake; /// struct BlackForestCake;
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MODULE_NAME_REPETITIONS, pub MODULE_NAME_REPETITIONS,
pedantic, pedantic,
"type names prefixed/postfixed with their containing module's name" "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 /// **What it does:** Checks for modules that have the same name as their
/// parent module /// parent module
/// ///
@ -95,7 +96,6 @@ declare_clippy_lint! {
/// ... /// ...
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MODULE_INCEPTION, pub MODULE_INCEPTION,
style, style,
"modules that have the same name as their parent module" "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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for equal operands to comparison, logical and /// **What it does:** Checks for equal operands to comparison, logical and
/// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`, /// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`,
/// `||`, `&`, `|`, `^`, `-` and `/`). /// `||`, `&`, `|`, `^`, `-` and `/`).
@ -21,12 +22,12 @@ use rustc_errors::Applicability;
/// ```rust /// ```rust
/// x + 1 == x + 1 /// x + 1 == x + 1
/// ``` /// ```
declare_clippy_lint! {
pub EQ_OP, pub EQ_OP,
correctness, correctness,
"equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)" "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 /// **What it does:** Checks for arguments to `==` which have their address
/// taken to satisfy a bound /// taken to satisfy a bound
/// and suggests to dereference the other argument instead /// and suggests to dereference the other argument instead
@ -39,7 +40,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// &x == y /// &x == y
/// ``` /// ```
declare_clippy_lint! {
pub OP_REF, pub OP_REF,
style, style,
"taking a reference to satisfy the type constraints on `==`" "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 rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for erasing operations, e.g. `x * 0`. /// **What it does:** Checks for erasing operations, e.g. `x * 0`.
/// ///
/// **Why is this bad?** The whole expression can be replaced by zero. /// **Why is this bad?** The whole expression can be replaced by zero.
@ -19,7 +20,6 @@ use syntax::source_map::Span;
/// 0 * x; /// 0 * x;
/// x & 0 /// x & 0
/// ``` /// ```
declare_clippy_lint! {
pub ERASING_OP, pub ERASING_OP,
correctness, correctness,
"using erasing operations, e.g. `x * 0` or `y & 0`" "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, pub too_large_for_stack: u64,
} }
declare_clippy_lint! {
/// **What it does:** Checks for usage of `Box<T>` where an unboxed `T` would /// **What it does:** Checks for usage of `Box<T>` where an unboxed `T` would
/// work fine. /// work fine.
/// ///
@ -31,7 +32,6 @@ pub struct Pass {
/// println!("{}", *x); /// println!("{}", *x);
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub BOXED_LOCAL, pub BOXED_LOCAL,
perf, perf,
"using `Box<T>` where unnecessary" "using `Box<T>` where unnecessary"

View file

@ -8,6 +8,7 @@ use rustc_errors::Applicability;
pub struct EtaPass; pub struct EtaPass;
declare_clippy_lint! {
/// **What it does:** Checks for closures which just call another function where /// **What it does:** Checks for closures which just call another function where
/// the function can be called directly. `unsafe` functions or calls where types /// the function can be called directly. `unsafe` functions or calls where types
/// get adjusted are ignored. /// get adjusted are ignored.
@ -27,7 +28,6 @@ pub struct EtaPass;
/// ``` /// ```
/// where `foo(_)` is a plain function that takes the exact argument type of /// where `foo(_)` is a plain function that takes the exact argument type of
/// `x`. /// `x`.
declare_clippy_lint! {
pub REDUNDANT_CLOSURE, pub REDUNDANT_CLOSURE,
style, style,
"redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)" "redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)"

View file

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

View file

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

View file

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

View file

@ -7,6 +7,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()` /// **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. /// **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, pub FALLIBLE_IMPL_FROM,
nursery, nursery,
"Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`" "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::ast::LitKind;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for the use of `format!("string literal with no /// **What it does:** Checks for the use of `format!("string literal with no
/// argument")` and `format!("{}", foo)` where `foo` is a string. /// argument")` and `format!("{}", foo)` where `foo` is a string.
/// ///
@ -28,7 +29,6 @@ use syntax::source_map::Span;
/// format!("foo") /// format!("foo")
/// format!("{}", foo) /// format!("{}", foo)
/// ``` /// ```
declare_clippy_lint! {
pub USELESS_FORMAT, pub USELESS_FORMAT,
complexity, complexity,
"useless use of `format!`" "useless use of `format!`"

View file

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

View file

@ -11,6 +11,7 @@ use rustc_target::spec::abi::Abi;
use syntax::ast; use syntax::ast;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for functions with too many parameters. /// **What it does:** Checks for functions with too many parameters.
/// ///
/// **Why is this bad?** Functions with lots of parameters are considered bad /// **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, pub TOO_MANY_ARGUMENTS,
complexity, complexity,
"functions with too many arguments" "functions with too many arguments"
} }
declare_clippy_lint! {
/// **What it does:** Checks for functions with a large amount of lines. /// **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 /// **Why is this bad?** Functions with a lot of lines are harder to understand
@ -48,12 +49,12 @@ declare_clippy_lint! {
/// println!(""); /// println!("");
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub TOO_MANY_LINES, pub TOO_MANY_LINES,
pedantic, pedantic,
"functions with too many lines" "functions with too many lines"
} }
declare_clippy_lint! {
/// **What it does:** Checks for public functions that dereferences raw pointer /// **What it does:** Checks for public functions that dereferences raw pointer
/// arguments but are not marked unsafe. /// arguments but are not marked unsafe.
/// ///
@ -76,7 +77,6 @@ declare_clippy_lint! {
/// println!("{}", unsafe { *x }); /// println!("{}", unsafe { *x });
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NOT_UNSAFE_PTR_ARG_DEREF, pub NOT_UNSAFE_PTR_ARG_DEREF,
correctness, correctness,
"public functions dereferencing raw pointer arguments but not marked `unsafe`" "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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions. /// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions.
/// ///
/// **Why is this bad?** Redundant code. /// **Why is this bad?** Redundant code.
@ -18,7 +19,6 @@ use rustc_errors::Applicability;
/// // format!() returns a `String` /// // format!() returns a `String`
/// let s: String = format!("hello").into(); /// let s: String = format!("hello").into();
/// ``` /// ```
declare_clippy_lint! {
pub IDENTITY_CONVERSION, pub IDENTITY_CONVERSION,
complexity, complexity,
"using always-identical `Into`/`From`/`IntoIter` conversions" "using always-identical `Into`/`From`/`IntoIter` conversions"

View file

@ -6,6 +6,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for identity operations, e.g. `x + 0`. /// **What it does:** Checks for identity operations, e.g. `x + 0`.
/// ///
/// **Why is this bad?** This code can be removed without changing the /// **Why is this bad?** This code can be removed without changing the
@ -17,7 +18,6 @@ use syntax::source_map::Span;
/// ```rust /// ```rust
/// x / 1 + 0 * 1 - 0 | 0 /// x / 1 + 0 * 1 - 0 | 0
/// ``` /// ```
declare_clippy_lint! {
pub IDENTITY_OP, pub IDENTITY_OP,
complexity, complexity,
"using identity operations, e.g. `x + 0` or `y / 1`" "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; use crate::utils::span_help_and_lint;
declare_clippy_lint! {
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an /// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
/// else branch. /// else branch.
/// ///
@ -32,7 +33,6 @@ use crate::utils::span_help_and_lint;
/// a() /// a()
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub IF_NOT_ELSE, pub IF_NOT_ELSE,
pedantic, pedantic,
"`if` branches that could be swapped so no negation operation is necessary on the condition" "`if` branches that could be swapped so no negation operation is necessary on the condition"

View file

@ -5,6 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for missing return statements at the end of a block. /// **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 /// **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; /// return x;
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub IMPLICIT_RETURN, pub IMPLICIT_RETURN,
restriction, restriction,
"use a return statement like `return expr` instead of an expression" "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 rustc::{declare_tool_lint, lint_array};
use syntax::ast::RangeLimits; use syntax::ast::RangeLimits;
declare_clippy_lint! {
/// **What it does:** Checks for out of bounds array indexing with a constant /// **What it does:** Checks for out of bounds array indexing with a constant
/// index. /// index.
/// ///
@ -29,12 +30,12 @@ use syntax::ast::RangeLimits;
/// x[0]; /// x[0];
/// x[3]; /// x[3];
/// ``` /// ```
declare_clippy_lint! {
pub OUT_OF_BOUNDS_INDEXING, pub OUT_OF_BOUNDS_INDEXING,
correctness, correctness,
"out of bounds constant indexing" "out of bounds constant indexing"
} }
declare_clippy_lint! {
/// **What it does:** Checks for usage of indexing or slicing. Arrays are special cased, this 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 /// 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. /// 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(10..);
/// y.get(..100); /// y.get(..100);
/// ``` /// ```
declare_clippy_lint! {
pub INDEXING_SLICING, pub INDEXING_SLICING,
restriction, restriction,
"indexing/slicing usage" "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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for matches being used to destructure a single-variant enum /// **What it does:** Checks for matches being used to destructure a single-variant enum
/// or tuple struct where a `let` will suffice. /// or tuple struct where a `let` will suffice.
/// ///
@ -34,7 +35,6 @@ use rustc_errors::Applicability;
/// let wrapper = Wrapper::Data(42); /// let wrapper = Wrapper::Data(42);
/// let Wrapper::Data(data) = wrapper; /// let Wrapper::Data(data) = wrapper;
/// ``` /// ```
declare_clippy_lint! {
pub INFALLIBLE_DESTRUCTURING_MATCH, pub INFALLIBLE_DESTRUCTURING_MATCH,
style, style,
"a match statement with a single infallible arm instead of a `let`" "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::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for iteration that is guaranteed to be infinite. /// **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 /// **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 /// ```rust
/// repeat(1_u8).iter().collect::<Vec<_>>() /// repeat(1_u8).iter().collect::<Vec<_>>()
/// ``` /// ```
declare_clippy_lint! {
pub INFINITE_ITER, pub INFINITE_ITER,
correctness, correctness,
"infinite iteration" "infinite iteration"
} }
declare_clippy_lint! {
/// **What it does:** Checks for iteration that may be infinite. /// **What it does:** Checks for iteration that may be infinite.
/// ///
/// **Why is this bad?** While there may be places where this is acceptable /// **Why is this bad?** While there may be places where this is acceptable
@ -32,7 +33,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// [0..].iter().zip(infinite_iter.take_while(|x| x > 5)) /// [0..].iter().zip(infinite_iter.take_while(|x| x > 5))
/// ``` /// ```
declare_clippy_lint! {
pub MAYBE_INFINITE_ITER, pub MAYBE_INFINITE_ITER,
pedantic, pedantic,
"possible infinite iteration" "possible infinite iteration"

View file

@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashMap;
use std::default::Default; use std::default::Default;
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for multiple inherent implementations of a struct /// **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. /// **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() {} /// fn other() {}
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MULTIPLE_INHERENT_IMPL, pub MULTIPLE_INHERENT_IMPL,
restriction, restriction,
"Multiple inherent impl that could be grouped" "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 rustc_errors::Applicability;
use syntax::ast::{Attribute, Name}; use syntax::ast::{Attribute, Name};
declare_clippy_lint! {
/// **What it does:** Checks for `#[inline]` on trait methods without bodies /// **What it does:** Checks for `#[inline]` on trait methods without bodies
/// ///
/// **Why is this bad?** Only implementations of trait methods may be inlined. /// **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; /// fn name(&self) -> &'static str;
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub INLINE_FN_WITHOUT_BODY, pub INLINE_FN_WITHOUT_BODY,
correctness, correctness,
"use of `#[inline]` on trait methods without bodies" "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}; 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 /// **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 /// ```rust
/// x > y /// x > y
/// ``` /// ```
declare_clippy_lint! {
pub INT_PLUS_ONE, pub INT_PLUS_ONE,
complexity, complexity,
"instead of using x >= y + 1, use x > y" "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::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for creation of references to zeroed or uninitialized memory. /// **What it does:** Checks for creation of references to zeroed or uninitialized memory.
/// ///
/// **Why is this bad?** Creation of null references is undefined behavior. /// **Why is this bad?** Creation of null references is undefined behavior.
@ -15,7 +16,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust /// ```rust
/// let bad_ref: &usize = std::mem::zeroed(); /// let bad_ref: &usize = std::mem::zeroed();
/// ``` /// ```
declare_clippy_lint! {
pub INVALID_REF, pub INVALID_REF,
correctness, correctness,
"creation of invalid reference" "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 rustc::{declare_tool_lint, lint_array};
use syntax::ast::*; use syntax::ast::*;
declare_clippy_lint! {
/// **What it does:** Checks for items declared after some statement in a block. /// **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 /// **Why is this bad?** Items live for the entire scope they are declared
@ -28,7 +29,6 @@ use syntax::ast::*;
/// foo(); // prints "foo" /// foo(); // prints "foo"
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub ITEMS_AFTER_STATEMENTS, pub ITEMS_AFTER_STATEMENTS,
pedantic, pedantic,
"blocks where an item comes after a statement" "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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for large size differences between variants on /// **What it does:** Checks for large size differences between variants on
/// `enum`s. /// `enum`s.
/// ///
@ -23,7 +24,6 @@ use rustc_errors::Applicability;
/// B([i32; 8000]), /// B([i32; 8000]),
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub LARGE_ENUM_VARIANT, pub LARGE_ENUM_VARIANT,
perf, perf,
"large size difference between variants on an enum" "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::ast::{Lit, LitKind, Name};
use syntax::source_map::{Span, Spanned}; use syntax::source_map::{Span, Spanned};
declare_clippy_lint! {
/// **What it does:** Checks for getting the length of something via `.len()` /// **What it does:** Checks for getting the length of something via `.len()`
/// just to compare to zero, and suggests using `.is_empty()` where applicable. /// 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, pub LEN_ZERO,
style, style,
"checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` \ "checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` could be used instead"
could be used instead"
} }
declare_clippy_lint! {
/// **What it does:** Checks for items that implement `.len()` but not /// **What it does:** Checks for items that implement `.len()` but not
/// `.is_empty()`. /// `.is_empty()`.
/// ///
@ -64,7 +64,6 @@ style,
/// } /// }
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub LEN_WITHOUT_IS_EMPTY, pub LEN_WITHOUT_IS_EMPTY,
style, style,
"traits or impls with a public `len` method but no corresponding `is_empty` method" "traits or impls with a public `len` method but no corresponding `is_empty` method"

View file

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

View file

@ -39,7 +39,7 @@ use toml;
/// ///
/// Every lint declaration consists of 4 parts: /// 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. /// 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 /// 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. /// `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 clippy_lints::declare_clippy_lint;
/// use rustc::declare_tool_lint; /// use rustc::declare_tool_lint;
/// ///
/// declare_clippy_lint! {
/// /// **What it does:** Checks for ... (describe what the lint matches). /// /// **What it does:** Checks for ... (describe what the lint matches).
/// /// /// ///
/// /// **Why is this bad?** Supply the reason for linting the code. /// /// **Why is this bad?** Supply the reason for linting the code.
@ -75,7 +76,6 @@ use toml;
/// /// // Good /// /// // Good
/// /// Insert a short example of improved code that doesn't trigger the lint /// /// Insert a short example of improved code that doesn't trigger the lint
/// /// ``` /// /// ```
/// declare_clippy_lint! {
/// pub LINT_NAME, /// pub LINT_NAME,
/// pedantic, /// pedantic,
/// "description" /// "description"
@ -84,35 +84,55 @@ use toml;
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints /// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
#[macro_export] #[macro_export]
macro_rules! declare_clippy_lint { macro_rules! declare_clippy_lint {
{ pub $name:tt, style, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true } declare_tool_lint! {
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, correctness, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Deny, $description, report_in_external_macro: true } declare_tool_lint! {
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, complexity, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Warn, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, perf, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Warn, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, pedantic, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, restriction, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, cargo, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, nursery, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, internal, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true } declare_tool_lint! {
pub clippy::$name, Allow, $description, report_in_external_macro: true
}
}; };
{ pub $name:tt, internal_warn, $description:tt } => { { $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true } 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::source_map::Span;
use syntax::symbol::keywords; use syntax::symbol::keywords;
declare_clippy_lint! {
/// **What it does:** Checks for lifetime annotations which can be removed by /// **What it does:** Checks for lifetime annotations which can be removed by
/// relying on lifetime elision. /// relying on lifetime elision.
/// ///
@ -26,13 +27,13 @@ use syntax::symbol::keywords;
/// x /// x
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NEEDLESS_LIFETIMES, pub NEEDLESS_LIFETIMES,
complexity, complexity,
"using explicit lifetimes for references in function arguments when elision rules \ "using explicit lifetimes for references in function arguments when elision rules \
would allow omitting them" would allow omitting them"
} }
declare_clippy_lint! {
/// **What it does:** Checks for lifetimes in generics that are never used /// **What it does:** Checks for lifetimes in generics that are never used
/// anywhere else. /// anywhere else.
/// ///
@ -48,7 +49,6 @@ complexity,
/// .. /// ..
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub EXTRA_UNUSED_LIFETIMES, pub EXTRA_UNUSED_LIFETIMES,
complexity, complexity,
"unused lifetimes in function definitions" "unused lifetimes in function definitions"

View file

@ -9,6 +9,7 @@ use rustc_errors::Applicability;
use syntax::ast::*; use syntax::ast::*;
use syntax_pos; use syntax_pos;
declare_clippy_lint! {
/// **What it does:** Warns if a long integral or floating-point constant does /// **What it does:** Warns if a long integral or floating-point constant does
/// not contain underscores. /// not contain underscores.
/// ///
@ -21,12 +22,12 @@ use syntax_pos;
/// ```rust /// ```rust
/// 61864918973511 /// 61864918973511
/// ``` /// ```
declare_clippy_lint! {
pub UNREADABLE_LITERAL, pub UNREADABLE_LITERAL,
style, style,
"long integer literal without underscores" "long integer literal without underscores"
} }
declare_clippy_lint! {
/// **What it does:** Warns for mistyped suffix in literals /// **What it does:** Warns for mistyped suffix in literals
/// ///
/// **Why is this bad?** This is most probably a typo /// **Why is this bad?** This is most probably a typo
@ -41,12 +42,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// 2_32 /// 2_32
/// ``` /// ```
declare_clippy_lint! {
pub MISTYPED_LITERAL_SUFFIXES, pub MISTYPED_LITERAL_SUFFIXES,
correctness, correctness,
"mistyped literal suffix" "mistyped literal suffix"
} }
declare_clippy_lint! {
/// **What it does:** Warns if an integral or floating-point constant is /// **What it does:** Warns if an integral or floating-point constant is
/// grouped inconsistently with underscores. /// grouped inconsistently with underscores.
/// ///
@ -60,12 +61,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// 618_64_9189_73_511 /// 618_64_9189_73_511
/// ``` /// ```
declare_clippy_lint! {
pub INCONSISTENT_DIGIT_GROUPING, pub INCONSISTENT_DIGIT_GROUPING,
style, style,
"integer literals with digits grouped inconsistently" "integer literals with digits grouped inconsistently"
} }
declare_clippy_lint! {
/// **What it does:** Warns if the digits of an integral or floating-point /// **What it does:** Warns if the digits of an integral or floating-point
/// constant are grouped into groups that /// constant are grouped into groups that
/// are too large. /// are too large.
@ -79,12 +80,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// 6186491_8973511 /// 6186491_8973511
/// ``` /// ```
declare_clippy_lint! {
pub LARGE_DIGIT_GROUPS, pub LARGE_DIGIT_GROUPS,
pedantic, pedantic,
"grouping digits into groups that are too large" "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. /// **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 /// **Why is this bad?** Especially for big powers of 2 a hexadecimal representation is more
@ -97,7 +98,6 @@ declare_clippy_lint! {
/// `255` => `0xFF` /// `255` => `0xFF`
/// `65_535` => `0xFFFF` /// `65_535` => `0xFFFF`
/// `4_042_322_160` => `0xF0F0_F0F0` /// `4_042_322_160` => `0xF0F0_F0F0`
declare_clippy_lint! {
pub DECIMAL_LITERAL_REPRESENTATION, pub DECIMAL_LITERAL_REPRESENTATION,
restriction, restriction,
"using decimal representation when hexadecimal would be better" "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, 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 /// **What it does:** Checks for for-loops that manually copy items between
/// slices that could be optimized by having a memcpy. /// slices that could be optimized by having a memcpy.
/// ///
@ -45,12 +46,12 @@ use crate::utils::{
/// dst[i + 64] = src[i]; /// dst[i + 64] = src[i];
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MANUAL_MEMCPY, pub MANUAL_MEMCPY,
perf, perf,
"manually copying items between slices" "manually copying items between slices"
} }
declare_clippy_lint! {
/// **What it does:** Checks for looping over the range of `0..len` of some /// **What it does:** Checks for looping over the range of `0..len` of some
/// collection just to get the values by index. /// collection just to get the values by index.
/// ///
@ -65,12 +66,12 @@ declare_clippy_lint! {
/// println!("{}", vec[i]); /// println!("{}", vec[i]);
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NEEDLESS_RANGE_LOOP, pub NEEDLESS_RANGE_LOOP,
style, style,
"for-looping over a range of indices where an iterator over items would do" "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 /// **What it does:** Checks for loops on `x.iter()` where `&x` will do, and
/// suggests the latter. /// suggests the latter.
/// ///
@ -92,12 +93,12 @@ declare_clippy_lint! {
/// .. /// ..
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub EXPLICIT_ITER_LOOP, pub EXPLICIT_ITER_LOOP,
pedantic, pedantic,
"for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do" "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 /// **What it does:** Checks for loops on `y.into_iter()` where `y` will do, and
/// suggests the latter. /// suggests the latter.
/// ///
@ -118,12 +119,12 @@ declare_clippy_lint! {
/// .. /// ..
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub EXPLICIT_INTO_ITER_LOOP, pub EXPLICIT_INTO_ITER_LOOP,
pedantic, pedantic,
"for-looping over `_.into_iter()` when `_` would do" "for-looping over `_.into_iter()` when `_` would do"
} }
declare_clippy_lint! {
/// **What it does:** Checks for loops on `x.next()`. /// **What it does:** Checks for loops on `x.next()`.
/// ///
/// **Why is this bad?** `next()` returns either `Some(value)` if there was a /// **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, pub ITER_NEXT_LOOP,
correctness, correctness,
"for-looping over `_.next()` which is probably not intended" "for-looping over `_.next()` which is probably not intended"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `for` loops over `Option` values. /// **What it does:** Checks for `for` loops over `Option` values.
/// ///
/// **Why is this bad?** Readability. This is more clearly expressed as an `if /// **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, pub FOR_LOOP_OVER_OPTION,
correctness, correctness,
"for-looping over an `Option`, which is more clearly expressed as an `if let`" "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. /// **What it does:** Checks for `for` loops over `Result` values.
/// ///
/// **Why is this bad?** Readability. This is more clearly expressed as an `if /// **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, pub FOR_LOOP_OVER_RESULT,
correctness, correctness,
"for-looping over a `Result`, which is more clearly expressed as an `if let`" "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 /// **What it does:** Detects `loop + match` combinations that are easier
/// written as a `while let` loop. /// written as a `while let` loop.
/// ///
@ -221,12 +222,12 @@ declare_clippy_lint! {
/// // .. do something with x /// // .. do something with x
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub WHILE_LET_LOOP, pub WHILE_LET_LOOP,
complexity, complexity,
"`loop { if let { ... } else break }`, which can be written as a `while let` loop" "`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 /// **What it does:** Checks for using `collect()` on an iterator without using
/// the result. /// the result.
/// ///
@ -239,12 +240,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// vec.iter().map(|x| /* some operation returning () */).collect::<Vec<_>>(); /// vec.iter().map(|x| /* some operation returning () */).collect::<Vec<_>>();
/// ``` /// ```
declare_clippy_lint! {
pub UNUSED_COLLECT, pub UNUSED_COLLECT,
perf, perf,
"`collect()`ing an iterator without using the result; this is usually better written as a for loop" "`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 /// **What it does:** Checks for functions collecting an iterator when collect
/// is not needed. /// is not needed.
/// ///
@ -260,12 +261,12 @@ declare_clippy_lint! {
/// // should be /// // should be
/// let len = iterator.count(); /// let len = iterator.count();
/// ``` /// ```
declare_clippy_lint! {
pub NEEDLESS_COLLECT, pub NEEDLESS_COLLECT,
perf, perf,
"collecting an iterator when collect is not needed" "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` /// **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 /// are constant and `x` is greater or equal to `y`, unless the range is
/// reversed or has a negative `.step_by(_)`. /// reversed or has a negative `.step_by(_)`.
@ -284,12 +285,12 @@ declare_clippy_lint! {
/// .. /// ..
/// } // oops, stray `-` /// } // oops, stray `-`
/// ``` /// ```
declare_clippy_lint! {
pub REVERSE_RANGE_LOOP, pub REVERSE_RANGE_LOOP,
correctness, correctness,
"iteration over an empty range, such as `10..0` or `5..5`" "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 /// **What it does:** Checks `for` loops over slices with an explicit counter
/// and suggests the use of `.enumerate()`. /// 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() { foo(v[i]);
/// for i in 0..v.len() { bar(i, v[i]); } /// for i in 0..v.len() { bar(i, v[i]); }
/// ``` /// ```
declare_clippy_lint! {
pub EXPLICIT_COUNTER_LOOP, pub EXPLICIT_COUNTER_LOOP,
complexity, complexity,
"for-looping with an explicit counter when `_.enumerate()` would do" "for-looping with an explicit counter when `_.enumerate()` would do"
} }
declare_clippy_lint! {
/// **What it does:** Checks for empty `loop` expressions. /// **What it does:** Checks for empty `loop` expressions.
/// ///
/// **Why is this bad?** Those busy loops burn CPU cycles without doing /// **Why is this bad?** Those busy loops burn CPU cycles without doing
@ -322,12 +323,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// loop {} /// loop {}
/// ``` /// ```
declare_clippy_lint! {
pub EMPTY_LOOP, pub EMPTY_LOOP,
style, style,
"empty `loop {}`, which should block or sleep" "empty `loop {}`, which should block or sleep"
} }
declare_clippy_lint! {
/// **What it does:** Checks for `while let` expressions on iterators. /// **What it does:** Checks for `while let` expressions on iterators.
/// ///
/// **Why is this bad?** Readability. A simple `for` loop is shorter and conveys /// **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, pub WHILE_LET_ON_ITERATOR,
style, style,
"using a while-let loop instead of a for loop on an iterator" "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 /// **What it does:** Checks for iterating a map (`HashMap` or `BTreeMap`) and
/// ignoring either the keys or values. /// ignoring either the keys or values.
/// ///
@ -369,12 +370,12 @@ declare_clippy_lint! {
/// .. /// ..
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub FOR_KV_MAP, pub FOR_KV_MAP,
style, style,
"looping on a map using `iter` when `keys` or `values` would do" "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 /// **What it does:** Checks for loops that will always `break`, `return` or
/// `continue` an outer loop. /// `continue` an outer loop.
/// ///
@ -390,12 +391,12 @@ declare_clippy_lint! {
/// break; /// break;
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NEVER_LOOP, pub NEVER_LOOP,
correctness, correctness,
"any loop that will always `break` or `return`" "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 /// **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 /// **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 /// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MUT_RANGE_BOUND, pub MUT_RANGE_BOUND,
complexity, complexity,
"for loop over a range where one of the bounds is a mutable variable" "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 /// **What it does:** Checks whether variables used within while loop condition
/// can be (and are) mutated in the body. /// can be (and are) mutated in the body.
/// ///
@ -433,7 +434,6 @@ declare_clippy_lint! {
/// println!("let me loop forever!"); /// println!("let me loop forever!");
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub WHILE_IMMUTABLE_CONDITION, pub WHILE_IMMUTABLE_CONDITION,
correctness, correctness,
"variables used within while expression are not mutated in the body" "variables used within while expression are not mutated in the body"

View file

@ -14,6 +14,7 @@ use syntax::source_map::Span;
#[derive(Clone)] #[derive(Clone)]
pub struct Pass; pub struct Pass;
declare_clippy_lint! {
/// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests /// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests
/// `iterator.cloned()` instead /// `iterator.cloned()` instead
/// ///
@ -36,7 +37,6 @@ pub struct Pass;
/// let y = x.iter(); /// let y = x.iter();
/// let z = y.cloned(); /// let z = y.cloned();
/// ``` /// ```
declare_clippy_lint! {
pub MAP_CLONE, pub MAP_CLONE,
style, style,
"using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types" "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)] #[derive(Clone)]
pub struct Pass; pub struct Pass;
declare_clippy_lint! {
/// **What it does:** Checks for usage of `option.map(f)` where f is a function /// **What it does:** Checks for usage of `option.map(f)` where f is a function
/// or closure that returns the unit type. /// or closure that returns the unit type.
/// ///
@ -38,12 +39,12 @@ pub struct Pass;
/// log_err_msg(format_msg(msg)) /// log_err_msg(format_msg(msg))
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub OPTION_MAP_UNIT_FN, pub OPTION_MAP_UNIT_FN,
complexity, complexity,
"using `option.map(f)`, where f is a function or closure that returns ()" "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 /// **What it does:** Checks for usage of `result.map(f)` where f is a function
/// or closure that returns the unit type. /// or closure that returns the unit type.
/// ///
@ -71,7 +72,6 @@ declare_clippy_lint! {
/// log_err_msg(format_msg(msg)) /// log_err_msg(format_msg(msg))
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub RESULT_MAP_UNIT_FN, pub RESULT_MAP_UNIT_FN,
complexity, complexity,
"using `result.map(f)`, where f is a function or closure that returns ()" "using `result.map(f)`, where f is a function or closure that returns ()"

View file

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

View file

@ -7,6 +7,7 @@ use rustc_errors::Applicability;
use std::iter; use std::iter;
declare_clippy_lint! {
/// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type. /// **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 /// **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(&"hello");
/// mem::discriminant(&&Some(2)); /// mem::discriminant(&&Some(2));
/// ``` /// ```
declare_clippy_lint! {
pub MEM_DISCRIMINANT_NON_ENUM, pub MEM_DISCRIMINANT_NON_ENUM,
correctness, correctness,
"calling mem::descriminant on non-enum type" "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::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is /// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is
/// `Drop`. /// `Drop`.
/// ///
@ -15,7 +16,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust /// ```rust
/// mem::forget(Rc::new(55)) /// mem::forget(Rc::new(55))
/// ``` /// ```
declare_clippy_lint! {
pub MEM_FORGET, pub MEM_FORGET,
restriction, restriction,
"`mem::forget` usage on `Drop` types, likely to cause memory leaks" "`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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for `mem::replace()` on an `Option` with /// **What it does:** Checks for `mem::replace()` on an `Option` with
/// `None`. /// `None`.
/// ///
@ -24,7 +25,6 @@ use rustc_errors::Applicability;
/// let mut an_option = Some(0); /// let mut an_option = Some(0);
/// let taken = an_option.take(); /// let taken = an_option.take();
/// ``` /// ```
declare_clippy_lint! {
pub MEM_REPLACE_OPTION_WITH_NONE, pub MEM_REPLACE_OPTION_WITH_NONE,
style, style,
"replacing an `Option` with `None` instead of `take()`" "replacing an `Option` with `None` instead of `take()`"

View file

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

View file

@ -16,6 +16,7 @@ use rustc_errors::Applicability;
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::source_map::{ExpnFormat, Span}; use syntax::source_map::{ExpnFormat, Span};
declare_clippy_lint! {
/// **What it does:** Checks for function arguments and let bindings denoted as /// **What it does:** Checks for function arguments and let bindings denoted as
/// `ref`. /// `ref`.
/// ///
@ -38,12 +39,12 @@ use syntax::source_map::{ExpnFormat, Span};
/// .. /// ..
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub TOPLEVEL_REF_ARG, pub TOPLEVEL_REF_ARG,
style, style,
"an entire binding declared as `ref`, in a function argument or a `let` statement" "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. /// **What it does:** Checks for comparisons to NaN.
/// ///
/// **Why is this bad?** NaN does not compare meaningfully to anything not /// **Why is this bad?** NaN does not compare meaningfully to anything not
@ -55,12 +56,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// x == NAN /// x == NAN
/// ``` /// ```
declare_clippy_lint! {
pub CMP_NAN, pub CMP_NAN,
correctness, correctness,
"comparisons to NAN, which will always return false, probably not intended" "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 /// **What it does:** Checks for (in-)equality comparisons on floating-point
/// values (apart from zero), except in functions called `*eq*` (which probably /// values (apart from zero), except in functions called `*eq*` (which probably
/// implement equality for a type involving floats). /// implement equality for a type involving floats).
@ -77,12 +78,12 @@ declare_clippy_lint! {
/// y == 1.23f64 /// y == 1.23f64
/// y != x // where both are floats /// y != x // where both are floats
/// ``` /// ```
declare_clippy_lint! {
pub FLOAT_CMP, pub FLOAT_CMP,
correctness, correctness,
"using `==` or `!=` on float values instead of comparing difference with an epsilon" "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 /// **What it does:** Checks for conversions to owned values just for the sake
/// of a comparison. /// of a comparison.
/// ///
@ -96,12 +97,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// x.to_owned() == y /// x.to_owned() == y
/// ``` /// ```
declare_clippy_lint! {
pub CMP_OWNED, pub CMP_OWNED,
perf, perf,
"creating owned instances for comparing with others, e.g. `x == \"foo\".to_string()`" "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. /// **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 /// **Why is this bad?** The result can only ever be zero. No one will write
@ -115,12 +116,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// x % 1 /// x % 1
/// ``` /// ```
declare_clippy_lint! {
pub MODULO_ONE, pub MODULO_ONE,
correctness, correctness,
"taking a number modulo 1, which always returns 0" "taking a number modulo 1, which always returns 0"
} }
declare_clippy_lint! {
/// **What it does:** Checks for patterns in the form `name @ _`. /// **What it does:** Checks for patterns in the form `name @ _`.
/// ///
/// **Why is this bad?** It's almost always more readable to just use direct /// **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`, /// y @ _ => (), // easier written as `y`,
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub REDUNDANT_PATTERN, pub REDUNDANT_PATTERN,
style, style,
"using `name @ _` in a pattern" "using `name @ _` in a pattern"
} }
declare_clippy_lint! {
/// **What it does:** Checks for the use of bindings with a single leading /// **What it does:** Checks for the use of bindings with a single leading
/// underscore. /// underscore.
/// ///
@ -157,12 +158,12 @@ declare_clippy_lint! {
/// let y = _x + 1; // Here we are using `_x`, even though it has a leading /// let y = _x + 1; // Here we are using `_x`, even though it has a leading
/// // underscore. We should rename `_x` to `x` /// // underscore. We should rename `_x` to `x`
/// ``` /// ```
declare_clippy_lint! {
pub USED_UNDERSCORE_BINDING, pub USED_UNDERSCORE_BINDING,
pedantic, pedantic,
"using a binding which is prefixed with an underscore" "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 /// **What it does:** Checks for the use of short circuit boolean conditions as
/// a /// a
/// statement. /// statement.
@ -177,12 +178,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// f() && g(); // We should write `if f() { g(); }`. /// f() && g(); // We should write `if f() { g(); }`.
/// ``` /// ```
declare_clippy_lint! {
pub SHORT_CIRCUIT_STATEMENT, pub SHORT_CIRCUIT_STATEMENT,
complexity, complexity,
"using a short circuit boolean condition as a statement" "using a short circuit boolean condition as a statement"
} }
declare_clippy_lint! {
/// **What it does:** Catch casts from `0` to some pointer type /// **What it does:** Catch casts from `0` to some pointer type
/// ///
/// **Why is this bad?** This generally means `null` and is better expressed as /// **Why is this bad?** This generally means `null` and is better expressed as
@ -195,12 +196,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// 0 as *const u32 /// 0 as *const u32
/// ``` /// ```
declare_clippy_lint! {
pub ZERO_PTR, pub ZERO_PTR,
style, style,
"using 0 as *{const, mut} T" "using 0 as *{const, mut} T"
} }
declare_clippy_lint! {
/// **What it does:** Checks for (in-)equality comparisons on floating-point /// **What it does:** Checks for (in-)equality comparisons on floating-point
/// value and constant, except in functions called `*eq*` (which probably /// value and constant, except in functions called `*eq*` (which probably
/// implement equality for a type involving floats). /// implement equality for a type involving floats).
@ -217,7 +218,6 @@ declare_clippy_lint! {
/// const ONE = 1.00f64; /// const ONE = 1.00f64;
/// x == ONE // where both are floats /// x == ONE // where both are floats
/// ``` /// ```
declare_clippy_lint! {
pub FLOAT_CMP_CONST, pub FLOAT_CMP_CONST,
restriction, restriction,
"using `==` or `!=` on float constants instead of comparing difference with an epsilon" "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::source_map::Span;
use syntax::visit::{walk_expr, FnKind, Visitor}; use syntax::visit::{walk_expr, FnKind, Visitor};
declare_clippy_lint! {
/// **What it does:** Checks for structure field patterns bound to wildcards. /// **What it does:** Checks for structure field patterns bound to wildcards.
/// ///
/// **Why is this bad?** Using `..` instead is shorter and leaves the focus on /// **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 /// ```rust
/// let { a: _, b: ref b, c: _ } = .. /// let { a: _, b: ref b, c: _ } = ..
/// ``` /// ```
declare_clippy_lint! {
pub UNNEEDED_FIELD_PATTERN, pub UNNEEDED_FIELD_PATTERN,
style, style,
"struct fields bound to a wildcard instead of using `..`" "struct fields bound to a wildcard instead of using `..`"
} }
declare_clippy_lint! {
/// **What it does:** Checks for function arguments having the similar names /// **What it does:** Checks for function arguments having the similar names
/// differing by an underscore. /// differing by an underscore.
/// ///
@ -37,12 +38,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// fn foo(a: i32, _a: i32) {} /// fn foo(a: i32, _a: i32) {}
/// ``` /// ```
declare_clippy_lint! {
pub DUPLICATE_UNDERSCORE_ARGUMENT, pub DUPLICATE_UNDERSCORE_ARGUMENT,
style, style,
"function arguments having names which only differ by an underscore" "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 /// **What it does:** Detects closures called in the same expression where they
/// are defined. /// are defined.
/// ///
@ -55,12 +56,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// (|| 42)() /// (|| 42)()
/// ``` /// ```
declare_clippy_lint! {
pub REDUNDANT_CLOSURE_CALL, pub REDUNDANT_CLOSURE_CALL,
complexity, complexity,
"throwaway closures called in the expression they are defined" "throwaway closures called in the expression they are defined"
} }
declare_clippy_lint! {
/// **What it does:** Detects expressions of the form `--x`. /// **What it does:** Detects expressions of the form `--x`.
/// ///
/// **Why is this bad?** It can mislead C/C++ programmers to think `x` was /// **Why is this bad?** It can mislead C/C++ programmers to think `x` was
@ -72,12 +73,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// --x; /// --x;
/// ``` /// ```
declare_clippy_lint! {
pub DOUBLE_NEG, pub DOUBLE_NEG,
style, style,
"`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++" "`--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 /// **What it does:** Warns on hexadecimal literals with mixed-case letter
/// digits. /// digits.
/// ///
@ -89,12 +90,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let y = 0x1a9BAcD; /// let y = 0x1a9BAcD;
/// ``` /// ```
declare_clippy_lint! {
pub MIXED_CASE_HEX_LITERALS, pub MIXED_CASE_HEX_LITERALS,
style, style,
"hex literals whose letter digits are not consistently upper- or lowercased" "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 /// **What it does:** Warns if literal suffixes are not separated by an
/// underscore. /// underscore.
/// ///
@ -106,12 +107,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let y = 123832i32; /// let y = 123832i32;
/// ``` /// ```
declare_clippy_lint! {
pub UNSEPARATED_LITERAL_SUFFIX, pub UNSEPARATED_LITERAL_SUFFIX,
pedantic, pedantic,
"literals whose suffix is not separated by an underscore" "literals whose suffix is not separated by an underscore"
} }
declare_clippy_lint! {
/// **What it does:** Warns if an integral constant literal starts with `0`. /// **What it does:** Warns if an integral constant literal starts with `0`.
/// ///
/// **Why is this bad?** In some languages (including the infamous C language /// **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`). /// prints `83` (as `83 == 0o123` while `123 == 0o173`).
declare_clippy_lint! {
pub ZERO_PREFIXED_LITERAL, pub ZERO_PREFIXED_LITERAL,
complexity, complexity,
"integer literals starting with `0`" "integer literals starting with `0`"
} }
declare_clippy_lint! {
/// **What it does:** Warns if a generic shadows a built-in type. /// **What it does:** Warns if a generic shadows a built-in type.
/// ///
/// **Why is this bad?** This gives surprising type errors. /// **Why is this bad?** This gives surprising type errors.
@ -165,7 +166,6 @@ declare_clippy_lint! {
/// } /// }
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub BUILTIN_TYPE_SHADOW, pub BUILTIN_TYPE_SHADOW,
style, style,
"shadowing a builtin type" "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 rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** /// **What it does:**
/// ///
/// Suggests the use of `const` in functions and methods where possible. /// Suggests the use of `const` in functions and methods where possible.
@ -52,7 +53,6 @@ use syntax_pos::Span;
/// Self { random_number: 42 } /// Self { random_number: 42 }
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MISSING_CONST_FOR_FN, pub MISSING_CONST_FOR_FN,
nursery, nursery,
"Lint functions definitions that could be made `const fn`" "Lint functions definitions that could be made `const fn`"

View file

@ -14,6 +14,7 @@ use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Warns if there is missing doc for any documentable item /// **What it does:** Warns if there is missing doc for any documentable item
/// (public or private). /// (public or private).
/// ///
@ -23,7 +24,6 @@ use syntax::source_map::Span;
/// This lint fixes that. /// This lint fixes that.
/// ///
/// **Known problems:** None. /// **Known problems:** None.
declare_clippy_lint! {
pub MISSING_DOCS_IN_PRIVATE_ITEMS, pub MISSING_DOCS_IN_PRIVATE_ITEMS,
restriction, restriction,
"detects missing documentation for public and private members" "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::ast;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** it lints if an exported function, method, trait method with default impl, /// **What it does:** it lints if an exported function, method, trait method with default impl,
/// or trait method impl is not `#[inline]`. /// or trait method impl is not `#[inline]`.
/// ///
@ -50,7 +51,6 @@ use syntax::source_map::Span;
/// fn def_bar() {} // missing #[inline] /// fn def_bar() {} // missing #[inline]
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub MISSING_INLINE_IN_PUBLIC_ITEMS, pub MISSING_INLINE_IN_PUBLIC_ITEMS,
restriction, restriction,
"detects missing #[inline] attribute for public callables (functions, trait methods, methods...)" "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 cargo_metadata;
use itertools::Itertools; use itertools::Itertools;
declare_clippy_lint! {
/// **What it does:** Checks to see if multiple versions of a crate are being /// **What it does:** Checks to see if multiple versions of a crate are being
/// used. /// used.
/// ///
@ -25,7 +26,6 @@ use itertools::Itertools;
/// ctrlc = "3.1.0" /// ctrlc = "3.1.0"
/// ansi_term = "0.11.0" /// ansi_term = "0.11.0"
/// ``` /// ```
declare_clippy_lint! {
pub MULTIPLE_CRATE_VERSIONS, pub MULTIPLE_CRATE_VERSIONS,
cargo, cargo,
"multiple versions of the same crate being used" "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::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for instances of `mut mut` references. /// **What it does:** Checks for instances of `mut mut` references.
/// ///
/// **Why is this bad?** Multiple `mut`s don't add anything meaningful to the /// **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 /// ```rust
/// let x = &mut &mut y; /// let x = &mut &mut y;
/// ``` /// ```
declare_clippy_lint! {
pub MUT_MUT, pub MUT_MUT,
pedantic, pedantic,
"usage of double-mut refs, e.g. `&mut &mut ...`" "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::ty::{self, Ty};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Detects giving a mutable reference to a function that only /// **What it does:** Detects giving a mutable reference to a function that only
/// requires an immutable reference. /// requires an immutable reference.
/// ///
@ -17,7 +18,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ```rust /// ```rust
/// my_vec.push(&mut value) /// my_vec.push(&mut value)
/// ``` /// ```
declare_clippy_lint! {
pub UNNECESSARY_MUT_PASSED, pub UNNECESSARY_MUT_PASSED,
style, style,
"an argument passed as a mutable reference although the callee only demands an immutable reference" "an argument passed as a mutable reference although the callee only demands an immutable reference"

View file

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

View file

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

View file

@ -11,6 +11,7 @@ use rustc::ty::adjustment::{Adjust, Adjustment};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for address of operations (`&`) that are going to /// **What it does:** Checks for address of operations (`&`) that are going to
/// be dereferenced immediately by the compiler. /// be dereferenced immediately by the compiler.
/// ///
@ -23,7 +24,6 @@ use rustc_errors::Applicability;
/// ``` /// ```
/// ///
/// **Known problems:** None. /// **Known problems:** None.
declare_clippy_lint! {
pub NEEDLESS_BORROW, pub NEEDLESS_BORROW,
nursery, nursery,
"taking a reference that is going to be automatically dereferenced" "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::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for useless borrowed references. /// **What it does:** Checks for useless borrowed references.
/// ///
/// **Why is this bad?** It is mostly useless and make the code look more /// **Why is this bad?** It is mostly useless and make the code look more
@ -45,7 +46,6 @@ use rustc_errors::Applicability;
/// reference and /// reference and
/// de-referenced. /// de-referenced.
/// As such, it could just be |a| a.is_empty() /// As such, it could just be |a| a.is_empty()
declare_clippy_lint! {
pub NEEDLESS_BORROWED_REFERENCE, pub NEEDLESS_BORROWED_REFERENCE,
complexity, complexity,
"taking a needless borrowed reference" "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}; 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 /// **What it does:** The lint checks for `if`-statements appearing in loops
/// that contain a `continue` statement in either their main blocks or their /// that contain a `continue` statement in either their main blocks or their
/// `else`-blocks, when omitting the `else`-block possibly with some /// `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 /// // Do something useful
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NEEDLESS_CONTINUE, pub NEEDLESS_CONTINUE,
pedantic, pedantic,
"`continue` statements that can be replaced by a rearrangement of code" "`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::errors::DiagnosticBuilder;
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for functions taking arguments by value, but not /// **What it does:** Checks for functions taking arguments by value, but not
/// consuming them in its /// consuming them in its
/// body. /// body.
@ -43,7 +44,6 @@ use syntax_pos::Span;
/// assert_eq!(v.len(), 42); /// assert_eq!(v.len(), 42);
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NEEDLESS_PASS_BY_VALUE, pub NEEDLESS_PASS_BY_VALUE,
pedantic, pedantic,
"functions taking arguments by value, but not consuming them in its body" "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::ty;
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for needlessly including a base struct on update /// **What it does:** Checks for needlessly including a base struct on update
/// when all fields are changed anyway. /// when all fields are changed anyway.
/// ///
@ -20,7 +21,6 @@ use rustc::{declare_tool_lint, lint_array};
/// ..zero_point /// ..zero_point
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub NEEDLESS_UPDATE, pub NEEDLESS_UPDATE,
complexity, complexity,
"using `Foo { ..base }` when there are no missing fields" "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}; use crate::utils::{self, paths, span_lint};
declare_clippy_lint! {
/// **What it does:** /// **What it does:**
/// Checks for the usage of negated comparison operators on types which only implement /// Checks for the usage of negated comparison operators on types which only implement
/// `PartialOrd` (e.g. `f64`). /// `PartialOrd` (e.g. `f64`).
@ -36,7 +37,6 @@ use crate::utils::{self, paths, span_lint};
/// _ => false, /// _ => false,
/// }; /// };
/// ``` /// ```
declare_clippy_lint! {
pub NEG_CMP_OP_ON_PARTIAL_ORD, pub NEG_CMP_OP_ON_PARTIAL_ORD,
complexity, complexity,
"The use of negated comparison operators on partially ordered types may produce confusing code." "The use of negated comparison operators on partially ordered types may produce confusing code."

View file

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

View file

@ -11,6 +11,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::source_map::Span; use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for types with a `fn new() -> Self` method and no /// **What it does:** Checks for types with a `fn new() -> Self` method and no
/// implementation of /// implementation of
/// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html). /// [`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()`. /// You can also have `new()` call `Default::default()`.
declare_clippy_lint! {
pub NEW_WITHOUT_DEFAULT, pub NEW_WITHOUT_DEFAULT,
style, style,
"`fn new() -> Self` method without `Default` implementation" "`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 rustc_errors::Applicability;
use std::ops::Deref; use std::ops::Deref;
declare_clippy_lint! {
/// **What it does:** Checks for statements which have no effect. /// **What it does:** Checks for statements which have no effect.
/// ///
/// **Why is this bad?** Similar to dead code, these statements are actually /// **Why is this bad?** Similar to dead code, these statements are actually
@ -18,12 +19,12 @@ use std::ops::Deref;
/// ```rust /// ```rust
/// 0; /// 0;
/// ``` /// ```
declare_clippy_lint! {
pub NO_EFFECT, pub NO_EFFECT,
complexity, complexity,
"statements with no effect" "statements with no effect"
} }
declare_clippy_lint! {
/// **What it does:** Checks for expression statements that can be reduced to a /// **What it does:** Checks for expression statements that can be reduced to a
/// sub-expression. /// sub-expression.
/// ///
@ -36,7 +37,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// compute_array()[0]; /// compute_array()[0];
/// ``` /// ```
declare_clippy_lint! {
pub UNNECESSARY_OPERATION, pub UNNECESSARY_OPERATION,
complexity, complexity,
"outer expressions with no effect" "outer expressions with no effect"

View file

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

View file

@ -7,6 +7,7 @@ use syntax::source_map::Span;
use syntax::symbol::LocalInternedString; use syntax::symbol::LocalInternedString;
use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor}; 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. /// **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 /// **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_exp = something;
/// let checked_expr = something_else; /// let checked_expr = something_else;
/// ``` /// ```
declare_clippy_lint! {
pub SIMILAR_NAMES, pub SIMILAR_NAMES,
pedantic, pedantic,
"similarly named items and bindings" "similarly named items and bindings"
} }
declare_clippy_lint! {
/// **What it does:** Checks for too many variables whose name consists of a /// **What it does:** Checks for too many variables whose name consists of a
/// single character. /// single character.
/// ///
@ -37,12 +38,12 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// let (a, b, c, d, e, f, g) = (...); /// let (a, b, c, d, e, f, g) = (...);
/// ``` /// ```
declare_clippy_lint! {
pub MANY_SINGLE_CHAR_NAMES, pub MANY_SINGLE_CHAR_NAMES,
style, style,
"too many single character bindings" "too many single character bindings"
} }
declare_clippy_lint! {
/// **What it does:** Checks if you have variables whose name consists of just /// **What it does:** Checks if you have variables whose name consists of just
/// underscores and digits. /// underscores and digits.
/// ///
@ -57,7 +58,6 @@ declare_clippy_lint! {
/// let ___1 = 1; /// let ___1 = 1;
/// let __1___2 = 11; /// let __1___2 = 11;
/// ``` /// ```
declare_clippy_lint! {
pub JUST_UNDERSCORES_AND_DIGITS, pub JUST_UNDERSCORES_AND_DIGITS,
style, style,
"unclear name" "unclear name"

View file

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

View file

@ -5,6 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::source_map::{Span, Spanned}; use syntax::source_map::{Span, Spanned};
declare_clippy_lint! {
/// **What it does:** Checks for duplicate open options as well as combinations /// **What it does:** Checks for duplicate open options as well as combinations
/// that make no sense. /// that make no sense.
/// ///
@ -17,7 +18,6 @@ use syntax::source_map::{Span, Spanned};
/// ```rust /// ```rust
/// OpenOptions::new().read(true).truncate(true) /// OpenOptions::new().read(true).truncate(true)
/// ``` /// ```
declare_clippy_lint! {
pub NONSENSICAL_OPEN_OPTIONS, pub NONSENSICAL_OPEN_OPTIONS,
correctness, correctness,
"nonsensical combination of options for opening a file" "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::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Detects classic underflow/overflow checks. /// **What it does:** Detects classic underflow/overflow checks.
/// ///
/// **Why is this bad?** Most classic C underflow/overflow checks will fail in /// **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 /// ```rust
/// a + b < a /// a + b < a
/// ``` /// ```
declare_clippy_lint! {
pub OVERFLOW_CHECK_CONDITIONAL, pub OVERFLOW_CHECK_CONDITIONAL,
complexity, complexity,
"overflow checks inspired by C which are likely to panic" "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::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
declare_clippy_lint! {
/// **What it does:** Checks for missing parameters in `panic!`. /// **What it does:** Checks for missing parameters in `panic!`.
/// ///
/// **Why is this bad?** Contrary to the `format!` family of macros, there are /// **Why is this bad?** Contrary to the `format!` family of macros, there are
@ -20,12 +21,12 @@ use syntax_pos::Span;
/// ```rust /// ```rust
/// panic!("This `panic!` is probably missing a parameter there: {}"); /// panic!("This `panic!` is probably missing a parameter there: {}");
/// ``` /// ```
declare_clippy_lint! {
pub PANIC_PARAMS, pub PANIC_PARAMS,
style, style,
"missing parameters in `panic!` calls" "missing parameters in `panic!` calls"
} }
declare_clippy_lint! {
/// **What it does:** Checks for usage of `unimplemented!`. /// **What it does:** Checks for usage of `unimplemented!`.
/// ///
/// **Why is this bad?** This macro should not be present in production code /// **Why is this bad?** This macro should not be present in production code
@ -36,7 +37,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// unimplemented!(); /// unimplemented!();
/// ``` /// ```
declare_clippy_lint! {
pub UNIMPLEMENTED, pub UNIMPLEMENTED,
restriction, restriction,
"`unimplemented!` should not be present in production code" "`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::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
declare_clippy_lint! {
/// **What it does:** Checks for manual re-implementations of `PartialEq::ne`. /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
/// ///
/// **Why is this bad?** `PartialEq::ne` is required to always return the /// **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) } /// fn ne(&self, other: &Foo) -> bool { !(self == other) }
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub PARTIALEQ_NE_IMPL, pub PARTIALEQ_NE_IMPL,
complexity, complexity,
"re-implementing `PartialEq::ne`" "re-implementing `PartialEq::ne`"

View file

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

View file

@ -13,6 +13,7 @@ use std::borrow::Cow;
use syntax::source_map::Span; use syntax::source_map::Span;
use syntax_pos::MultiSpan; use syntax_pos::MultiSpan;
declare_clippy_lint! {
/// **What it does:** This lint checks for function arguments of type `&String` /// **What it does:** This lint checks for function arguments of type `&String`
/// or `&Vec` unless the references are mutable. It will also suggest you /// or `&Vec` unless the references are mutable. It will also suggest you
/// replace `.clone()` calls with the appropriate `.to_owned()`/`to_string()` /// replace `.clone()` calls with the appropriate `.to_owned()`/`to_string()`
@ -43,12 +44,12 @@ use syntax_pos::MultiSpan;
/// ```rust /// ```rust
/// fn foo(&Vec<u32>) { .. } /// fn foo(&Vec<u32>) { .. }
/// ``` /// ```
declare_clippy_lint! {
pub PTR_ARG, pub PTR_ARG,
style, style,
"fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively" "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` /// **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 /// **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, pub CMP_NULL,
style, style,
"comparing a pointer to a null pointer, suggesting to use `.is_null()` instead." "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 /// **What it does:** This lint checks for functions that take immutable
/// references and return /// references and return
/// mutable ones. /// mutable ones.
@ -88,7 +89,6 @@ declare_clippy_lint! {
/// ```rust /// ```rust
/// fn foo(&Foo) -> &mut Bar { .. } /// fn foo(&Foo) -> &mut Bar { .. }
/// ``` /// ```
declare_clippy_lint! {
pub MUT_FROM_REF, pub MUT_FROM_REF,
correctness, correctness,
"fns that create mutable refs from immutable ref args" "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 rustc_errors::Applicability;
use std::fmt; use std::fmt;
declare_clippy_lint! {
/// **What it does:** Checks for usage of the `offset` pointer method with a `usize` casted to an /// **What it does:** Checks for usage of the `offset` pointer method with a `usize` casted to an
/// `isize`. /// `isize`.
/// ///
@ -33,7 +34,6 @@ use std::fmt;
/// ptr.add(offset); /// ptr.add(offset);
/// } /// }
/// ``` /// ```
declare_clippy_lint! {
pub PTR_OFFSET_WITH_CAST, pub PTR_OFFSET_WITH_CAST,
complexity, complexity,
"unneeded pointer offset cast" "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 crate::utils::{match_def_path, match_type, span_lint_and_then, SpanlessEq};
use rustc_errors::Applicability; use rustc_errors::Applicability;
declare_clippy_lint! {
/// **What it does:** Checks for expressions that could be replaced by the question mark operator /// **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 /// **Why is this bad?** Question mark usage is more idiomatic
@ -28,7 +29,6 @@ use rustc_errors::Applicability;
/// ```rust /// ```rust
/// option?; /// option?;
/// ``` /// ```
declare_clippy_lint! {
pub QUESTION_MARK, pub QUESTION_MARK,
style, style,
"checks for expressions that could be replaced by the question mark operator" "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