From ef9fdbb8a9a3321a0d2261a0b6a013c23e2f669b Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 27 Mar 2018 17:13:55 +0200 Subject: [PATCH 1/5] Implementation + move one lint --- clippy_lints/src/approx_const.rs | 4 +-- clippy_lints/src/lib.rs | 29 ++++++++++++++- util/update_lints.py | 60 ++++++++++++++++++++++++++++---- 3 files changed, 84 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 36f3579e548..d15b48ce2d1 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -26,9 +26,9 @@ use utils::span_lint; /// ```rust /// let x = 3.14; /// ``` -declare_lint! { +declare_clippy_lint! { pub APPROX_CONSTANT, - Warn, + correctness, "the approximate of a known float constant (in `std::fXX::consts`)" } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d9a19ac1e76..6d6b1fe0b8c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -66,6 +66,21 @@ macro_rules! declare_restriction_lint { }; } +macro_rules! declare_clippy_lint { + { pub $name:tt, style, $description:tt } => { + declare_lint! { pub $name, Warn, $description } + }; + { pub $name:tt, correctness, $description:tt } => { + declare_lint! { pub $name, Deny, $description } + }; + { pub $name:tt, complexity, $description:tt } => { + declare_lint! { pub $name, Warn, $description } + }; + { pub $name:tt, perf, $description:tt } => { + declare_lint! { pub $name, Warn, $description } + }; +} + pub mod consts; #[macro_use] pub mod utils; @@ -442,7 +457,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { ]); reg.register_lint_group("clippy", vec![ - approx_const::APPROX_CONSTANT, array_indexing::OUT_OF_BOUNDS_INDEXING, assign_ops::ASSIGN_OP_PATTERN, assign_ops::MISREFACTORED_ASSIGN_OP, @@ -641,6 +655,19 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { vec::USELESS_VEC, zero_div_zero::ZERO_DIVIDED_BY_ZERO, ]); + + reg.register_lint_group("clippy_style", vec![ + ]); + + reg.register_lint_group("clippy_complexity", vec![ + ]); + + reg.register_lint_group("clippy_correctness", vec![ + approx_const::APPROX_CONSTANT, + ]); + + reg.register_lint_group("clippy_perf", vec![ + ]); } // only exists to let the dogfood integration test works. diff --git a/util/update_lints.py b/util/update_lints.py index 6c08f575d05..0f9c3479439 100755 --- a/util/update_lints.py +++ b/util/update_lints.py @@ -27,12 +27,19 @@ declare_restriction_lint_re = re.compile(r''' " (?P(?:[^"\\]+|\\.)*) " \s* [})] ''', re.VERBOSE | re.DOTALL) +declare_clippy_lint_re = re.compile(r''' + declare_clippy_lint! \s* [{(] \s* + pub \s+ (?P[A-Z_][A-Z_0-9]*) \s*,\s* + (?P[a-z_]+) \s*,\s* + " (?P(?:[^"\\]+|\\.)*) " \s* [})] +''', re.VERBOSE | re.DOTALL) + nl_escape_re = re.compile(r'\\\n\s*') docs_link = 'https://rust-lang-nursery.github.io/rust-clippy/master/index.html' -def collect(lints, deprecated_lints, restriction_lints, fn): +def collect(lints, deprecated_lints, restriction_lints, clippy_lints, fn): """Collect all lints from a file. Adds entries to the lints list as `(module, name, level, desc)`. @@ -61,6 +68,15 @@ def collect(lints, deprecated_lints, restriction_lints, fn): match.group('name').lower(), "allow", desc.replace('\\"', '"'))) + + for match in declare_clippy_lint_re.finditer(code): + # remove \-newline escapes from description string + desc = nl_escape_re.sub('', match.group('desc')) + cat = match.group('cat') + clippy_lints[cat].append((os.path.splitext(os.path.basename(fn))[0], + match.group('name').lower(), + "allow", + desc.replace('\\"', '"'))) def gen_group(lints, levels=None): @@ -130,6 +146,12 @@ def main(print_only=False, check=False): lints = [] deprecated_lints = [] restriction_lints = [] + clippy_lints = { + "correctness": [], + "style": [], + "complexity": [], + "perf": [], + } # check directory if not os.path.isfile('clippy_lints/src/lib.rs'): @@ -139,7 +161,7 @@ def main(print_only=False, check=False): # collect all lints from source files for fn in os.listdir('clippy_lints/src'): if fn.endswith('.rs'): - collect(lints, deprecated_lints, restriction_lints, + collect(lints, deprecated_lints, restriction_lints, clippy_lints, os.path.join('clippy_lints', 'src', fn)) # determine version @@ -152,8 +174,10 @@ def main(print_only=False, check=False): print('Error: version not found in Cargo.toml!') return + all_lints = lints + restriction_lints + clippy_lints['perf'] + clippy_lints['correctness'] + clippy_lints['style'] + clippy_lints['complexity'] + if print_only: - sys.stdout.writelines(gen_table(lints + restriction_lints)) + sys.stdout.writelines(gen_table(all_lints)) return # update the lint counter in README.md @@ -161,7 +185,7 @@ def main(print_only=False, check=False): 'README.md', r'^\[There are \d+ lints included in this crate\]\(https://rust-lang-nursery.github.io/rust-clippy/master/index.html\)$', "", lambda: ['[There are %d lints included in this crate](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)\n' % - (len(lints) + len(restriction_lints))], + (len(all_lints))], write_back=not check) # update the links in the CHANGELOG @@ -170,7 +194,7 @@ def main(print_only=False, check=False): "", "", lambda: ["[`{0}`]: {1}#{0}\n".format(l[1], docs_link) for l in - sorted(lints + restriction_lints + deprecated_lints, + sorted(all_lints + deprecated_lints, key=lambda l: l[1])], replace_start=False, write_back=not check) @@ -190,7 +214,7 @@ def main(print_only=False, check=False): # update the `pub mod` list changed |= replace_region( 'clippy_lints/src/lib.rs', r'begin lints modules', r'end lints modules', - lambda: gen_mods(lints + restriction_lints), + lambda: gen_mods(all_lints), replace_start=False, write_back=not check) # same for "clippy" lint collection @@ -199,6 +223,30 @@ def main(print_only=False, check=False): lambda: gen_group(lints, levels=('warn', 'deny')), replace_start=False, write_back=not check) + # same for "clippy_style" lint collection + changed |= replace_region( + 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_style"', r'\]\);', + lambda: gen_group(clippy_lints['style']), + replace_start=False, write_back=not check) + + # same for "clippy_correctness" lint collection + changed |= replace_region( + 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_correctness"', r'\]\);', + lambda: gen_group(clippy_lints['correctness']), + replace_start=False, write_back=not check) + + # same for "clippy_complexity" lint collection + changed |= replace_region( + 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_complexity"', r'\]\);', + lambda: gen_group(clippy_lints['complexity']), + replace_start=False, write_back=not check) + + # same for "clippy_perf" lint collection + changed |= replace_region( + 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_perf"', r'\]\);', + lambda: gen_group(clippy_lints['perf']), + replace_start=False, write_back=not check) + # same for "deprecated" lint collection changed |= replace_region( 'clippy_lints/src/lib.rs', r'let mut store', r'end deprecated lints', From d6344c47e3bf8e1c1bc4dea52841d0a1f83b4fa4 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 28 Mar 2018 15:24:26 +0200 Subject: [PATCH 2/5] Categorize all the lints! --- clippy_lints/src/arithmetic.rs | 6 +- clippy_lints/src/array_indexing.rs | 7 +- clippy_lints/src/assign_ops.rs | 11 +- clippy_lints/src/attrs.rs | 16 +- clippy_lints/src/bit_mask.rs | 12 +- clippy_lints/src/blacklisted_name.rs | 4 +- clippy_lints/src/block_in_if_condition.rs | 8 +- clippy_lints/src/booleans.rs | 8 +- clippy_lints/src/bytecount.rs | 4 +- clippy_lints/src/collapsible_if.rs | 4 +- clippy_lints/src/const_static_lifetime.rs | 4 +- clippy_lints/src/copies.rs | 12 +- clippy_lints/src/cyclomatic_complexity.rs | 4 +- clippy_lints/src/derive.rs | 10 +- clippy_lints/src/doc.rs | 4 +- clippy_lints/src/double_comparison.rs | 4 +- clippy_lints/src/double_parens.rs | 5 +- clippy_lints/src/drop_forget_ref.rs | 16 +- clippy_lints/src/else_if_without_else.rs | 3 +- clippy_lints/src/empty_enum.rs | 4 +- clippy_lints/src/entry.rs | 4 +- clippy_lints/src/enum_clike.rs | 4 +- clippy_lints/src/enum_glob_use.rs | 4 +- clippy_lints/src/enum_variants.rs | 16 +- clippy_lints/src/eq_op.rs | 8 +- clippy_lints/src/erasing_op.rs | 4 +- clippy_lints/src/escape.rs | 4 +- clippy_lints/src/eta_reduction.rs | 4 +- clippy_lints/src/eval_order_dependence.rs | 8 +- clippy_lints/src/explicit_write.rs | 4 +- clippy_lints/src/fallible_impl_from.rs | 5 +- clippy_lints/src/format.rs | 4 +- clippy_lints/src/formatting.rs | 12 +- clippy_lints/src/functions.rs | 8 +- clippy_lints/src/identity_conversion.rs | 4 +- clippy_lints/src/identity_op.rs | 4 +- .../src/if_let_redundant_pattern_matching.rs | 4 +- clippy_lints/src/if_not_else.rs | 4 +- clippy_lints/src/infinite_iter.rs | 8 +- clippy_lints/src/inline_fn_without_body.rs | 4 +- clippy_lints/src/int_plus_one.rs | 4 +- clippy_lints/src/invalid_ref.rs | 4 +- clippy_lints/src/items_after_statements.rs | 4 +- clippy_lints/src/large_enum_variant.rs | 4 +- clippy_lints/src/len_zero.rs | 8 +- clippy_lints/src/let_if_seq.rs | 4 +- clippy_lints/src/lib.rs | 234 +++++++++--------- clippy_lints/src/lifetimes.rs | 8 +- clippy_lints/src/literal_representation.rs | 15 +- clippy_lints/src/loops.rs | 84 ++++--- clippy_lints/src/map_clone.rs | 4 +- clippy_lints/src/matches.rs | 28 +-- clippy_lints/src/mem_forget.rs | 4 +- clippy_lints/src/methods.rs | 117 ++++----- clippy_lints/src/minmax.rs | 4 +- clippy_lints/src/misc.rs | 39 +-- clippy_lints/src/misc_early.rs | 32 +-- clippy_lints/src/missing_doc.rs | 4 +- clippy_lints/src/mut_mut.rs | 4 +- clippy_lints/src/mut_reference.rs | 4 +- clippy_lints/src/mutex_atomic.rs | 8 +- clippy_lints/src/needless_bool.rs | 8 +- clippy_lints/src/needless_borrow.rs | 4 +- clippy_lints/src/needless_borrowed_ref.rs | 4 +- clippy_lints/src/needless_continue.rs | 4 +- clippy_lints/src/needless_pass_by_value.rs | 4 +- clippy_lints/src/needless_update.rs | 4 +- clippy_lints/src/neg_multiply.rs | 4 +- clippy_lints/src/new_without_default.rs | 8 +- clippy_lints/src/no_effect.rs | 8 +- clippy_lints/src/non_expressive_names.rs | 12 +- clippy_lints/src/ok_if_let.rs | 4 +- clippy_lints/src/open_options.rs | 4 +- .../src/overflow_check_conditional.rs | 4 +- clippy_lints/src/panic.rs | 4 +- clippy_lints/src/partialeq_ne_impl.rs | 4 +- clippy_lints/src/precedence.rs | 4 +- clippy_lints/src/print.rs | 16 +- clippy_lints/src/ptr.rs | 12 +- clippy_lints/src/question_mark.rs | 4 +- clippy_lints/src/ranges.rs | 16 +- clippy_lints/src/redundant_field_names.rs | 4 +- clippy_lints/src/reference.rs | 4 +- clippy_lints/src/regex.rs | 12 +- clippy_lints/src/replace_consts.rs | 4 +- clippy_lints/src/returns.rs | 8 +- clippy_lints/src/serde_api.rs | 6 +- clippy_lints/src/shadow.rs | 12 +- clippy_lints/src/strings.rs | 15 +- clippy_lints/src/suspicious_trait_impl.rs | 8 +- clippy_lints/src/swap.rs | 8 +- clippy_lints/src/temporary_assignment.rs | 4 +- clippy_lints/src/transmute.rs | 36 +-- clippy_lints/src/types.rs | 72 +++--- clippy_lints/src/unicode.rs | 12 +- clippy_lints/src/unsafe_removed_from_name.rs | 4 +- clippy_lints/src/unused_io_amount.rs | 4 +- clippy_lints/src/unused_label.rs | 4 +- clippy_lints/src/use_self.rs | 4 +- clippy_lints/src/utils/author.rs | 4 +- clippy_lints/src/utils/inspector.rs | 4 +- clippy_lints/src/utils/internal_lints.rs | 8 +- clippy_lints/src/vec.rs | 4 +- clippy_lints/src/zero_div_zero.rs | 4 +- tests/ui/lint_pass.rs | 4 +- util/lintlib.py | 80 +++--- util/update_lints.py | 81 ++---- 107 files changed, 707 insertions(+), 715 deletions(-) diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index a551ebf046b..501f49363dd 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -15,8 +15,9 @@ use utils::span_lint; /// ```rust /// a + 1 /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub INTEGER_ARITHMETIC, + restriction, "any integer arithmetic statement" } @@ -31,8 +32,9 @@ declare_restriction_lint! { /// ```rust /// a + 1.0 /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub FLOAT_ARITHMETIC, + restriction, "any floating-point arithmetic statement" } diff --git a/clippy_lints/src/array_indexing.rs b/clippy_lints/src/array_indexing.rs index 53d0d7cebaa..4563a58f7ab 100644 --- a/clippy_lints/src/array_indexing.rs +++ b/clippy_lints/src/array_indexing.rs @@ -19,9 +19,9 @@ use consts::{constant, Constant}; /// x[9]; /// &x[2..9]; /// ``` -declare_lint! { +declare_clippy_lint! { pub OUT_OF_BOUNDS_INDEXING, - Deny, + correctness, "out of bounds constant indexing" } @@ -39,8 +39,9 @@ declare_lint! { /// x[2]; /// &x[0..2]; /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub INDEXING_SLICING, + restriction, "indexing/slicing usage" } diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index a3d9d5cbba8..da4b0d6a437 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -18,8 +18,9 @@ use utils::{higher, sugg}; /// ```rust /// a += 1; /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub ASSIGN_OPS, + restriction, "any compound assignment operation" } @@ -37,9 +38,9 @@ declare_restriction_lint! { /// ... /// a = a + b; /// ``` -declare_lint! { +declare_clippy_lint! { pub ASSIGN_OP_PATTERN, - Warn, + style, "assigning the result of an operation on a variable to that same variable" } @@ -57,9 +58,9 @@ declare_lint! { /// ... /// a += a + b; /// ``` -declare_lint! { +declare_clippy_lint! { pub MISREFACTORED_ASSIGN_OP, - Warn, + complexity, "having a variable on both sides of an assign op" } diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 38cc40d2e16..340d82dfa61 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -29,9 +29,9 @@ use utils::{in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snip /// #[inline(always)] /// fn not_quite_hot_code(..) { ... } /// ``` -declare_lint! { +declare_clippy_lint! { pub INLINE_ALWAYS, - Warn, + pedantic, "use of `#[inline(always)]`" } @@ -53,9 +53,9 @@ declare_lint! { /// #[allow(unused_import)] /// use foo::bar; /// ``` -declare_lint! { +declare_clippy_lint! { pub USELESS_ATTRIBUTE, - Warn, + correctness, "use of lint attributes on `extern crate` items" } @@ -72,9 +72,9 @@ declare_lint! { /// #[deprecated(since = "forever")] /// fn something_else(..) { ... } /// ``` -declare_lint! { +declare_clippy_lint! { pub DEPRECATED_SEMVER, - Warn, + correctness, "use of `#[deprecated(since = \"x\")]` where x is not semver" } @@ -103,9 +103,9 @@ declare_lint! { /// #[inline(always)] /// fn this_is_fine_too(..) { ... } /// ``` -declare_lint! { +declare_clippy_lint! { pub EMPTY_LINE_AFTER_OUTER_ATTR, - Warn, + style, "empty line after outer attribute" } diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 8989c5ca8cf..b6adbf1bd86 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -36,9 +36,9 @@ use consts::{constant, Constant}; /// ```rust /// if (x & 1 == 2) { … } /// ``` -declare_lint! { +declare_clippy_lint! { pub BAD_BIT_MASK, - Warn, + correctness, "expressions of the form `_ & mask == select` that will only ever return `true` or `false`" } @@ -64,9 +64,9 @@ declare_lint! { /// ```rust /// if (x | 1 > 3) { … } /// ``` -declare_lint! { +declare_clippy_lint! { pub INEFFECTIVE_BIT_MASK, - Warn, + correctness, "expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`" } @@ -82,9 +82,9 @@ declare_lint! { /// ```rust /// x & 0x1111 == 0 /// ``` -declare_lint! { +declare_clippy_lint! { pub VERBOSE_BIT_MASK, - Warn, + style, "expressions where a bit mask is less readable than the corresponding method call" } diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index dd5bf968bb3..d06e1240b06 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -14,9 +14,9 @@ use utils::span_lint; /// ```rust /// let foo = 3.14; /// ``` -declare_lint! { +declare_clippy_lint! { pub BLACKLISTED_NAME, - Warn, + style, "usage of a blacklisted/placeholder name" } diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index 0afb8a73dfe..2fd385228b2 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -15,9 +15,9 @@ use utils::*; /// ```rust /// if { true } .. /// ``` -declare_lint! { +declare_clippy_lint! { pub BLOCK_IN_IF_CONDITION_EXPR, - Warn, + style, "braces that can be eliminated in conditions, e.g. `if { true } ...`" } @@ -34,9 +34,9 @@ declare_lint! { /// // or /// if somefunc(|x| { x == 47 }) .. /// ``` -declare_lint! { +declare_clippy_lint! { pub BLOCK_IN_IF_CONDITION_STMT, - Warn, + style, "complex blocks in conditions, e.g. `if { let x = true; x } ...`" } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index cec569ec061..0fa2c2ac96f 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -20,9 +20,9 @@ use utils::{in_macro, snippet_opt, span_lint_and_then, SpanlessEq}; /// if a && true // should be: if a /// if !(a == b) // should be: if a != b /// ``` -declare_lint! { +declare_clippy_lint! { pub NONMINIMAL_BOOL, - Allow, + complexity, "boolean expressions that can be written more concisely" } @@ -38,9 +38,9 @@ declare_lint! { /// if a && b || a { ... } /// ``` /// The `b` is unnecessary, the expression is equivalent to `if a`. -declare_lint! { +declare_clippy_lint! { pub LOGIC_BUG, - Warn, + correctness, "boolean expressions that contain terminals which can be eliminated" } diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 886834e3981..278decc2ebd 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -20,9 +20,9 @@ use utils::{contains_name, get_pat_name, match_type, paths, single_segment_path, /// ```rust /// &my_data.filter(|&x| x == 0u8).count() // use bytecount::count instead /// ``` -declare_lint! { +declare_clippy_lint! { pub NAIVE_BYTECOUNT, - Warn, + perf, "use of naive `.filter(|&x| x == y).count()` to count byte values" } diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index fa0d7de6676..20a5e606dbf 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -62,9 +62,9 @@ use utils::sugg::Sugg; /// … /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub COLLAPSIBLE_IF, - Warn, + style, "`if`s that can be collapsed (e.g. `if x { if y { ... } }` and `else { if x { ... } }`)" } diff --git a/clippy_lints/src/const_static_lifetime.rs b/clippy_lints/src/const_static_lifetime.rs index 66a1634ebce..38fcf514626 100644 --- a/clippy_lints/src/const_static_lifetime.rs +++ b/clippy_lints/src/const_static_lifetime.rs @@ -18,9 +18,9 @@ use utils::{in_macro, snippet, span_lint_and_then}; /// ```rust /// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] /// ``` -declare_lint! { +declare_clippy_lint! { pub CONST_STATIC_LIFETIME, - Warn, + style, "Using explicit `'static` lifetime for constants when elision rules would allow omitting them." } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index d41ea5849a8..1434a1437f0 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -33,9 +33,9 @@ use utils::{get_parent_expr, in_macro, snippet, span_lint_and_then, span_note_an /// … /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub IFS_SAME_COND, - Warn, + correctness, "consecutive `ifs` with the same condition" } @@ -54,9 +54,9 @@ declare_lint! { /// 42 /// }; /// ``` -declare_lint! { +declare_clippy_lint! { pub IF_SAME_THEN_ELSE, - Warn, + correctness, "if with the same *then* and *else* blocks" } @@ -95,9 +95,9 @@ declare_lint! { /// Quz => quz(), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MATCH_SAME_ARMS, - Warn, + pedantic, "`match` with identical arm bodies" } diff --git a/clippy_lints/src/cyclomatic_complexity.rs b/clippy_lints/src/cyclomatic_complexity.rs index 751fc13292c..139936554a1 100644 --- a/clippy_lints/src/cyclomatic_complexity.rs +++ b/clippy_lints/src/cyclomatic_complexity.rs @@ -19,9 +19,9 @@ use utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitSt /// complexity. /// /// **Example:** No. You'll see it when you get the warning. -declare_lint! { +declare_clippy_lint! { pub CYCLOMATIC_COMPLEXITY, - Warn, + complexity, "functions that should be split up into multiple functions" } diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 8702ec1e716..b505e52c95b 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -28,9 +28,9 @@ use utils::{is_automatically_derived, is_copy, match_path, span_lint_and_then}; /// ... /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub DERIVE_HASH_XOR_EQ, - Warn, + correctness, "deriving `Hash` but implementing `PartialEq` explicitly" } @@ -43,7 +43,7 @@ declare_lint! { /// nothing more than copy the object, which is what `#[derive(Copy, Clone)]` /// gets you. /// -/// **Known problems:** None. +/// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925 /// /// **Example:** /// ```rust @@ -54,9 +54,9 @@ declare_lint! { /// .. /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub EXPL_IMPL_CLONE_ON_COPY, - Warn, + pedantic, "implementing `Clone` explicitly on `Copy` types" } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 3e2c56f5fb9..1439c23f0fa 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -25,9 +25,9 @@ use url::Url; /// // ^ `foo_bar` and `that::other::module::foo` should be ticked. /// fn doit(foo_bar) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub DOC_MARKDOWN, - Warn, + pedantic, "presence of `_`, `::` or camel-case outside backticks in documentation" } diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index a4124883fcb..06d0cf1d09e 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -23,9 +23,9 @@ use utils::{snippet, span_lint_and_sugg, SpanlessEq}; /// ```rust /// x <= y /// ``` -declare_lint! { +declare_clippy_lint! { pub DOUBLE_COMPARISONS, - Deny, + complexity, "unnecessary double comparisons that can be simplified" } diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index be5e056d5df..2b81e1db257 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -14,8 +14,9 @@ use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass} /// foo((0)) /// ((1, 2)) /// ``` -declare_lint! { - pub DOUBLE_PARENS, Warn, +declare_clippy_lint! { + pub DOUBLE_PARENS, + complexity, "Warn on unnecessary double parentheses" } diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index c523c569a68..7acc7805f82 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -20,9 +20,9 @@ use utils::{is_copy, match_def_path, opt_def_id, paths, span_note_and_lint}; /// still locked /// operation_that_requires_mutex_to_be_unlocked(); /// ``` -declare_lint! { +declare_clippy_lint! { pub DROP_REF, - Warn, + correctness, "calls to `std::mem::drop` with a reference instead of an owned value" } @@ -41,9 +41,9 @@ declare_lint! { /// let x = Box::new(1); /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped /// ``` -declare_lint! { +declare_clippy_lint! { pub FORGET_REF, - Warn, + correctness, "calls to `std::mem::forget` with a reference instead of an owned value" } @@ -62,9 +62,9 @@ declare_lint! { /// std::mem::drop(x) // A copy of x is passed to the function, leaving the /// original unaffected /// ``` -declare_lint! { +declare_clippy_lint! { pub DROP_COPY, - Warn, + correctness, "calls to `std::mem::drop` with a value that implements Copy" } @@ -89,9 +89,9 @@ declare_lint! { /// std::mem::forget(x) // A copy of x is passed to the function, leaving the /// original unaffected /// ``` -declare_lint! { +declare_clippy_lint! { pub FORGET_COPY, - Warn, + correctness, "calls to `std::mem::forget` with a value that implements Copy" } diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index b354fe70596..bceed1c2168 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -32,8 +32,9 @@ use utils::{in_external_macro, span_lint_and_sugg}; /// // we don't care about zero /// } /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub ELSE_IF_WITHOUT_ELSE, + restriction, "if expression with an `else if`, but without a final `else` branch" } diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 67a4b8d4030..1641c4d444b 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -16,9 +16,9 @@ use utils::span_lint_and_then; /// ```rust /// enum Test {} /// ``` -declare_lint! { +declare_clippy_lint! { pub EMPTY_ENUM, - Allow, + pedantic, "enum with no variants" } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index aeae5fc6ced..d67b3a010cf 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -24,9 +24,9 @@ use utils::{get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ /// ```rust /// m.entry(k).or_insert(v); /// ``` -declare_lint! { +declare_clippy_lint! { pub MAP_ENTRY, - Warn, + perf, "use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`" } diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index f1572043024..da3586af262 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -27,9 +27,9 @@ use rustc::mir::interpret::GlobalId; /// Y = 0 /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub ENUM_CLIKE_UNPORTABLE_VARIANT, - Warn, + correctness, "C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`" } diff --git a/clippy_lints/src/enum_glob_use.rs b/clippy_lints/src/enum_glob_use.rs index 8a0d03d2ae9..0718a6b3679 100644 --- a/clippy_lints/src/enum_glob_use.rs +++ b/clippy_lints/src/enum_glob_use.rs @@ -19,9 +19,9 @@ use utils::span_lint; /// ```rust /// use std::cmp::Ordering::*; /// ``` -declare_lint! { +declare_clippy_lint! { pub ENUM_GLOB_USE, - Allow, + pedantic, "use items that import all variants of an enum" } diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 4a5dc1cc286..c2e246a71fa 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -22,9 +22,9 @@ use utils::{camel_case_from, camel_case_until, in_macro}; /// HummingbirdCake, /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub ENUM_VARIANT_NAMES, - Warn, + style, "enums where all variants share a prefix/postfix" } @@ -43,9 +43,9 @@ declare_lint! { /// HummingbirdCake, /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub PUB_ENUM_VARIANT_NAMES, - Allow, + pedantic, "enums where all variants share a prefix/postfix" } @@ -62,9 +62,9 @@ declare_lint! { /// struct BlackForestCake; /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub STUTTER, - Allow, + pedantic, "type names prefixed/postfixed with their containing module's name" } @@ -92,9 +92,9 @@ declare_lint! { /// ... /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MODULE_INCEPTION, - Warn, + style, "modules that have the same name as their parent module" } diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index d62b937f52f..cce20a58da8 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -17,9 +17,9 @@ use utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_l /// ```rust /// x + 1 == x + 1 /// ``` -declare_lint! { +declare_clippy_lint! { pub EQ_OP, - Warn, + correctness, "equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)" } @@ -35,9 +35,9 @@ declare_lint! { /// ```rust /// &x == y /// ``` -declare_lint! { +declare_clippy_lint! { pub OP_REF, - Warn, + style, "taking a reference to satisfy the type constraints on `==`" } diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index a601d91a185..9cd4f3ada3b 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -16,9 +16,9 @@ use utils::{in_macro, span_lint}; /// ```rust /// 0 / x; 0 * x; x & 0 /// ``` -declare_lint! { +declare_clippy_lint! { pub ERASING_OP, - Warn, + correctness, "using erasing operations, e.g. `x * 0` or `y & 0`" } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 8cd0aaee9af..8c3127085fa 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -32,9 +32,9 @@ pub struct Pass { /// println!("{}", *x); /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub BOXED_LOCAL, - Warn, + perf, "using `Box` where unnecessary" } diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 0710689c3d4..cb1122486f3 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -22,9 +22,9 @@ pub struct EtaPass; /// ``` /// where `foo(_)` is a plain function that takes the exact argument type of /// `x`. -declare_lint! { +declare_clippy_lint! { pub REDUNDANT_CLOSURE, - Warn, + style, "redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)" } diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 1ca15e4d24f..d034104a609 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -21,9 +21,9 @@ use utils::{get_parent_expr, span_lint, span_note_and_lint}; /// let a = {x = 1; 1} + x; /// // Unclear whether a is 1 or 2. /// ``` -declare_lint! { +declare_clippy_lint! { pub EVAL_ORDER_DEPENDENCE, - Warn, + complexity, "whether a variable read occurs before a write depends on sub-expression evaluation order" } @@ -43,9 +43,9 @@ declare_lint! { /// let x = (a, b, c, panic!()); /// // can simply be replaced by `panic!()` /// ``` -declare_lint! { +declare_clippy_lint! { pub DIVERGING_SUB_EXPRESSION, - Warn, + complexity, "whether an expression contains a diverging sub expression" } diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 7ea96cabfac..bad5bbd8422 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -15,9 +15,9 @@ use utils::opt_def_id; /// // this would be clearer as `eprintln!("foo: {:?}", bar);` /// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap(); /// ``` -declare_lint! { +declare_clippy_lint! { pub EXPLICIT_WRITE, - Warn, + complexity, "using the `write!()` family of functions instead of the `print!()` family \ of functions, when using the latter would work" } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 5b9830ad0ab..dd37a6725d2 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -20,8 +20,9 @@ use utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT}; /// } /// } /// ``` -declare_lint! { - pub FALLIBLE_IMPL_FROM, Allow, +declare_clippy_lint! { + pub FALLIBLE_IMPL_FROM, + nursery, "Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`" } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index d86e6839cfb..7136eff3274 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -21,9 +21,9 @@ use utils::{is_expn_of, match_def_path, match_type, opt_def_id, resolve_node, sn /// format!("foo") /// format!("{}", foo) /// ``` -declare_lint! { +declare_clippy_lint! { pub USELESS_FORMAT, - Warn, + complexity, "useless use of `format!`" } diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index e016fa3d595..ff40839637b 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -15,9 +15,9 @@ use syntax::ptr::P; /// ```rust,ignore /// a =- 42; // confusing, should it be `a -= 42` or `a = -42`? /// ``` -declare_lint! { +declare_clippy_lint! { pub SUSPICIOUS_ASSIGNMENT_FORMATTING, - Warn, + style, "suspicious formatting of `*=`, `-=` or `!=`" } @@ -41,9 +41,9 @@ declare_lint! { /// if bar { // this is the `else` block of the previous `if`, but should it be? /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub SUSPICIOUS_ELSE_FORMATTING, - Warn, + style, "suspicious formatting of `else if`" } @@ -61,9 +61,9 @@ declare_lint! { /// -4, -5, -6 /// ]; /// ``` -declare_lint! { +declare_clippy_lint! { pub POSSIBLE_MISSING_COMMA, - Warn, + style, "possible missing comma in array" } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 4bf4aafcc4e..719708d6d18 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -22,9 +22,9 @@ use utils::{iter_input_pats, span_lint, type_is_unsafe_function}; /// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: /// f32) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub TOO_MANY_ARGUMENTS, - Warn, + style, "functions with too many arguments" } @@ -48,9 +48,9 @@ declare_lint! { /// ```rust /// pub fn foo(x: *const u8) { println!("{}", unsafe { *x }); } /// ``` -declare_lint! { +declare_clippy_lint! { pub NOT_UNSAFE_PTR_ARG_DEREF, - Warn, + correctness, "public functions dereferencing raw pointer arguments but not marked `unsafe`" } diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index d64f352d7f1..8132ce73944 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -15,9 +15,9 @@ use utils::{opt_def_id, paths, resolve_node}; /// // format!() returns a `String` /// let s: String = format!("hello").into(); /// ``` -declare_lint! { +declare_clippy_lint! { pub IDENTITY_CONVERSION, - Warn, + complexity, "using always-identical `Into`/`From` conversions" } diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 717245ec0f5..c6b4f9f1af3 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -16,9 +16,9 @@ use rustc::ty; /// ```rust /// x / 1 + 0 * 1 - 0 | 0 /// ``` -declare_lint! { +declare_clippy_lint! { pub IDENTITY_OP, - Warn, + complexity, "using identity operations, e.g. `x + 0` or `y / 1`" } diff --git a/clippy_lints/src/if_let_redundant_pattern_matching.rs b/clippy_lints/src/if_let_redundant_pattern_matching.rs index 27f41c0e698..2465c5351bd 100644 --- a/clippy_lints/src/if_let_redundant_pattern_matching.rs +++ b/clippy_lints/src/if_let_redundant_pattern_matching.rs @@ -28,9 +28,9 @@ use utils::{match_qpath, paths, snippet, span_lint_and_then}; /// if Some(42).is_some() {} /// ``` /// -declare_lint! { +declare_clippy_lint! { pub IF_LET_REDUNDANT_PATTERN_MATCHING, - Warn, + style, "use the proper utility function avoiding an `if let`" } diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index d7d98351647..ea264bf5186 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -31,9 +31,9 @@ use utils::{in_external_macro, span_help_and_lint}; /// a() /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub IF_NOT_ELSE, - Allow, + pedantic, "`if` branches that could be swapped so no negation operation is necessary on the condition" } diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 3a5bcdc78d4..238970d4a9f 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -13,9 +13,9 @@ use utils::{get_trait_def_id, higher, implements_trait, match_qpath, paths, span /// ```rust /// repeat(1_u8).iter().collect::>() /// ``` -declare_lint! { +declare_clippy_lint! { pub INFINITE_ITER, - Warn, + correctness, "infinite iteration" } @@ -31,9 +31,9 @@ declare_lint! { /// ```rust /// [0..].iter().zip(infinite_iter.take_while(|x| x > 5)) /// ``` -declare_lint! { +declare_clippy_lint! { pub MAYBE_INFINITE_ITER, - Allow, + pedantic, "possible infinite iteration" } diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 99b7812472a..243498d2d4e 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -20,9 +20,9 @@ use utils::sugg::DiagnosticBuilderExt; /// fn name(&self) -> &'static str; /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub INLINE_FN_WITHOUT_BODY, - Warn, + complexity, "use of `#[inline]` on trait methods without bodies" } diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 6e74547b75f..42fb8440ac8 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -22,9 +22,9 @@ use utils::{snippet_opt, span_lint_and_then}; /// ```rust /// x > y /// ``` -declare_lint! { +declare_clippy_lint! { pub INT_PLUS_ONE, - Allow, + complexity, "instead of using x >= y + 1, use x > y" } diff --git a/clippy_lints/src/invalid_ref.rs b/clippy_lints/src/invalid_ref.rs index 6e6b0392a90..037f07be1d7 100644 --- a/clippy_lints/src/invalid_ref.rs +++ b/clippy_lints/src/invalid_ref.rs @@ -13,9 +13,9 @@ use utils::{match_def_path, opt_def_id, paths, span_help_and_lint}; /// ```rust /// let bad_ref: &usize = std::mem::zeroed(); /// ``` -declare_lint! { +declare_clippy_lint! { pub INVALID_REF, - Warn, + correctness, "creation of invalid reference" } diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index 2aabecabff0..f39f60f079c 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -26,9 +26,9 @@ use utils::{in_macro, span_lint}; /// foo(); // prints "foo" /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub ITEMS_AFTER_STATEMENTS, - Allow, + pedantic, "blocks where an item comes after a statement" } diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 668e8e992ec..fd3d9714b86 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -21,9 +21,9 @@ use rustc::ty::layout::LayoutOf; /// B([i32; 8000]), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub LARGE_ENUM_VARIANT, - Warn, + perf, "large size difference between variants on an enum" } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 4499f41fc1d..df3239ee1c7 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -22,9 +22,9 @@ use utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_sugg, wal /// ```rust /// if x.len() == 0 { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub LEN_ZERO, - Warn, + style, "checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` \ could be used instead" } @@ -46,9 +46,9 @@ declare_lint! { /// pub fn len(&self) -> usize { .. } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub LEN_WITHOUT_IS_EMPTY, - Warn, + style, "traits or impls with a public `len` method but no corresponding `is_empty` method" } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 257f619ec29..15230ddf7e4 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -44,9 +44,9 @@ use utils::{snippet, span_lint_and_then}; /// None /// }; /// ``` -declare_lint! { +declare_clippy_lint! { pub USELESS_LET_IF_SEQ, - Warn, + style, "unidiomatic `let mut` declaration followed by initialization in `if`" } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 6d6b1fe0b8c..045b7c02905 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -60,12 +60,6 @@ extern crate url; #[macro_use] extern crate if_chain; -macro_rules! declare_restriction_lint { - { pub $name:tt, $description:tt } => { - declare_lint! { pub $name, Allow, $description } - }; -} - macro_rules! declare_clippy_lint { { pub $name:tt, style, $description:tt } => { declare_lint! { pub $name, Warn, $description } @@ -79,6 +73,18 @@ macro_rules! declare_clippy_lint { { pub $name:tt, perf, $description:tt } => { declare_lint! { pub $name, Warn, $description } }; + { pub $name:tt, pedantic, $description:tt } => { + declare_lint! { pub $name, Allow, $description } + }; + { pub $name:tt, restriction, $description:tt } => { + declare_lint! { pub $name, Allow, $description } + }; + { pub $name:tt, nursery, $description:tt } => { + declare_lint! { pub $name, Allow, $description } + }; + { pub $name:tt, internal, $description:tt } => { + declare_lint! { pub $name, Allow, $description } + }; } pub mod consts; @@ -407,45 +413,36 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { ]); reg.register_lint_group("clippy_pedantic", vec![ - booleans::NONMINIMAL_BOOL, + attrs::INLINE_ALWAYS, + copies::MATCH_SAME_ARMS, + derive::EXPL_IMPL_CLONE_ON_COPY, + doc::DOC_MARKDOWN, empty_enum::EMPTY_ENUM, enum_glob_use::ENUM_GLOB_USE, enum_variants::PUB_ENUM_VARIANT_NAMES, enum_variants::STUTTER, - fallible_impl_from::FALLIBLE_IMPL_FROM, if_not_else::IF_NOT_ELSE, infinite_iter::MAYBE_INFINITE_ITER, - int_plus_one::INT_PLUS_ONE, items_after_statements::ITEMS_AFTER_STATEMENTS, matches::SINGLE_MATCH_ELSE, - mem_forget::MEM_FORGET, methods::FILTER_MAP, methods::OPTION_MAP_UNWRAP_OR, methods::OPTION_MAP_UNWRAP_OR_ELSE, - methods::OPTION_UNWRAP_USED, methods::RESULT_MAP_UNWRAP_OR_ELSE, - methods::RESULT_UNWRAP_USED, - methods::WRONG_PUB_SELF_CONVENTION, misc::USED_UNDERSCORE_BINDING, misc_early::UNSEPARATED_LITERAL_SUFFIX, - missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS, mut_mut::MUT_MUT, mutex_atomic::MUTEX_INTEGER, + needless_continue::NEEDLESS_CONTINUE, non_expressive_names::SIMILAR_NAMES, - print::PRINT_STDOUT, - print::USE_DEBUG, - ranges::RANGE_PLUS_ONE, replace_consts::REPLACE_CONSTS, - shadow::SHADOW_REUSE, - shadow::SHADOW_SAME, - shadow::SHADOW_UNRELATED, - strings::STRING_ADD, strings::STRING_ADD_ASSIGN, types::CAST_POSSIBLE_TRUNCATION, types::CAST_POSSIBLE_WRAP, types::CAST_PRECISION_LOSS, types::CAST_SIGN_LOSS, types::INVALID_UPCAST_COMPARISONS, + types::LINKEDLIST, unicode::NON_ASCII_LITERAL, unicode::UNICODE_NOT_NFC, use_self::USE_SELF, @@ -457,66 +454,29 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { ]); reg.register_lint_group("clippy", vec![ - array_indexing::OUT_OF_BOUNDS_INDEXING, + ]); + + reg.register_lint_group("clippy_style", vec![ assign_ops::ASSIGN_OP_PATTERN, - assign_ops::MISREFACTORED_ASSIGN_OP, - attrs::DEPRECATED_SEMVER, attrs::EMPTY_LINE_AFTER_OUTER_ATTR, - attrs::INLINE_ALWAYS, - attrs::USELESS_ATTRIBUTE, - bit_mask::BAD_BIT_MASK, - bit_mask::INEFFECTIVE_BIT_MASK, bit_mask::VERBOSE_BIT_MASK, blacklisted_name::BLACKLISTED_NAME, block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR, block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT, - booleans::LOGIC_BUG, - bytecount::NAIVE_BYTECOUNT, collapsible_if::COLLAPSIBLE_IF, const_static_lifetime::CONST_STATIC_LIFETIME, - copies::IF_SAME_THEN_ELSE, - copies::IFS_SAME_COND, - copies::MATCH_SAME_ARMS, - cyclomatic_complexity::CYCLOMATIC_COMPLEXITY, - derive::DERIVE_HASH_XOR_EQ, - derive::EXPL_IMPL_CLONE_ON_COPY, - doc::DOC_MARKDOWN, - double_comparison::DOUBLE_COMPARISONS, - double_parens::DOUBLE_PARENS, - drop_forget_ref::DROP_COPY, - drop_forget_ref::DROP_REF, - drop_forget_ref::FORGET_COPY, - drop_forget_ref::FORGET_REF, - entry::MAP_ENTRY, - enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, enum_variants::ENUM_VARIANT_NAMES, enum_variants::MODULE_INCEPTION, - eq_op::EQ_OP, eq_op::OP_REF, - erasing_op::ERASING_OP, - escape::BOXED_LOCAL, eta_reduction::REDUNDANT_CLOSURE, - eval_order_dependence::DIVERGING_SUB_EXPRESSION, - eval_order_dependence::EVAL_ORDER_DEPENDENCE, - explicit_write::EXPLICIT_WRITE, - format::USELESS_FORMAT, formatting::POSSIBLE_MISSING_COMMA, formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING, formatting::SUSPICIOUS_ELSE_FORMATTING, - functions::NOT_UNSAFE_PTR_ARG_DEREF, functions::TOO_MANY_ARGUMENTS, - identity_conversion::IDENTITY_CONVERSION, - identity_op::IDENTITY_OP, if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING, - infinite_iter::INFINITE_ITER, - inline_fn_without_body::INLINE_FN_WITHOUT_BODY, - invalid_ref::INVALID_REF, - large_enum_variant::LARGE_ENUM_VARIANT, len_zero::LEN_WITHOUT_IS_EMPTY, len_zero::LEN_ZERO, let_if_seq::USELESS_LET_IF_SEQ, - lifetimes::NEEDLESS_LIFETIMES, - lifetimes::UNUSED_LIFETIMES, literal_representation::INCONSISTENT_DIGIT_GROUPING, literal_representation::LARGE_DIGIT_GROUPS, literal_representation::UNREADABLE_LITERAL, @@ -525,20 +485,13 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { loops::EXPLICIT_INTO_ITER_LOOP, loops::EXPLICIT_ITER_LOOP, loops::FOR_KV_MAP, - loops::FOR_LOOP_OVER_OPTION, - loops::FOR_LOOP_OVER_RESULT, - loops::ITER_NEXT_LOOP, loops::MANUAL_MEMCPY, - loops::MUT_RANGE_BOUND, loops::NEEDLESS_RANGE_LOOP, loops::NEVER_LOOP, - loops::REVERSE_RANGE_LOOP, loops::UNUSED_COLLECT, - loops::WHILE_IMMUTABLE_CONDITION, loops::WHILE_LET_LOOP, loops::WHILE_LET_ON_ITERATOR, map_clone::MAP_CLONE, - matches::MATCH_AS_REF, matches::MATCH_BOOL, matches::MATCH_OVERLAPPING_ARM, matches::MATCH_REF_PATS, @@ -546,12 +499,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { matches::SINGLE_MATCH, methods::CHARS_LAST_CMP, methods::CHARS_NEXT_CMP, - methods::CLONE_DOUBLE_REF, - methods::CLONE_ON_COPY, methods::FILTER_NEXT, methods::GET_UNWRAP, methods::ITER_CLONED_COLLECT, - methods::ITER_NTH, methods::ITER_SKIP_NEXT, methods::NEW_RET_NO_SELF, methods::OK_EXPECT, @@ -559,19 +509,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { methods::OR_FUN_CALL, methods::SEARCH_IS_SOME, methods::SHOULD_IMPLEMENT_TRAIT, - methods::SINGLE_CHAR_PATTERN, methods::STRING_EXTEND_CHARS, - methods::TEMPORARY_CSTRING_AS_PTR, methods::UNNECESSARY_FOLD, - methods::USELESS_ASREF, methods::WRONG_SELF_CONVENTION, - minmax::MIN_MAX, - misc::CMP_NAN, - misc::CMP_OWNED, - misc::FLOAT_CMP, - misc::MODULO_ONE, misc::REDUNDANT_PATTERN, - misc::SHORT_CIRCUIT_STATEMENT, misc::TOPLEVEL_REF_ARG, misc::ZERO_PTR, misc_early::BUILTIN_TYPE_SHADOW, @@ -580,50 +521,70 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { misc_early::MIXED_CASE_HEX_LITERALS, misc_early::REDUNDANT_CLOSURE_CALL, misc_early::UNNEEDED_FIELD_PATTERN, - misc_early::ZERO_PREFIXED_LITERAL, mut_reference::UNNECESSARY_MUT_PASSED, - mutex_atomic::MUTEX_ATOMIC, needless_bool::BOOL_COMPARISON, - needless_bool::NEEDLESS_BOOL, - needless_borrow::NEEDLESS_BORROW, - needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE, - needless_continue::NEEDLESS_CONTINUE, needless_pass_by_value::NEEDLESS_PASS_BY_VALUE, - needless_update::NEEDLESS_UPDATE, neg_multiply::NEG_MULTIPLY, new_without_default::NEW_WITHOUT_DEFAULT, new_without_default::NEW_WITHOUT_DEFAULT_DERIVE, - no_effect::NO_EFFECT, - no_effect::UNNECESSARY_OPERATION, non_expressive_names::JUST_UNDERSCORES_AND_DIGITS, non_expressive_names::MANY_SINGLE_CHAR_NAMES, ok_if_let::IF_LET_SOME_RESULT, - open_options::NONSENSICAL_OPEN_OPTIONS, - overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, panic::PANIC_PARAMS, - partialeq_ne_impl::PARTIALEQ_NE_IMPL, - precedence::PRECEDENCE, print::PRINT_WITH_NEWLINE, print::PRINTLN_EMPTY_STRING, ptr::CMP_NULL, - ptr::MUT_FROM_REF, ptr::PTR_ARG, question_mark::QUESTION_MARK, - ranges::ITERATOR_STEP_BY_ZERO, ranges::RANGE_MINUS_ONE, - ranges::RANGE_ZIP_WITH_LEN, redundant_field_names::REDUNDANT_FIELD_NAMES, - reference::DEREF_ADDROF, - regex::INVALID_REGEX, regex::REGEX_MACRO, regex::TRIVIAL_REGEX, returns::LET_AND_RETURN, returns::NEEDLESS_RETURN, - serde_api::SERDE_API_MISUSE, strings::STRING_LIT_AS_BYTES, - suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL, - suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL, - swap::ALMOST_SWAPPED, + types::IMPLICIT_HASHER, + types::LET_UNIT_VALUE, + unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME, + ]); + + reg.register_lint_group("clippy_complexity", vec![ + assign_ops::MISREFACTORED_ASSIGN_OP, + booleans::NONMINIMAL_BOOL, + cyclomatic_complexity::CYCLOMATIC_COMPLEXITY, + double_comparison::DOUBLE_COMPARISONS, + double_parens::DOUBLE_PARENS, + eval_order_dependence::DIVERGING_SUB_EXPRESSION, + eval_order_dependence::EVAL_ORDER_DEPENDENCE, + explicit_write::EXPLICIT_WRITE, + format::USELESS_FORMAT, + identity_conversion::IDENTITY_CONVERSION, + identity_op::IDENTITY_OP, + inline_fn_without_body::INLINE_FN_WITHOUT_BODY, + int_plus_one::INT_PLUS_ONE, + lifetimes::NEEDLESS_LIFETIMES, + lifetimes::UNUSED_LIFETIMES, + loops::FOR_LOOP_OVER_OPTION, + loops::FOR_LOOP_OVER_RESULT, + loops::ITER_NEXT_LOOP, + loops::MUT_RANGE_BOUND, + matches::MATCH_AS_REF, + methods::CLONE_ON_COPY, + methods::USELESS_ASREF, + misc::FLOAT_CMP, + misc::SHORT_CIRCUIT_STATEMENT, + misc_early::ZERO_PREFIXED_LITERAL, + needless_bool::NEEDLESS_BOOL, + needless_borrow::NEEDLESS_BORROW, + needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE, + needless_update::NEEDLESS_UPDATE, + no_effect::NO_EFFECT, + no_effect::UNNECESSARY_OPERATION, + overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, + partialeq_ne_impl::PARTIALEQ_NE_IMPL, + precedence::PRECEDENCE, + ranges::RANGE_ZIP_WITH_LEN, + reference::DEREF_ADDROF, swap::MANUAL_SWAP, temporary_assignment::TEMPORARY_ASSIGNMENT, transmute::CROSSPOINTER_TRANSMUTE, @@ -634,39 +595,76 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { transmute::TRANSMUTE_INT_TO_FLOAT, transmute::TRANSMUTE_PTR_TO_REF, transmute::USELESS_TRANSMUTE, - transmute::WRONG_TRANSMUTE, - types::ABSURD_EXTREME_COMPARISONS, types::BORROWED_BOX, types::BOX_VEC, types::CAST_LOSSLESS, types::CHAR_LIT_AS_U8, - types::IMPLICIT_HASHER, - types::LET_UNIT_VALUE, - types::LINKEDLIST, types::OPTION_OPTION, types::TYPE_COMPLEXITY, types::UNIT_ARG, - types::UNIT_CMP, types::UNNECESSARY_CAST, - unicode::ZERO_WIDTH_SPACE, - unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME, - unused_io_amount::UNUSED_IO_AMOUNT, unused_label::UNUSED_LABEL, - vec::USELESS_VEC, zero_div_zero::ZERO_DIVIDED_BY_ZERO, ]); - reg.register_lint_group("clippy_style", vec![ - ]); - - reg.register_lint_group("clippy_complexity", vec![ - ]); - reg.register_lint_group("clippy_correctness", vec![ approx_const::APPROX_CONSTANT, + array_indexing::OUT_OF_BOUNDS_INDEXING, + attrs::DEPRECATED_SEMVER, + attrs::USELESS_ATTRIBUTE, + bit_mask::BAD_BIT_MASK, + bit_mask::INEFFECTIVE_BIT_MASK, + booleans::LOGIC_BUG, + copies::IF_SAME_THEN_ELSE, + copies::IFS_SAME_COND, + derive::DERIVE_HASH_XOR_EQ, + drop_forget_ref::DROP_COPY, + drop_forget_ref::DROP_REF, + drop_forget_ref::FORGET_COPY, + drop_forget_ref::FORGET_REF, + enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, + eq_op::EQ_OP, + erasing_op::ERASING_OP, + functions::NOT_UNSAFE_PTR_ARG_DEREF, + infinite_iter::INFINITE_ITER, + invalid_ref::INVALID_REF, + loops::REVERSE_RANGE_LOOP, + loops::WHILE_IMMUTABLE_CONDITION, + methods::CLONE_DOUBLE_REF, + methods::TEMPORARY_CSTRING_AS_PTR, + minmax::MIN_MAX, + misc::CMP_NAN, + misc::MODULO_ONE, + open_options::NONSENSICAL_OPEN_OPTIONS, + ptr::MUT_FROM_REF, + ranges::ITERATOR_STEP_BY_ZERO, + regex::INVALID_REGEX, + serde_api::SERDE_API_MISUSE, + suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL, + suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL, + swap::ALMOST_SWAPPED, + transmute::WRONG_TRANSMUTE, + types::ABSURD_EXTREME_COMPARISONS, + types::UNIT_CMP, + unicode::ZERO_WIDTH_SPACE, + unused_io_amount::UNUSED_IO_AMOUNT, ]); reg.register_lint_group("clippy_perf", vec![ + bytecount::NAIVE_BYTECOUNT, + entry::MAP_ENTRY, + escape::BOXED_LOCAL, + large_enum_variant::LARGE_ENUM_VARIANT, + methods::ITER_NTH, + methods::SINGLE_CHAR_PATTERN, + misc::CMP_OWNED, + mutex_atomic::MUTEX_ATOMIC, + vec::USELESS_VEC, + ]); + + reg.register_lint_group("clippy_nursery", vec![ + fallible_impl_from::FALLIBLE_IMPL_FROM, + ranges::RANGE_PLUS_ONE, ]); } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index f2381cc39eb..5fe76112e52 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -22,9 +22,9 @@ use syntax::symbol::keywords; /// ```rust /// fn in_and_out<'a>(x: &'a u8, y: u8) -> &'a u8 { x } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_LIFETIMES, - Warn, + complexity, "using explicit lifetimes for references in function arguments when elision rules \ would allow omitting them" } @@ -42,9 +42,9 @@ declare_lint! { /// ```rust /// fn unused_lifetime<'a>(x: u8) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub UNUSED_LIFETIMES, - Warn, + complexity, "unused lifetimes in function definitions" } diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index b505a4c30a5..89396ebd5b3 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -18,9 +18,9 @@ use utils::{in_external_macro, snippet_opt, span_lint_and_sugg}; /// ```rust /// 61864918973511 /// ``` -declare_lint! { +declare_clippy_lint! { pub UNREADABLE_LITERAL, - Warn, + style, "long integer literal without underscores" } @@ -37,9 +37,9 @@ declare_lint! { /// ```rust /// 618_64_9189_73_511 /// ``` -declare_lint! { +declare_clippy_lint! { pub INCONSISTENT_DIGIT_GROUPING, - Warn, + style, "integer literals with digits grouped inconsistently" } @@ -56,9 +56,9 @@ declare_lint! { /// ```rust /// 6186491_8973511 /// ``` -declare_lint! { +declare_clippy_lint! { pub LARGE_DIGIT_GROUPS, - Warn, + style, "grouping digits into groups that are too large" } @@ -74,8 +74,9 @@ declare_lint! { /// `255` => `0xFF` /// `65_535` => `0xFFFF` /// `4_042_322_160` => `0xF0F0_F0F0` -declare_restriction_lint! { +declare_clippy_lint! { pub DECIMAL_LITERAL_REPRESENTATION, + restriction, "using decimal representation when hexadecimal would be better" } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index a76b46a1bcb..48b77be662b 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -38,9 +38,9 @@ use utils::paths; /// dst[i + 64] = src[i]; /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MANUAL_MEMCPY, - Warn, + style, "manually copying items between slices" } @@ -58,9 +58,9 @@ declare_lint! { /// println!("{}", vec[i]); /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_RANGE_LOOP, - Warn, + style, "for-looping over a range of indices where an iterator over items would do" } @@ -77,9 +77,9 @@ declare_lint! { /// // with `y` a `Vec` or slice: /// for x in y.iter() { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub EXPLICIT_ITER_LOOP, - Warn, + style, "for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do" } @@ -95,9 +95,9 @@ declare_lint! { /// // with `y` a `Vec` or slice: /// for x in y.into_iter() { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub EXPLICIT_INTO_ITER_LOOP, - Warn, + style, "for-looping over `_.into_iter()` when `_` would do" } @@ -117,9 +117,9 @@ declare_lint! { /// ```rust /// for x in y.next() { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub ITER_NEXT_LOOP, - Warn, + complexity, "for-looping over `_.next()` which is probably not intended" } @@ -139,9 +139,9 @@ declare_lint! { /// ```rust /// if let Some(x) = option { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub FOR_LOOP_OVER_OPTION, - Warn, + complexity, "for-looping over an `Option`, which is more clearly expressed as an `if let`" } @@ -161,9 +161,9 @@ declare_lint! { /// ```rust /// if let Ok(x) = result { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub FOR_LOOP_OVER_RESULT, - Warn, + complexity, "for-looping over a `Result`, which is more clearly expressed as an `if let`" } @@ -189,9 +189,9 @@ declare_lint! { /// // .. do something with x /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub WHILE_LET_LOOP, - Warn, + style, "`loop { if let { ... } else break }`, which can be written as a `while let` loop" } @@ -207,9 +207,9 @@ declare_lint! { /// ```rust /// vec.iter().map(|x| /* some operation returning () */).collect::>(); /// ``` -declare_lint! { +declare_clippy_lint! { pub UNUSED_COLLECT, - Warn, + style, "`collect()`ing an iterator without using the result; this is usually better \ written as a for loop" } @@ -230,9 +230,9 @@ declare_lint! { /// ```rust /// for x in 5..10-5 { .. } // oops, stray `-` /// ``` -declare_lint! { +declare_clippy_lint! { pub REVERSE_RANGE_LOOP, - Warn, + correctness, "iteration over an empty range, such as `10..0` or `5..5`" } @@ -250,9 +250,9 @@ declare_lint! { /// for i in 0..v.len() { foo(v[i]); /// for i in 0..v.len() { bar(i, v[i]); } /// ``` -declare_lint! { +declare_clippy_lint! { pub EXPLICIT_COUNTER_LOOP, - Warn, + style, "for-looping with an explicit counter when `_.enumerate()` would do" } @@ -268,9 +268,9 @@ declare_lint! { /// ```rust /// loop {} /// ``` -declare_lint! { +declare_clippy_lint! { pub EMPTY_LOOP, - Warn, + style, "empty `loop {}`, which should block or sleep" } @@ -285,9 +285,9 @@ declare_lint! { /// ```rust /// while let Some(val) = iter() { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub WHILE_LET_ON_ITERATOR, - Warn, + style, "using a while-let loop instead of a for loop on an iterator" } @@ -309,9 +309,9 @@ declare_lint! { /// ```rust /// for k in map.keys() { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub FOR_KV_MAP, - Warn, + style, "looping on a map using `iter` when `keys` or `values` would do" } @@ -327,17 +327,29 @@ declare_lint! { /// ```rust /// loop { ..; break; } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEVER_LOOP, - Warn, + style, "any loop that will always `break` or `return`" } -/// TODO: add documentation - -declare_lint! { +/// **What it does:** Checks for loops which have a range bound that is a mutable variable +/// +/// **Why is this bad?** One might think that modifying the mutable variable changes the loop bounds +/// +/// **Known problems:** None +/// +/// **Example:** +/// ```rust +/// let mut foo = 42; +/// for i in 0..foo { +/// foo -= 1; +/// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21 +/// } +/// ``` +declare_clippy_lint! { pub MUT_RANGE_BOUND, - Warn, + complexity, "for loop over a range where one of the bounds is a mutable variable" } @@ -358,9 +370,9 @@ declare_lint! { /// println!("let me loop forever!"); /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub WHILE_IMMUTABLE_CONDITION, - Warn, + correctness, "variables used within while expression are not mutated in the body" } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 4eeaf675c88..23d3c8d433d 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -18,9 +18,9 @@ use utils::{get_arg_name, is_adjusted, iter_input_pats, match_qpath, match_trait /// ```rust /// x.map(|e| e.clone()); /// ``` -declare_lint! { +declare_clippy_lint! { pub MAP_CLONE, - Warn, + style, "using `.map(|x| x.clone())` to clone an iterator or option's contents" } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index b617f098e3e..67971998477 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -25,9 +25,9 @@ use consts::{constant, Constant}; /// _ => () /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub SINGLE_MATCH, - Warn, + style, "a match statement with a single nontrivial arm (i.e. where the other arm \ is `_ => {}`) instead of `if let`" } @@ -46,9 +46,9 @@ declare_lint! { /// _ => bar(other_ref), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub SINGLE_MATCH_ELSE, - Allow, + pedantic, "a match statement with a two arms where the second arm's pattern is a wildcard \ instead of `if let`" } @@ -70,9 +70,9 @@ declare_lint! { /// _ => frob(&x), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MATCH_REF_PATS, - Warn, + style, "a match or `if let` with all arms prefixed with `&` instead of deref-ing the match expression" } @@ -91,9 +91,9 @@ declare_lint! { /// false => bar(), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MATCH_BOOL, - Warn, + style, "a match on a boolean expression instead of an `if..else` block" } @@ -113,9 +113,9 @@ declare_lint! { /// _ => (), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MATCH_OVERLAPPING_ARM, - Warn, + style, "a match with overlapping arms" } @@ -135,9 +135,9 @@ declare_lint! { /// Err(_) => panic!("err"), /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub MATCH_WILD_ERR_ARM, - Warn, + style, "a match with `Err(_)` arm and take drastic actions" } @@ -156,9 +156,9 @@ declare_lint! { /// Some(ref v) => Some(v), /// }; /// ``` -declare_lint! { +declare_clippy_lint! { pub MATCH_AS_REF, - Warn, + complexity, "a match on an Option value instead of using `as_ref()` or `as_mut`" } diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index 103dbb72229..603fbef3421 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -14,9 +14,9 @@ use utils::{match_def_path, opt_def_id, paths, span_lint}; /// ```rust /// mem::forget(Rc::new(55))) /// ``` -declare_lint! { +declare_clippy_lint! { pub MEM_FORGET, - Allow, + restriction, "`mem::forget` usage on `Drop` types, likely to cause memory leaks" } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index a9882bdfe0c..abce4c2d5fb 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -31,9 +31,9 @@ pub struct Pass; /// ```rust /// x.unwrap() /// ``` -declare_lint! { +declare_clippy_lint! { pub OPTION_UNWRAP_USED, - Allow, + restriction, "using `Option.unwrap()`, which should at least get a better message using `expect()`" } @@ -53,9 +53,9 @@ declare_lint! { /// ```rust /// x.unwrap() /// ``` -declare_lint! { +declare_clippy_lint! { pub RESULT_UNWRAP_USED, - Allow, + restriction, "using `Result.unwrap()`, which might be better handled" } @@ -79,9 +79,9 @@ declare_lint! { /// fn add(&self, other: &X) -> X { .. } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub SHOULD_IMPLEMENT_TRAIT, - Warn, + style, "defining a method that should be implementing a std trait" } @@ -108,9 +108,9 @@ declare_lint! { /// fn as_str(self) -> &str { .. } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub WRONG_SELF_CONVENTION, - Warn, + style, "defining a method named with an established prefix (like \"into_\") that takes \ `self` with the wrong convention" } @@ -130,9 +130,9 @@ declare_lint! { /// pub fn as_str(self) -> &str { .. } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub WRONG_PUB_SELF_CONVENTION, - Allow, + restriction, "defining a public method named with an established prefix (like \"into_\") that takes \ `self` with the wrong convention" } @@ -142,15 +142,15 @@ declare_lint! { /// **Why is this bad?** Because you usually call `expect()` on the `Result` /// directly to get a better error message. /// -/// **Known problems:** None. +/// **Known problems:** The error type needs to implement `Debug` /// /// **Example:** /// ```rust /// x.ok().expect("why did I do this again?") /// ``` -declare_lint! { +declare_clippy_lint! { pub OK_EXPECT, - Warn, + style, "using `ok().expect()`, which gives worse error messages than \ calling `expect` directly on the Result" } @@ -166,9 +166,9 @@ declare_lint! { /// ```rust /// x.map(|a| a + 1).unwrap_or(0) /// ``` -declare_lint! { +declare_clippy_lint! { pub OPTION_MAP_UNWRAP_OR, - Allow, + pedantic, "using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as \ `map_or(a, f)`" } @@ -184,9 +184,9 @@ declare_lint! { /// ```rust /// x.map(|a| a + 1).unwrap_or_else(some_function) /// ``` -declare_lint! { +declare_clippy_lint! { pub OPTION_MAP_UNWRAP_OR_ELSE, - Allow, + pedantic, "using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as \ `map_or_else(g, f)`" } @@ -202,9 +202,9 @@ declare_lint! { /// ```rust /// x.map(|a| a + 1).unwrap_or_else(some_function) /// ``` -declare_lint! { +declare_clippy_lint! { pub RESULT_MAP_UNWRAP_OR_ELSE, - Allow, + pedantic, "using `Result.map(f).unwrap_or_else(g)`, which is more succinctly expressed as \ `.ok().map_or_else(g, f)`" } @@ -220,9 +220,9 @@ declare_lint! { /// ```rust /// opt.map_or(None, |a| a + 1) /// ``` -declare_lint! { +declare_clippy_lint! { pub OPTION_MAP_OR_NONE, - Warn, + style, "using `Option.map_or(None, f)`, which is more succinctly expressed as \ `and_then(f)`" } @@ -238,9 +238,9 @@ declare_lint! { /// ```rust /// iter.filter(|x| x == 0).next() /// ``` -declare_lint! { +declare_clippy_lint! { pub FILTER_NEXT, - Warn, + style, "using `filter(p).next()`, which is more succinctly expressed as `.find(p)`" } @@ -257,9 +257,9 @@ declare_lint! { /// ```rust /// iter.filter(|x| x == 0).map(|x| x * 2) /// ``` -declare_lint! { +declare_clippy_lint! { pub FILTER_MAP, - Allow, + pedantic, "using combinations of `filter`, `map`, `filter_map` and `flat_map` which can \ usually be written as a single method call" } @@ -276,9 +276,9 @@ declare_lint! { /// ```rust /// iter.find(|x| x == 0).is_some() /// ``` -declare_lint! { +declare_clippy_lint! { pub SEARCH_IS_SOME, - Warn, + style, "using an iterator search followed by `is_some()`, which is more succinctly \ expressed as a call to `any()`" } @@ -295,9 +295,9 @@ declare_lint! { /// ```rust /// name.chars().next() == Some('_') /// ``` -declare_lint! { +declare_clippy_lint! { pub CHARS_NEXT_CMP, - Warn, + style, "using `.chars().next()` to check if a string starts with a char" } @@ -323,9 +323,9 @@ declare_lint! { /// ```rust /// foo.unwrap_or_default() /// ``` -declare_lint! { +declare_clippy_lint! { pub OR_FUN_CALL, - Warn, + style, "using any `*or` method with a function call, which suggests `*or_else`" } @@ -340,9 +340,9 @@ declare_lint! { /// ```rust /// 42u64.clone() /// ``` -declare_lint! { +declare_clippy_lint! { pub CLONE_ON_COPY, - Warn, + complexity, "using `clone` on a `Copy` type" } @@ -358,8 +358,9 @@ declare_lint! { /// ```rust /// x.clone() /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub CLONE_ON_REF_PTR, + restriction, "using 'clone' on a ref-counted pointer" } @@ -379,9 +380,9 @@ declare_restriction_lint! { /// println!("{:p} {:p}",*y, z); // prints out the same pointer /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub CLONE_DOUBLE_REF, - Warn, + correctness, "using `clone` on `&&T`" } @@ -399,9 +400,9 @@ declare_lint! { /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEW_RET_NO_SELF, - Warn, + style, "not returning `Self` in a `new` method" } @@ -415,9 +416,9 @@ declare_lint! { /// /// **Example:** /// `_.split("x")` could be `_.split('x') -declare_lint! { +declare_clippy_lint! { pub SINGLE_CHAR_PATTERN, - Warn, + perf, "using a single-character str where a char could be used, e.g. \ `_.split(\"x\")`" } @@ -444,9 +445,9 @@ declare_lint! { /// call_some_ffi_func(c_str.as_ptr()); /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub TEMPORARY_CSTRING_AS_PTR, - Warn, + correctness, "getting the inner pointer of a temporary `CString`" } @@ -470,9 +471,9 @@ declare_lint! { /// let bad_vec = some_vec.get(3); /// let bad_slice = &some_vec[..].get(3); /// ``` -declare_lint! { +declare_clippy_lint! { pub ITER_NTH, - Warn, + perf, "using `.iter().nth()` on a standard library type with O(1) element access" } @@ -494,9 +495,9 @@ declare_lint! { /// let bad_vec = some_vec.iter().nth(3); /// let bad_slice = &some_vec[..].iter().nth(3); /// ``` -declare_lint! { +declare_clippy_lint! { pub ITER_SKIP_NEXT, - Warn, + style, "using `.skip(x).next()` on an iterator" } @@ -520,9 +521,9 @@ declare_lint! { /// let last = some_vec[3]; /// some_vec[0] = 1; /// ``` -declare_lint! { +declare_clippy_lint! { pub GET_UNWRAP, - Warn, + style, "using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead" } @@ -549,9 +550,9 @@ declare_lint! { /// s.push_str(abc); /// s.push_str(&def)); /// ``` -declare_lint! { +declare_clippy_lint! { pub STRING_EXTEND_CHARS, - Warn, + style, "using `x.extend(s.chars())` where s is a `&str` or `String`" } @@ -572,9 +573,9 @@ declare_lint! { /// let s = [1,2,3,4,5]; /// let s2 : Vec = s.to_vec(); /// ``` -declare_lint! { +declare_clippy_lint! { pub ITER_CLONED_COLLECT, - Warn, + style, "using `.cloned().collect()` on slice to create a `Vec`" } @@ -590,9 +591,9 @@ declare_lint! { /// ```rust /// name.chars().last() == Some('_') || name.chars().next_back() == Some('-') /// ``` -declare_lint! { +declare_clippy_lint! { pub CHARS_LAST_CMP, - Warn, + style, "using `.chars().last()` or `.chars().next_back()` to check if a string ends with a char" } @@ -613,9 +614,9 @@ declare_lint! { /// let x: &[i32] = &[1,2,3,4,5]; /// do_stuff(x); /// ``` -declare_lint! { +declare_clippy_lint! { pub USELESS_ASREF, - Warn, + complexity, "using `as_ref` where the types before and after the call are the same" } @@ -636,9 +637,9 @@ declare_lint! { /// ```rust /// let _ = (0..3).any(|x| x > 2); /// ``` -declare_lint! { +declare_clippy_lint! { pub UNNECESSARY_FOLD, - Warn, + style, "using `fold` when a more succinct alternative exists" } diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index b5b844e199e..8c19f627f53 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -18,9 +18,9 @@ use utils::{match_def_path, opt_def_id, paths, span_lint}; /// ``` /// It will always be equal to `0`. Probably the author meant to clamp the value /// between 0 and 100, but has erroneously swapped `min` and `max`. -declare_lint! { +declare_clippy_lint! { pub MIN_MAX, - Warn, + correctness, "`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant" } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 172de7a15a5..538a3eaaefd 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -31,9 +31,9 @@ use consts::{constant, Constant}; /// ```rust /// fn foo(ref x: u8) -> bool { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub TOPLEVEL_REF_ARG, - Warn, + style, "an entire binding declared as `ref`, in a function argument or a `let` statement" } @@ -48,9 +48,9 @@ declare_lint! { /// ```rust /// x == NAN /// ``` -declare_lint! { +declare_clippy_lint! { pub CMP_NAN, - Deny, + correctness, "comparisons to NAN, which will always return false, probably not intended" } @@ -70,9 +70,9 @@ declare_lint! { /// y == 1.23f64 /// y != x // where both are floats /// ``` -declare_lint! { +declare_clippy_lint! { pub FLOAT_CMP, - Warn, + complexity, "using `==` or `!=` on float values instead of comparing difference with an epsilon" } @@ -89,9 +89,9 @@ declare_lint! { /// ```rust /// x.to_owned() == y /// ``` -declare_lint! { +declare_clippy_lint! { pub CMP_OWNED, - Warn, + perf, "creating owned instances for comparing with others, e.g. `x == \"foo\".to_string()`" } @@ -108,9 +108,9 @@ declare_lint! { /// ```rust /// x % 1 /// ``` -declare_lint! { +declare_clippy_lint! { pub MODULO_ONE, - Warn, + correctness, "taking a number modulo 1, which always returns 0" } @@ -128,9 +128,9 @@ declare_lint! { /// y @ _ => (), // easier written as `y`, /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub REDUNDANT_PATTERN, - Warn, + style, "using `name @ _` in a pattern" } @@ -150,9 +150,9 @@ declare_lint! { /// let y = _x + 1; // Here we are using `_x`, even though it has a leading /// // underscore. We should rename `_x` to `x` /// ``` -declare_lint! { +declare_clippy_lint! { pub USED_UNDERSCORE_BINDING, - Allow, + pedantic, "using a binding which is prefixed with an underscore" } @@ -170,9 +170,9 @@ declare_lint! { /// ```rust /// f() && g(); // We should write `if f() { g(); }`. /// ``` -declare_lint! { +declare_clippy_lint! { pub SHORT_CIRCUIT_STATEMENT, - Warn, + complexity, "using a short circuit boolean condition as a statement" } @@ -188,9 +188,9 @@ declare_lint! { /// ```rust /// 0 as *const u32 /// ``` -declare_lint! { +declare_clippy_lint! { pub ZERO_PTR, - Warn, + style, "using 0 as *{const, mut} T" } @@ -210,8 +210,9 @@ declare_lint! { /// const ONE == 1.00f64 /// x == ONE // where both are floats /// ``` -declare_restriction_lint! { +declare_clippy_lint! { pub FLOAT_CMP_CONST, + restriction, "using `==` or `!=` on float constants instead of comparing difference with an epsilon" } diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 8ac0c4bf098..0331c976377 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -17,9 +17,9 @@ use utils::{constants, in_external_macro, snippet, snippet_opt, span_help_and_li /// ```rust /// let { a: _, b: ref b, c: _ } = .. /// ``` -declare_lint! { +declare_clippy_lint! { pub UNNEEDED_FIELD_PATTERN, - Warn, + style, "struct fields bound to a wildcard instead of using `..`" } @@ -34,9 +34,9 @@ declare_lint! { /// ```rust /// fn foo(a: i32, _a: i32) {} /// ``` -declare_lint! { +declare_clippy_lint! { pub DUPLICATE_UNDERSCORE_ARGUMENT, - Warn, + style, "function arguments having names which only differ by an underscore" } @@ -52,9 +52,9 @@ declare_lint! { /// ```rust /// (|| 42)() /// ``` -declare_lint! { +declare_clippy_lint! { pub REDUNDANT_CLOSURE_CALL, - Warn, + style, "throwaway closures called in the expression they are defined" } @@ -69,9 +69,9 @@ declare_lint! { /// ```rust /// --x; /// ``` -declare_lint! { +declare_clippy_lint! { pub DOUBLE_NEG, - Warn, + style, "`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++" } @@ -86,9 +86,9 @@ declare_lint! { /// ```rust /// let y = 0x1a9BAcD; /// ``` -declare_lint! { +declare_clippy_lint! { pub MIXED_CASE_HEX_LITERALS, - Warn, + style, "hex literals whose letter digits are not consistently upper- or lowercased" } @@ -103,9 +103,9 @@ declare_lint! { /// ```rust /// let y = 123832i32; /// ``` -declare_lint! { +declare_clippy_lint! { pub UNSEPARATED_LITERAL_SUFFIX, - Allow, + pedantic, "literals whose suffix is not separated by an underscore" } @@ -141,9 +141,9 @@ declare_lint! { /// ``` /// /// prints `83` (as `83 == 0o123` while `123 == 0o173`). -declare_lint! { +declare_clippy_lint! { pub ZERO_PREFIXED_LITERAL, - Warn, + complexity, "integer literals starting with `0`" } @@ -162,9 +162,9 @@ declare_lint! { /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub BUILTIN_TYPE_SHADOW, - Warn, + style, "shadowing a builtin type" } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 82df78ec234..6a83417157b 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -35,9 +35,9 @@ use utils::in_macro; /// This lint fixes that. /// /// **Known problems:** None. -declare_lint! { +declare_clippy_lint! { pub MISSING_DOCS_IN_PRIVATE_ITEMS, - Allow, + restriction, "detects missing documentation for public and private members" } diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index ca1592271b3..13c1c930a05 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -16,9 +16,9 @@ use utils::{higher, in_external_macro, span_lint}; /// ```rust /// let x = &mut &mut y; /// ``` -declare_lint! { +declare_clippy_lint! { pub MUT_MUT, - Allow, + pedantic, "usage of double-mut refs, e.g. `&mut &mut ...`" } diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 63ccc77a03d..5e60ff624a1 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -16,9 +16,9 @@ use utils::span_lint; /// ```rust /// my_vec.push(&mut value) /// ``` -declare_lint! { +declare_clippy_lint! { pub UNNECESSARY_MUT_PASSED, - Warn, + style, "an argument passed as a mutable reference although the callee only demands an \ immutable reference" } diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 3a1ecfbefc7..77af0be0ec8 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -22,9 +22,9 @@ use utils::{match_type, paths, span_lint}; /// ```rust /// let x = Mutex::new(&y); /// ``` -declare_lint! { +declare_clippy_lint! { pub MUTEX_ATOMIC, - Warn, + perf, "using a mutex where an atomic value could be used instead" } @@ -42,9 +42,9 @@ declare_lint! { /// ```rust /// let x = Mutex::new(0usize); /// ``` -declare_lint! { +declare_clippy_lint! { pub MUTEX_INTEGER, - Allow, + pedantic, "using a mutex for an integer type" } diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index bc93190cd09..393e0ec110c 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -24,9 +24,9 @@ use utils::sugg::Sugg; /// ```rust /// if x { false } else { true } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_BOOL, - Warn, + complexity, "if-statements with plain booleans in the then- and else-clause, e.g. \ `if p { true } else { false }`" } @@ -42,9 +42,9 @@ declare_lint! { /// ```rust /// if x == true { } // could be `if x { }` /// ``` -declare_lint! { +declare_clippy_lint! { pub BOOL_COMPARISON, - Warn, + style, "comparing a variable to a boolean, e.g. `if x == true`" } diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index b1388864bdc..a5d89cbcb73 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -20,9 +20,9 @@ use utils::{in_macro, snippet_opt, span_lint_and_then}; /// ```rust /// let x: &i32 = &&&&&&5; /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_BORROW, - Warn, + complexity, "taking a reference that is going to be automatically dereferenced" } diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index f0e5db6d404..35eb599a527 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -42,9 +42,9 @@ use utils::{in_macro, snippet, span_lint_and_then}; /// reference and /// de-referenced. /// As such, it could just be |a| a.is_empty() -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_BORROWED_REFERENCE, - Warn, + complexity, "taking a needless borrowed reference" } diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 9c801ba7495..162cfc7e77f 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -93,9 +93,9 @@ use utils::{in_macro, snippet, snippet_block, span_help_and_lint, trim_multiline /// // Do something useful /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_CONTINUE, - Warn, + pedantic, "`continue` statements that can be replaced by a rearrangement of code" } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index b189fcbff4f..02048c39265 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -39,9 +39,9 @@ use std::borrow::Cow; /// assert_eq!(v.len(), 42); /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_PASS_BY_VALUE, - Warn, + style, "functions taking arguments by value, but not consuming them in its body" } diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 5512a2092b4..fe75bfaf24c 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -15,9 +15,9 @@ use utils::span_lint; /// ```rust /// Point { x: 1, y: 0, ..zero_point } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_UPDATE, - Warn, + complexity, "using `Foo { ..base }` when there are no missing fields" } diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 2ac195f555b..5ddd0d409e3 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -15,9 +15,9 @@ use utils::span_lint; /// ```rust /// x * -1 /// ``` -declare_lint! { +declare_clippy_lint! { pub NEG_MULTIPLY, - Warn, + style, "multiplying integers with -1" } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 5f237095115..54b00081973 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -42,9 +42,9 @@ use utils::sugg::DiagnosticBuilderExt; /// ``` /// /// You can also have `new()` call `Default::default()`. -declare_lint! { +declare_clippy_lint! { pub NEW_WITHOUT_DEFAULT, - Warn, + style, "`fn new() -> Self` method without `Default` implementation" } @@ -72,9 +72,9 @@ declare_lint! { /// ``` /// /// Just prepend `#[derive(Default)]` before the `struct` definition. -declare_lint! { +declare_clippy_lint! { pub NEW_WITHOUT_DEFAULT_DERIVE, - Warn, + style, "`fn new() -> Self` without `#[derive]`able `Default` implementation" } diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index a1139ff7464..1847761416b 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -16,9 +16,9 @@ use std::ops::Deref; /// ```rust /// 0; /// ``` -declare_lint! { +declare_clippy_lint! { pub NO_EFFECT, - Warn, + complexity, "statements with no effect" } @@ -34,9 +34,9 @@ declare_lint! { /// ```rust /// compute_array()[0]; /// ``` -declare_lint! { +declare_clippy_lint! { pub UNNECESSARY_OPERATION, - Warn, + complexity, "outer expressions with no effect" } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index a267900fcbb..057ed157382 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -18,9 +18,9 @@ use utils::{in_macro, span_lint, span_lint_and_then}; /// let checked_exp = something; /// let checked_expr = something_else; /// ``` -declare_lint! { +declare_clippy_lint! { pub SIMILAR_NAMES, - Allow, + pedantic, "similarly named items and bindings" } @@ -36,9 +36,9 @@ declare_lint! { /// ```rust /// let (a, b, c, d, e, f, g) = (...); /// ``` -declare_lint! { +declare_clippy_lint! { pub MANY_SINGLE_CHAR_NAMES, - Warn, + style, "too many single character bindings" } @@ -56,9 +56,9 @@ declare_lint! { /// let ___1 = 1; /// let __1___2 = 11; /// ``` -declare_lint! { +declare_clippy_lint! { pub JUST_UNDERSCORES_AND_DIGITS, - Warn, + style, "unclear name" } diff --git a/clippy_lints/src/ok_if_let.rs b/clippy_lints/src/ok_if_let.rs index b79e90f910b..286ed4b4d48 100644 --- a/clippy_lints/src/ok_if_let.rs +++ b/clippy_lints/src/ok_if_let.rs @@ -26,9 +26,9 @@ use utils::{match_type, method_chain_args, paths, snippet, span_help_and_lint}; /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub IF_LET_SOME_RESULT, - Warn, + style, "usage of `ok()` in `if let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead" } diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 248990f4f37..9ab22560093 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -16,9 +16,9 @@ use utils::{match_type, paths, span_lint, walk_ptrs_ty}; /// ```rust /// OpenOptions::new().read(true).truncate(true) /// ``` -declare_lint! { +declare_clippy_lint! { pub NONSENSICAL_OPEN_OPTIONS, - Warn, + correctness, "nonsensical combination of options for opening a file" } diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 4177f4a3e73..986206a1986 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -13,9 +13,9 @@ use utils::span_lint; /// ```rust /// a + b < a /// ``` -declare_lint! { +declare_clippy_lint! { pub OVERFLOW_CHECK_CONDITIONAL, - Warn, + complexity, "overflow checks inspired by C which are likely to panic" } diff --git a/clippy_lints/src/panic.rs b/clippy_lints/src/panic.rs index a768565518c..bbb62a778b5 100644 --- a/clippy_lints/src/panic.rs +++ b/clippy_lints/src/panic.rs @@ -17,9 +17,9 @@ use utils::{is_direct_expn_of, match_def_path, opt_def_id, paths, resolve_node, /// ```rust /// panic!("This `panic!` is probably missing a parameter there: {}"); /// ``` -declare_lint! { +declare_clippy_lint! { pub PANIC_PARAMS, - Warn, + style, "missing parameters in `panic!` calls" } diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 22dc43eb6c5..787aee71843 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -20,9 +20,9 @@ use utils::{is_automatically_derived, span_lint}; /// fn ne(&self, other: &Foo) -> bool { !(self == other) } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub PARTIALEQ_NE_IMPL, - Warn, + complexity, "re-implementing `PartialEq::ne`" } diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 5d56a927bc0..90e418f0687 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -20,9 +20,9 @@ use utils::{in_macro, snippet, span_lint_and_sugg}; /// **Example:** /// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7 /// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1 -declare_lint! { +declare_clippy_lint! { pub PRECEDENCE, - Warn, + complexity, "operations where precedence may be unclear" } diff --git a/clippy_lints/src/print.rs b/clippy_lints/src/print.rs index 451b27033ea..7413ab2ac63 100644 --- a/clippy_lints/src/print.rs +++ b/clippy_lints/src/print.rs @@ -19,9 +19,9 @@ use utils::{opt_def_id, paths}; /// ```rust /// println!(""); /// ``` -declare_lint! { +declare_clippy_lint! { pub PRINTLN_EMPTY_STRING, - Warn, + style, "using `print!()` with a format string that ends in a newline" } @@ -38,9 +38,9 @@ declare_lint! { /// ```rust /// print!("Hello {}!\n", name); /// ``` -declare_lint! { +declare_clippy_lint! { pub PRINT_WITH_NEWLINE, - Warn, + style, "using `print!()` with a format string that ends in a newline" } @@ -56,9 +56,9 @@ declare_lint! { /// ```rust /// println!("Hello world!"); /// ``` -declare_lint! { +declare_clippy_lint! { pub PRINT_STDOUT, - Allow, + restriction, "printing on stdout" } @@ -72,9 +72,9 @@ declare_lint! { /// ```rust /// println!("{:?}", foo); /// ``` -declare_lint! { +declare_clippy_lint! { pub USE_DEBUG, - Allow, + restriction, "use of `Debug`-based formatting" } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 435812bf962..17f46f78baa 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -42,9 +42,9 @@ use utils::ptr::get_spans; /// ```rust /// fn foo(&Vec) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub PTR_ARG, - Warn, + style, "fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` \ instead, respectively" } @@ -61,9 +61,9 @@ declare_lint! { /// ```rust /// if x == ptr::null { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub CMP_NULL, - Warn, + style, "comparing a pointer to a null pointer, suggesting to use `.is_null()` instead." } @@ -86,9 +86,9 @@ declare_lint! { /// ```rust /// fn foo(&Foo) -> &mut Bar { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub MUT_FROM_REF, - Warn, + correctness, "fns that create mutable refs from immutable ref args" } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 39fcc2b1b8f..9478d874c69 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -25,9 +25,9 @@ use utils::paths::*; /// ```rust /// option?; /// ``` -declare_lint!{ +declare_clippy_lint!{ pub QUESTION_MARK, - Warn, + style, "checks for expressions that could be replaced by the question mark operator" } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index c98df6464d4..5a5dfe04d01 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -18,9 +18,9 @@ use utils::sugg::Sugg; /// ```rust /// for x in (5..5).step_by(0) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub ITERATOR_STEP_BY_ZERO, - Warn, + correctness, "using `Iterator::step_by(0)`, which produces an infinite iterator" } @@ -35,9 +35,9 @@ declare_lint! { /// ```rust /// x.iter().zip(0..x.len()) /// ``` -declare_lint! { +declare_clippy_lint! { pub RANGE_ZIP_WITH_LEN, - Warn, + complexity, "zipping iterator with a range when `enumerate()` would do" } @@ -53,9 +53,9 @@ declare_lint! { /// ```rust /// for x..(y+1) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub RANGE_PLUS_ONE, - Allow, + nursery, "`x..(y+1)` reads better as `x..=y`" } @@ -71,9 +71,9 @@ declare_lint! { /// ```rust /// for x..=(y-1) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub RANGE_MINUS_ONE, - Warn, + style, "`x..=(y-1)` reads better as `x..y`" } diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index a63447575ef..5e24361f1d1 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -20,9 +20,9 @@ use utils::{in_macro, is_range_expression, match_var, span_lint_and_sugg}; /// /// let foo = Foo{ bar: bar } /// ``` -declare_lint! { +declare_clippy_lint! { pub REDUNDANT_FIELD_NAMES, - Warn, + style, "checks for fields in struct literals where shorthands could be used" } diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index fce3c6ad285..0d4332b4a7d 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -15,9 +15,9 @@ use utils::{snippet, span_lint_and_sugg}; /// let a = f(*&mut b); /// let c = *&d; /// ``` -declare_lint! { +declare_clippy_lint! { pub DEREF_ADDROF, - Warn, + complexity, "use of `*&` or `*&mut` in an expression" } diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 93ba3f0e8e7..556ee72d995 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -19,9 +19,9 @@ use consts::{constant, Constant}; /// ```rust /// Regex::new("|") /// ``` -declare_lint! { +declare_clippy_lint! { pub INVALID_REGEX, - Deny, + correctness, "invalid regular expressions" } @@ -38,9 +38,9 @@ declare_lint! { /// ```rust /// Regex::new("^foobar") /// ``` -declare_lint! { +declare_clippy_lint! { pub TRIVIAL_REGEX, - Warn, + style, "trivial regular expressions" } @@ -57,9 +57,9 @@ declare_lint! { /// ```rust /// regex!("foo|bar") /// ``` -declare_lint! { +declare_clippy_lint! { pub REGEX_MACRO, - Warn, + style, "use of `regex!(_)` instead of `Regex::new(_)`" } diff --git a/clippy_lints/src/replace_consts.rs b/clippy_lints/src/replace_consts.rs index 511dbf7a40f..0677cb087d6 100644 --- a/clippy_lints/src/replace_consts.rs +++ b/clippy_lints/src/replace_consts.rs @@ -20,9 +20,9 @@ use utils::{match_def_path, span_lint_and_sugg}; /// ```rust /// static FOO: AtomicIsize = AtomicIsize::new(0); /// ``` -declare_lint! { +declare_clippy_lint! { pub REPLACE_CONSTS, - Allow, + pedantic, "Lint usages of standard library `const`s that could be replaced by `const fn`s" } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 98027885ccf..62038262de4 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -17,9 +17,9 @@ use utils::{in_external_macro, in_macro, match_path_ast, snippet_opt, span_lint_ /// ```rust /// fn foo(x: usize) { return x; } /// ``` -declare_lint! { +declare_clippy_lint! { pub NEEDLESS_RETURN, - Warn, + style, "using a return statement like `return expr;` where an expression would suffice" } @@ -35,9 +35,9 @@ declare_lint! { /// ```rust /// { let x = ..; x } /// ``` -declare_lint! { +declare_clippy_lint! { pub LET_AND_RETURN, - Warn, + style, "creating a let-binding and then immediately returning it like `let x = expr; x` at \ the end of a block" } diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 0ea24a33393..588e22b7cb1 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -5,15 +5,15 @@ use utils::{get_trait_def_id, paths, span_lint}; /// **What it does:** Checks for mis-uses of the serde API. /// /// **Why is this bad?** Serde is very finnicky about how its API should be -/// used, but the type system can't be used to enforce it (yet). +/// used, but the type system can't be used to enforce it (yet?). /// /// **Known problems:** None. /// /// **Example:** Implementing `Visitor::visit_string` but not /// `Visitor::visit_str`. -declare_lint! { +declare_clippy_lint! { pub SERDE_API_MISUSE, - Warn, + correctness, "various things that will negatively affect your serde experience" } diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 92ac65b5abc..8330bb7015b 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -20,9 +20,9 @@ use utils::{contains_name, higher, in_external_macro, iter_input_pats, snippet, /// ```rust /// let x = &x; /// ``` -declare_lint! { +declare_clippy_lint! { pub SHADOW_SAME, - Allow, + restriction, "rebinding a name to itself, e.g. `let mut x = &mut x`" } @@ -41,9 +41,9 @@ declare_lint! { /// ```rust /// let x = x + 1; /// ``` -declare_lint! { +declare_clippy_lint! { pub SHADOW_REUSE, - Allow, + restriction, "rebinding a name to an expression that re-uses the original value, e.g. \ `let x = x + 1`" } @@ -64,9 +64,9 @@ declare_lint! { /// ```rust /// let x = y; let x = z; // shadows the earlier binding /// ``` -declare_lint! { +declare_clippy_lint! { pub SHADOW_UNRELATED, - Allow, + restriction, "rebinding a name without even using the original value" } diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index b7c671c0c48..823ed1be351 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -8,7 +8,8 @@ use utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint /// `let`!). /// /// **Why is this bad?** It's not really bad, but some people think that the -/// `.push_str(_)` method is more readable. +/// `.push_str(_)` method is more readable. Also creates a new heap allocation and throws +/// away the old one. /// /// **Known problems:** None. /// @@ -18,9 +19,9 @@ use utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint /// let mut x = "Hello".to_owned(); /// x = x + ", World"; /// ``` -declare_lint! { +declare_clippy_lint! { pub STRING_ADD_ASSIGN, - Allow, + pedantic, "using `x = x + ..` where x is a `String` instead of `push_str()`" } @@ -46,9 +47,9 @@ declare_lint! { /// let x = "Hello".to_owned(); /// x + ", World" /// ``` -declare_lint! { +declare_clippy_lint! { pub STRING_ADD, - Allow, + restriction, "using `x + ..` where x is a `String` instead of `push_str()`" } @@ -64,9 +65,9 @@ declare_lint! { /// ```rust /// let bs = "a byte string".as_bytes(); /// ``` -declare_lint! { +declare_clippy_lint! { pub STRING_LIT_AS_BYTES, - Warn, + style, "calling `as_bytes` on a string literal instead of using a byte string literal" } diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 2c3abc512bb..2c322ce6b5e 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -21,9 +21,9 @@ use utils::{get_trait_def_id, span_lint}; /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub SUSPICIOUS_ARITHMETIC_IMPL, - Warn, + correctness, "suspicious use of operators in impl of arithmetic trait" } @@ -42,9 +42,9 @@ declare_lint! { /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub SUSPICIOUS_OP_ASSIGN_IMPL, - Warn, + correctness, "suspicious use of operators in impl of OpAssign trait" } diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 25fc666d3e1..47ac45578be 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -17,9 +17,9 @@ use utils::sugg::Sugg; /// b = a; /// a = t; /// ``` -declare_lint! { +declare_clippy_lint! { pub MANUAL_SWAP, - Warn, + complexity, "manual swap of two variables" } @@ -34,9 +34,9 @@ declare_lint! { /// a = b; /// b = a; /// ``` -declare_lint! { +declare_clippy_lint! { pub ALMOST_SWAPPED, - Warn, + correctness, "`foo = bar; bar = foo` sequence" } diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index 877321255c1..459549f1e58 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -15,9 +15,9 @@ use utils::span_lint; /// ```rust /// (0, 0).0 = 1 /// ``` -declare_lint! { +declare_clippy_lint! { pub TEMPORARY_ASSIGNMENT, - Warn, + complexity, "assignments to temporaries" } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 2be5f4764f4..00d6c310c69 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -19,9 +19,9 @@ use utils::{opt_def_id, sugg}; /// ```rust /// let ptr: *const T = core::intrinsics::transmute('x')` /// ``` -declare_lint! { +declare_clippy_lint! { pub WRONG_TRANSMUTE, - Warn, + correctness, "transmutes that are confusing at best, undefined behaviour at worst and always useless" } @@ -37,9 +37,9 @@ declare_lint! { /// ```rust /// core::intrinsics::transmute(t) // where the result type is the same as `t`'s /// ``` -declare_lint! { +declare_clippy_lint! { pub USELESS_TRANSMUTE, - Warn, + complexity, "transmutes that have the same to and from types or could be a cast/coercion" } @@ -55,9 +55,9 @@ declare_lint! { /// core::intrinsics::transmute(t)` // where the result type is the same as /// `*t` or `&t`'s /// ``` -declare_lint! { +declare_clippy_lint! { pub CROSSPOINTER_TRANSMUTE, - Warn, + complexity, "transmutes that have to or from types that are a pointer to the other" } @@ -73,9 +73,9 @@ declare_lint! { /// // can be written: /// let _: &T = &*p; /// ``` -declare_lint! { +declare_clippy_lint! { pub TRANSMUTE_PTR_TO_REF, - Warn, + complexity, "transmutes from a pointer to a reference type" } @@ -100,9 +100,9 @@ declare_lint! { /// // should be: /// let _ = std::char::from_u32(x).unwrap(); /// ``` -declare_lint! { +declare_clippy_lint! { pub TRANSMUTE_INT_TO_CHAR, - Warn, + complexity, "transmutes from an integer to a `char`" } @@ -127,9 +127,9 @@ declare_lint! { /// // should be: /// let _ = std::str::from_utf8(b).unwrap(); /// ``` -declare_lint! { +declare_clippy_lint! { pub TRANSMUTE_BYTES_TO_STR, - Warn, + complexity, "transmutes from a `&[u8]` to a `&str`" } @@ -145,9 +145,9 @@ declare_lint! { /// // should be: /// let _: bool = x != 0; /// ``` -declare_lint! { +declare_clippy_lint! { pub TRANSMUTE_INT_TO_BOOL, - Warn, + complexity, "transmutes from an integer to a `bool`" } @@ -163,9 +163,9 @@ declare_lint! { /// // should be: /// let _: f32 = f32::from_bits(x); /// ``` -declare_lint! { +declare_clippy_lint! { pub TRANSMUTE_INT_TO_FLOAT, - Warn, + complexity, "transmutes from an integer to a float" } @@ -180,9 +180,9 @@ declare_lint! { /// // u32 is 32-bit aligned; u8 is 8-bit aligned /// let _: u32 = unsafe { std::mem::transmute([0u8; 4]) }; /// ``` -declare_lint! { +declare_clippy_lint! { pub MISALIGNED_TRANSMUTE, - Warn, + complexity, "transmutes to a potentially less-aligned type" } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 82a1799ffd8..ba7d4bbbe0f 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -44,9 +44,9 @@ pub struct TypePass; /// values: Vec, /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub BOX_VEC, - Warn, + complexity, "usage of `Box>`, vector elements are already on the heap" } @@ -64,9 +64,9 @@ declare_lint! { /// fn x() -> Option> { /// None /// } -declare_lint! { +declare_clippy_lint! { pub OPTION_OPTION, - Warn, + complexity, "usage of `Option>`" } @@ -99,9 +99,9 @@ declare_lint! { /// ```rust /// let x = LinkedList::new(); /// ``` -declare_lint! { +declare_clippy_lint! { pub LINKEDLIST, - Warn, + pedantic, "usage of LinkedList, usually a vector is faster, or a more specialized data \ structure like a VecDeque" } @@ -123,9 +123,9 @@ declare_lint! { /// ```rust /// fn foo(bar: &T) { ... } /// ``` -declare_lint! { +declare_clippy_lint! { pub BORROWED_BOX, - Warn, + complexity, "a borrow of a boxed type" } @@ -353,9 +353,9 @@ pub struct LetPass; /// ```rust /// let x = { 1; }; /// ``` -declare_lint! { +declare_clippy_lint! { pub LET_UNIT_VALUE, - Warn, + style, "creating a let binding to a value of unit type, which usually can't be used afterwards" } @@ -409,9 +409,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetPass { /// ```rust /// { foo(); bar(); baz(); } /// ``` -declare_lint! { +declare_clippy_lint! { pub UNIT_CMP, - Warn, + correctness, "comparing unit values" } @@ -464,9 +464,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { /// baz(a); /// }) /// ``` -declare_lint! { +declare_clippy_lint! { pub UNIT_ARG, - Warn, + complexity, "passing unit to a function" } @@ -563,9 +563,9 @@ pub struct CastPass; /// ```rust /// let x = u64::MAX; x as f64 /// ``` -declare_lint! { +declare_clippy_lint! { pub CAST_PRECISION_LOSS, - Allow, + pedantic, "casts that cause loss of precision, e.g. `x as f32` where `x: u64`" } @@ -584,9 +584,9 @@ declare_lint! { /// let y: i8 = -1; /// y as u128 // will return 18446744073709551615 /// ``` -declare_lint! { +declare_clippy_lint! { pub CAST_SIGN_LOSS, - Allow, + pedantic, "casts from signed types to unsigned types, e.g. `x as u32` where `x: i32`" } @@ -604,9 +604,9 @@ declare_lint! { /// ```rust /// fn as_u8(x: u64) -> u8 { x as u8 } /// ``` -declare_lint! { +declare_clippy_lint! { pub CAST_POSSIBLE_TRUNCATION, - Allow, + pedantic, "casts that may cause truncation of the value, e.g. `x as u8` where `x: u32`, \ or `x as i32` where `x: f32`" } @@ -628,9 +628,9 @@ declare_lint! { /// ```rust /// u32::MAX as i32 // will yield a value of `-1` /// ``` -declare_lint! { +declare_clippy_lint! { pub CAST_POSSIBLE_WRAP, - Allow, + pedantic, "casts that may cause wrapping around the value, e.g. `x as i32` where `x: u32` \ and `x > i32::MAX`" } @@ -657,9 +657,9 @@ declare_lint! { /// ```rust /// fn as_u64(x: u8) -> u64 { u64::from(x) } /// ``` -declare_lint! { +declare_clippy_lint! { pub CAST_LOSSLESS, - Warn, + complexity, "casts using `as` that are known to be lossless, e.g. `x as u64` where `x: u8`" } @@ -673,9 +673,9 @@ declare_lint! { /// ```rust /// let _ = 2i32 as i32 /// ``` -declare_lint! { +declare_clippy_lint! { pub UNNECESSARY_CAST, - Warn, + complexity, "cast to the same type, e.g. `x as i32` where `x: i32`" } @@ -971,9 +971,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass { /// ```rust /// struct Foo { inner: Rc>>> } /// ``` -declare_lint! { +declare_clippy_lint! { pub TYPE_COMPLEXITY, - Warn, + complexity, "usage of very complex types that might be better factored into `type` definitions" } @@ -1143,9 +1143,9 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { /// ```rust /// b'x' /// ``` -declare_lint! { +declare_clippy_lint! { pub CHAR_LIT_AS_U8, - Warn, + complexity, "casting a character literal to u8" } @@ -1198,9 +1198,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { /// vec.len() <= 0 /// 100 > std::i32::MAX /// ``` -declare_lint! { +declare_clippy_lint! { pub ABSURD_EXTREME_COMPARISONS, - Warn, + correctness, "a comparison with a maximum or minimum value that is always true or false" } @@ -1374,9 +1374,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons { /// ```rust /// let x : u8 = ...; (x as u32) > 300 /// ``` -declare_lint! { +declare_clippy_lint! { pub INVALID_UPCAST_COMPARISONS, - Allow, + pedantic, "a comparison involving an upcast which is always true or false" } @@ -1599,9 +1599,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidUpcastComparisons { /// /// pub foo(map: &mut HashMap) { .. } /// ``` -declare_lint! { +declare_clippy_lint! { pub IMPLICIT_HASHER, - Warn, + style, "missing generalization over different hashers" } diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index c045c870810..21c6b521153 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -14,9 +14,9 @@ use utils::{is_allowed, snippet, span_help_and_lint}; /// /// **Example:** You don't see it, but there may be a zero-width space /// somewhere in this text. -declare_lint! { +declare_clippy_lint! { pub ZERO_WIDTH_SPACE, - Deny, + correctness, "using a zero-width space in a string literal, which is confusing" } @@ -34,9 +34,9 @@ declare_lint! { /// ```rust /// let x = "Hä?" /// ``` -declare_lint! { +declare_clippy_lint! { pub NON_ASCII_LITERAL, - Allow, + pedantic, "using any literal non-ASCII chars in a string literal instead of \ using the `\\u` escape" } @@ -52,9 +52,9 @@ declare_lint! { /// /// **Example:** You may not see it, but “à” and “à” aren't the same string. The /// former when escaped is actually `"a\u{300}"` while the latter is `"\u{e0}"`. -declare_lint! { +declare_clippy_lint! { pub UNICODE_NOT_NFC, - Allow, + pedantic, "using a unicode literal not in NFC normal form (see \ [unicode tr15](http://www.unicode.org/reports/tr15/) for further information)" } diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index a238a9b9283..f852784545c 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -19,9 +19,9 @@ use utils::span_lint; /// extern crate crossbeam; /// use crossbeam::{spawn_unsafe as spawn}; /// ``` -declare_lint! { +declare_clippy_lint! { pub UNSAFE_REMOVED_FROM_NAME, - Warn, + style, "`unsafe` removed from API names on import" } diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 1af63c56107..0c28e9e74ec 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -23,9 +23,9 @@ use utils::{is_try, match_qpath, match_trait_method, paths, span_lint}; /// Ok(()) /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub UNUSED_IO_AMOUNT, - Deny, + correctness, "unused written/read amount" } diff --git a/clippy_lints/src/unused_label.rs b/clippy_lints/src/unused_label.rs index ee708eb13ae..b009420bdb6 100644 --- a/clippy_lints/src/unused_label.rs +++ b/clippy_lints/src/unused_label.rs @@ -21,9 +21,9 @@ use utils::{in_macro, span_lint}; /// if i > 4 { continue } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub UNUSED_LABEL, - Warn, + complexity, "unused labels" } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index a1390596cda..86ce57ca0bd 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -32,9 +32,9 @@ use syntax_pos::symbol::keywords::SelfType; /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub USE_SELF, - Allow, + pedantic, "Unnecessary structure name repetition whereas `Self` is applicable" } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 44e5e84c4a0..2684e3999ab 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -38,9 +38,9 @@ use std::collections::HashMap; /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub LINT_AUTHOR, - Warn, + style, // ok, this is not a style lint, but it's also a noop without the appropriate attribute "helper for writing lints" } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9ade2778e0c..cc98df941e8 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -24,9 +24,9 @@ use syntax::attr; /// visibility inherited from outer item /// extern crate dylib source: "/path/to/foo.so" /// ``` -declare_lint! { +declare_clippy_lint! { pub DEEP_CODE_INSPECTION, - Warn, + style, // not a style lint, but essentially a noop without the appropriate attribute "helper to dump info about code" } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 625ef63a3dc..666db3e0692 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -15,9 +15,9 @@ use std::collections::{HashMap, HashSet}; /// **Known problems:** None. /// /// **Example:** Wrong ordering of the util::paths constants. -declare_lint! { +declare_clippy_lint! { pub CLIPPY_LINTS_INTERNAL, - Allow, + internal, "various things that will negatively affect your clippy experience" } @@ -45,9 +45,9 @@ declare_lint! { /// } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub LINT_WITHOUT_LINT_PASS, - Warn, + internal, "declaring a lint without associating it in a LintPass" } diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 4762c730683..c98cd8719f1 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -16,9 +16,9 @@ use consts::constant; /// ```rust,ignore /// foo(&vec![1, 2]) /// ``` -declare_lint! { +declare_clippy_lint! { pub USELESS_VEC, - Warn, + perf, "useless `vec!`" } diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 416ee155174..16c12702c6c 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -14,9 +14,9 @@ use utils::span_help_and_lint; /// ```rust /// 0.0f32 / 0.0 /// ``` -declare_lint! { +declare_clippy_lint! { pub ZERO_DIVIDED_BY_ZERO, - Warn, + complexity, "usage of `0.0 / 0.0` to obtain NaN instead of std::f32::NaN or std::f64::NaN" } diff --git a/tests/ui/lint_pass.rs b/tests/ui/lint_pass.rs index 29c93e745b3..275be4ea1eb 100644 --- a/tests/ui/lint_pass.rs +++ b/tests/ui/lint_pass.rs @@ -8,8 +8,8 @@ use rustc::lint::{LintPass, LintArray}; -declare_lint! { GOOD_LINT, Warn, "good lint" } -declare_lint! { MISSING_LINT, Warn, "missing lint" } +declare_clippy_lint! { GOOD_LINT, style, "good lint" } +declare_clippy_lint! { MISSING_LINT, style, "missing lint" } pub struct Pass; diff --git a/util/lintlib.py b/util/lintlib.py index 190bce5e2f3..1fddcbdc3fa 100644 --- a/util/lintlib.py +++ b/util/lintlib.py @@ -12,14 +12,27 @@ Config = collections.namedtuple('Config', 'name ty doc default') lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''') level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''') +group_re = re.compile(r'''([a-z_][a-z_0-9]+)''') conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE) confvar_re = re.compile( r'''/// Lint: (\w+). (.*).*\n\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE) +lint_levels = { + "correctness": 'Deny', + "style": 'Warn', + "complexity": 'Warn', + "perf": 'Warn', + "restriction": 'Allow', + "pedantic": 'Allow', + "nursery": 'Allow', +} def parse_lints(lints, filepath): last_comment = [] comment = True + clippy = False + deprecated = False + name = "" with open(filepath) as fp: for line in fp: @@ -29,43 +42,54 @@ def parse_lints(lints, filepath): elif line.startswith("///"): last_comment.append(line[3:]) elif line.startswith("declare_lint!"): + import sys + print "don't use `declare_lint!` in clippy, use `declare_clippy_lint!` instead" + sys.exit(42) + elif line.startswith("declare_clippy_lint!"): comment = False deprecated = False - restriction = False - elif line.startswith("declare_restriction_lint!"): - comment = False - deprecated = False - restriction = True + clippy = True + name = "" elif line.startswith("declare_deprecated_lint!"): comment = False deprecated = True + clippy = False else: last_comment = [] if not comment: - m = lintname_re.search(line) - if m: - name = m.group(1).lower() + if name: + g = group_re.search(line) + if g: + group = g.group(1).lower() + level = lint_levels[group] + log.info("found %s with level %s in %s", + name, level, filepath) + lints.append(Lint(name, level, last_comment, filepath, group)) + last_comment = [] + comment = True + else: + m = lintname_re.search(line) + if m: + name = m.group(1).lower() - if deprecated: - level = "Deprecated" - elif restriction: - level = "Allow" - else: - while True: - m = level_re.search(line) - if m: - level = m.group(0) - break - line = next(fp) - - log.info("found %s with level %s in %s", - name, level, filepath) - lints.append(Lint(name, level, last_comment, filepath)) - last_comment = [] - comment = True - if "}" in line: - log.warn("Warning: missing Lint-Name in %s", filepath) - comment = True + if deprecated: + level = "Deprecated" + else: + while True: + m = level_re.search(line) + if m: + level = m.group(0) + break + line = next(fp) + if not clippy: + log.info("found %s with level %s in %s", + name, level, filepath) + lints.append(Lint(name, level, last_comment, filepath, "deprecated")) + last_comment = [] + comment = True + if "}" in line: + log.warn("Warning: missing Lint-Name in %s", filepath) + comment = True def parse_configs(path): diff --git a/util/update_lints.py b/util/update_lints.py index 0f9c3479439..6c89e5fd0e0 100755 --- a/util/update_lints.py +++ b/util/update_lints.py @@ -8,25 +8,12 @@ import os import re import sys -declare_lint_re = re.compile(r''' - declare_lint! \s* [{(] \s* - pub \s+ (?P[A-Z_][A-Z_0-9]*) \s*,\s* - (?PForbid|Deny|Warn|Allow) \s*,\s* - " (?P(?:[^"\\]+|\\.)*) " \s* [})] -''', re.VERBOSE | re.DOTALL) - declare_deprecated_lint_re = re.compile(r''' declare_deprecated_lint! \s* [{(] \s* pub \s+ (?P[A-Z_][A-Z_0-9]*) \s*,\s* " (?P(?:[^"\\]+|\\.)*) " \s* [})] ''', re.VERBOSE | re.DOTALL) -declare_restriction_lint_re = re.compile(r''' - declare_restriction_lint! \s* [{(] \s* - pub \s+ (?P[A-Z_][A-Z_0-9]*) \s*,\s* - " (?P(?:[^"\\]+|\\.)*) " \s* [})] -''', re.VERBOSE | re.DOTALL) - declare_clippy_lint_re = re.compile(r''' declare_clippy_lint! \s* [{(] \s* pub \s+ (?P[A-Z_][A-Z_0-9]*) \s*,\s* @@ -39,20 +26,13 @@ nl_escape_re = re.compile(r'\\\n\s*') docs_link = 'https://rust-lang-nursery.github.io/rust-clippy/master/index.html' -def collect(lints, deprecated_lints, restriction_lints, clippy_lints, fn): +def collect(lints, deprecated_lints, clippy_lints, fn): """Collect all lints from a file. Adds entries to the lints list as `(module, name, level, desc)`. """ with open(fn) as fp: code = fp.read() - for match in declare_lint_re.finditer(code): - # remove \-newline escapes from description string - desc = nl_escape_re.sub('', match.group('desc')) - lints.append((os.path.splitext(os.path.basename(fn))[0], - match.group('name').lower(), - match.group('level').lower(), - desc.replace('\\"', '"'))) for match in declare_deprecated_lint_re.finditer(code): # remove \-newline escapes from description string @@ -60,14 +40,6 @@ def collect(lints, deprecated_lints, restriction_lints, clippy_lints, fn): deprecated_lints.append((os.path.splitext(os.path.basename(fn))[0], match.group('name').lower(), desc.replace('\\"', '"'))) - - for match in declare_restriction_lint_re.finditer(code): - # remove \-newline escapes from description string - desc = nl_escape_re.sub('', match.group('desc')) - restriction_lints.append((os.path.splitext(os.path.basename(fn))[0], - match.group('name').lower(), - "allow", - desc.replace('\\"', '"'))) for match in declare_clippy_lint_re.finditer(code): # remove \-newline escapes from description string @@ -145,12 +117,14 @@ def replace_region(fn, region_start, region_end, callback, def main(print_only=False, check=False): lints = [] deprecated_lints = [] - restriction_lints = [] clippy_lints = { "correctness": [], "style": [], "complexity": [], "perf": [], + "restriction": [], + "pedantic": [], + "nursery": [], } # check directory @@ -161,7 +135,7 @@ def main(print_only=False, check=False): # collect all lints from source files for fn in os.listdir('clippy_lints/src'): if fn.endswith('.rs'): - collect(lints, deprecated_lints, restriction_lints, clippy_lints, + collect(lints, deprecated_lints, clippy_lints, os.path.join('clippy_lints', 'src', fn)) # determine version @@ -174,7 +148,9 @@ def main(print_only=False, check=False): print('Error: version not found in Cargo.toml!') return - all_lints = lints + restriction_lints + clippy_lints['perf'] + clippy_lints['correctness'] + clippy_lints['style'] + clippy_lints['complexity'] + all_lints = lints + for _, value in clippy_lints.iteritems(): + all_lints += value if print_only: sys.stdout.writelines(gen_table(all_lints)) @@ -223,29 +199,12 @@ def main(print_only=False, check=False): lambda: gen_group(lints, levels=('warn', 'deny')), replace_start=False, write_back=not check) - # same for "clippy_style" lint collection - changed |= replace_region( - 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_style"', r'\]\);', - lambda: gen_group(clippy_lints['style']), - replace_start=False, write_back=not check) - - # same for "clippy_correctness" lint collection - changed |= replace_region( - 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_correctness"', r'\]\);', - lambda: gen_group(clippy_lints['correctness']), - replace_start=False, write_back=not check) - - # same for "clippy_complexity" lint collection - changed |= replace_region( - 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_complexity"', r'\]\);', - lambda: gen_group(clippy_lints['complexity']), - replace_start=False, write_back=not check) - - # same for "clippy_perf" lint collection - changed |= replace_region( - 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_perf"', r'\]\);', - lambda: gen_group(clippy_lints['perf']), - replace_start=False, write_back=not check) + for key, value in clippy_lints.iteritems(): + # same for "clippy_*" lint collections + changed |= replace_region( + 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_' + key + r'"', r'\]\);', + lambda: gen_group(value), + replace_start=False, write_back=not check) # same for "deprecated" lint collection changed |= replace_region( @@ -254,18 +213,6 @@ def main(print_only=False, check=False): replace_start=False, write_back=not check) - # same for "clippy_pedantic" lint collection - changed |= replace_region( - 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_pedantic"', r'\]\);', - lambda: gen_group(lints, levels=('allow',)), - replace_start=False, write_back=not check) - - # same for "clippy_restrictions" lint collection - changed |= replace_region( - 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_restrictions"', - r'\]\);', lambda: gen_group(restriction_lints), - replace_start=False, write_back=not check) - if check and changed: print('Please run util/update_lints.py to regenerate lints lists.') return 1 From eafb9fe8df7bd387bae9eaa6c221a1a96b848111 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 28 Mar 2018 23:49:32 +0200 Subject: [PATCH 3/5] Update test suite --- README.md | 2 +- clippy_lints/src/lib.rs | 207 ++++++++++++++++++++- tests/ui/absurd-extreme-comparisons.stderr | 2 +- tests/ui/bit_masks.stderr | 2 +- tests/ui/cstring.stderr | 2 +- tests/ui/derive.rs | 2 +- tests/ui/derive.stderr | 2 +- tests/ui/dlist.rs | 2 +- tests/ui/double_comparison.stderr | 2 +- tests/ui/infinite_loop.stderr | 2 +- tests/ui/invalid_ref.stderr | 2 +- tests/ui/lint_pass.rs | 24 --- tests/ui/lint_pass.stderr | 10 - tests/ui/matches.rs | 2 +- tests/ui/matches.stderr | 10 +- tests/ui/methods.rs | 2 +- tests/ui/shadow.rs | 2 +- tests/ui/suspicious_arithmetic_impl.stderr | 2 +- tests/ui/unnecessary_clone.stderr | 2 +- tests/ui/zero_div_zero.stderr | 2 +- util/update_lints.py | 30 ++- 21 files changed, 253 insertions(+), 60 deletions(-) delete mode 100644 tests/ui/lint_pass.rs delete mode 100644 tests/ui/lint_pass.stderr diff --git a/README.md b/README.md index 8ccc148942d..c5c327497da 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 208 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html) +[There are 248 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html) More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas! diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 045b7c02905..75aa4dfb418 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -401,15 +401,26 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_late_lint_pass(box redundant_field_names::RedundantFieldNames); - reg.register_lint_group("clippy_restrictions", vec![ + reg.register_lint_group("clippy_restriction", vec![ arithmetic::FLOAT_ARITHMETIC, arithmetic::INTEGER_ARITHMETIC, array_indexing::INDEXING_SLICING, assign_ops::ASSIGN_OPS, else_if_without_else::ELSE_IF_WITHOUT_ELSE, literal_representation::DECIMAL_LITERAL_REPRESENTATION, + mem_forget::MEM_FORGET, methods::CLONE_ON_REF_PTR, + methods::OPTION_UNWRAP_USED, + methods::RESULT_UNWRAP_USED, + methods::WRONG_PUB_SELF_CONVENTION, misc::FLOAT_CMP_CONST, + missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS, + print::PRINT_STDOUT, + print::USE_DEBUG, + shadow::SHADOW_REUSE, + shadow::SHADOW_SAME, + shadow::SHADOW_UNRELATED, + strings::STRING_ADD, ]); reg.register_lint_group("clippy_pedantic", vec![ @@ -454,6 +465,200 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { ]); reg.register_lint_group("clippy", vec![ + approx_const::APPROX_CONSTANT, + array_indexing::OUT_OF_BOUNDS_INDEXING, + assign_ops::ASSIGN_OP_PATTERN, + assign_ops::MISREFACTORED_ASSIGN_OP, + attrs::DEPRECATED_SEMVER, + attrs::EMPTY_LINE_AFTER_OUTER_ATTR, + attrs::USELESS_ATTRIBUTE, + bit_mask::BAD_BIT_MASK, + bit_mask::INEFFECTIVE_BIT_MASK, + bit_mask::VERBOSE_BIT_MASK, + blacklisted_name::BLACKLISTED_NAME, + block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR, + block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT, + booleans::LOGIC_BUG, + booleans::NONMINIMAL_BOOL, + bytecount::NAIVE_BYTECOUNT, + collapsible_if::COLLAPSIBLE_IF, + const_static_lifetime::CONST_STATIC_LIFETIME, + copies::IF_SAME_THEN_ELSE, + copies::IFS_SAME_COND, + cyclomatic_complexity::CYCLOMATIC_COMPLEXITY, + derive::DERIVE_HASH_XOR_EQ, + double_comparison::DOUBLE_COMPARISONS, + double_parens::DOUBLE_PARENS, + drop_forget_ref::DROP_COPY, + drop_forget_ref::DROP_REF, + drop_forget_ref::FORGET_COPY, + drop_forget_ref::FORGET_REF, + entry::MAP_ENTRY, + enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, + enum_variants::ENUM_VARIANT_NAMES, + enum_variants::MODULE_INCEPTION, + eq_op::EQ_OP, + eq_op::OP_REF, + erasing_op::ERASING_OP, + escape::BOXED_LOCAL, + eta_reduction::REDUNDANT_CLOSURE, + eval_order_dependence::DIVERGING_SUB_EXPRESSION, + eval_order_dependence::EVAL_ORDER_DEPENDENCE, + explicit_write::EXPLICIT_WRITE, + format::USELESS_FORMAT, + formatting::POSSIBLE_MISSING_COMMA, + formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING, + formatting::SUSPICIOUS_ELSE_FORMATTING, + functions::NOT_UNSAFE_PTR_ARG_DEREF, + functions::TOO_MANY_ARGUMENTS, + identity_conversion::IDENTITY_CONVERSION, + identity_op::IDENTITY_OP, + if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING, + infinite_iter::INFINITE_ITER, + inline_fn_without_body::INLINE_FN_WITHOUT_BODY, + int_plus_one::INT_PLUS_ONE, + invalid_ref::INVALID_REF, + large_enum_variant::LARGE_ENUM_VARIANT, + len_zero::LEN_WITHOUT_IS_EMPTY, + len_zero::LEN_ZERO, + let_if_seq::USELESS_LET_IF_SEQ, + lifetimes::NEEDLESS_LIFETIMES, + lifetimes::UNUSED_LIFETIMES, + literal_representation::INCONSISTENT_DIGIT_GROUPING, + literal_representation::LARGE_DIGIT_GROUPS, + literal_representation::UNREADABLE_LITERAL, + loops::EMPTY_LOOP, + loops::EXPLICIT_COUNTER_LOOP, + loops::EXPLICIT_INTO_ITER_LOOP, + loops::EXPLICIT_ITER_LOOP, + loops::FOR_KV_MAP, + loops::FOR_LOOP_OVER_OPTION, + loops::FOR_LOOP_OVER_RESULT, + loops::ITER_NEXT_LOOP, + loops::MANUAL_MEMCPY, + loops::MUT_RANGE_BOUND, + loops::NEEDLESS_RANGE_LOOP, + loops::NEVER_LOOP, + loops::REVERSE_RANGE_LOOP, + loops::UNUSED_COLLECT, + loops::WHILE_IMMUTABLE_CONDITION, + loops::WHILE_LET_LOOP, + loops::WHILE_LET_ON_ITERATOR, + map_clone::MAP_CLONE, + matches::MATCH_AS_REF, + matches::MATCH_BOOL, + matches::MATCH_OVERLAPPING_ARM, + matches::MATCH_REF_PATS, + matches::MATCH_WILD_ERR_ARM, + matches::SINGLE_MATCH, + methods::CHARS_LAST_CMP, + methods::CHARS_NEXT_CMP, + methods::CLONE_DOUBLE_REF, + methods::CLONE_ON_COPY, + methods::FILTER_NEXT, + methods::GET_UNWRAP, + methods::ITER_CLONED_COLLECT, + methods::ITER_NTH, + methods::ITER_SKIP_NEXT, + methods::NEW_RET_NO_SELF, + methods::OK_EXPECT, + methods::OPTION_MAP_OR_NONE, + methods::OR_FUN_CALL, + methods::SEARCH_IS_SOME, + methods::SHOULD_IMPLEMENT_TRAIT, + methods::SINGLE_CHAR_PATTERN, + methods::STRING_EXTEND_CHARS, + methods::TEMPORARY_CSTRING_AS_PTR, + methods::UNNECESSARY_FOLD, + methods::USELESS_ASREF, + methods::WRONG_SELF_CONVENTION, + minmax::MIN_MAX, + misc::CMP_NAN, + misc::CMP_OWNED, + misc::FLOAT_CMP, + misc::MODULO_ONE, + misc::REDUNDANT_PATTERN, + misc::SHORT_CIRCUIT_STATEMENT, + misc::TOPLEVEL_REF_ARG, + misc::ZERO_PTR, + misc_early::BUILTIN_TYPE_SHADOW, + misc_early::DOUBLE_NEG, + misc_early::DUPLICATE_UNDERSCORE_ARGUMENT, + misc_early::MIXED_CASE_HEX_LITERALS, + misc_early::REDUNDANT_CLOSURE_CALL, + misc_early::UNNEEDED_FIELD_PATTERN, + misc_early::ZERO_PREFIXED_LITERAL, + mut_reference::UNNECESSARY_MUT_PASSED, + mutex_atomic::MUTEX_ATOMIC, + needless_bool::BOOL_COMPARISON, + needless_bool::NEEDLESS_BOOL, + needless_borrow::NEEDLESS_BORROW, + needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE, + needless_pass_by_value::NEEDLESS_PASS_BY_VALUE, + needless_update::NEEDLESS_UPDATE, + neg_multiply::NEG_MULTIPLY, + new_without_default::NEW_WITHOUT_DEFAULT, + new_without_default::NEW_WITHOUT_DEFAULT_DERIVE, + no_effect::NO_EFFECT, + no_effect::UNNECESSARY_OPERATION, + non_expressive_names::JUST_UNDERSCORES_AND_DIGITS, + non_expressive_names::MANY_SINGLE_CHAR_NAMES, + ok_if_let::IF_LET_SOME_RESULT, + open_options::NONSENSICAL_OPEN_OPTIONS, + overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, + panic::PANIC_PARAMS, + partialeq_ne_impl::PARTIALEQ_NE_IMPL, + precedence::PRECEDENCE, + print::PRINT_WITH_NEWLINE, + print::PRINTLN_EMPTY_STRING, + ptr::CMP_NULL, + ptr::MUT_FROM_REF, + ptr::PTR_ARG, + question_mark::QUESTION_MARK, + ranges::ITERATOR_STEP_BY_ZERO, + ranges::RANGE_MINUS_ONE, + ranges::RANGE_ZIP_WITH_LEN, + redundant_field_names::REDUNDANT_FIELD_NAMES, + reference::DEREF_ADDROF, + regex::INVALID_REGEX, + regex::REGEX_MACRO, + regex::TRIVIAL_REGEX, + returns::LET_AND_RETURN, + returns::NEEDLESS_RETURN, + serde_api::SERDE_API_MISUSE, + strings::STRING_LIT_AS_BYTES, + suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL, + suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL, + swap::ALMOST_SWAPPED, + swap::MANUAL_SWAP, + temporary_assignment::TEMPORARY_ASSIGNMENT, + transmute::CROSSPOINTER_TRANSMUTE, + transmute::MISALIGNED_TRANSMUTE, + transmute::TRANSMUTE_BYTES_TO_STR, + transmute::TRANSMUTE_INT_TO_BOOL, + transmute::TRANSMUTE_INT_TO_CHAR, + transmute::TRANSMUTE_INT_TO_FLOAT, + transmute::TRANSMUTE_PTR_TO_REF, + transmute::USELESS_TRANSMUTE, + transmute::WRONG_TRANSMUTE, + types::ABSURD_EXTREME_COMPARISONS, + types::BORROWED_BOX, + types::BOX_VEC, + types::CAST_LOSSLESS, + types::CHAR_LIT_AS_U8, + types::IMPLICIT_HASHER, + types::LET_UNIT_VALUE, + types::OPTION_OPTION, + types::TYPE_COMPLEXITY, + types::UNIT_ARG, + types::UNIT_CMP, + types::UNNECESSARY_CAST, + unicode::ZERO_WIDTH_SPACE, + unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME, + unused_io_amount::UNUSED_IO_AMOUNT, + unused_label::UNUSED_LABEL, + vec::USELESS_VEC, + zero_div_zero::ZERO_DIVIDED_BY_ZERO, ]); reg.register_lint_group("clippy_style", vec![ diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index 2b1e9ad66fe..72b2f7a3942 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -141,7 +141,7 @@ error: <-comparison of unit values detected. This will always be false 31 | () < {}; | ^^^^^^^ | - = note: `-D unit-cmp` implied by `-D warnings` + = note: #[deny(unit_cmp)] on by default error: aborting due to 18 previous errors diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index 6aad98ff528..e1a4a42914c 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -12,7 +12,7 @@ error: this operation will always return zero. This is likely not the intended o 12 | x & 0 == 0; | ^^^^^ | - = note: `-D erasing-op` implied by `-D warnings` + = note: #[deny(erasing_op)] on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` --> $DIR/bit_masks.rs:15:5 diff --git a/tests/ui/cstring.stderr b/tests/ui/cstring.stderr index 973f26a96db..0e90f696357 100644 --- a/tests/ui/cstring.stderr +++ b/tests/ui/cstring.stderr @@ -4,7 +4,7 @@ error: you are getting the inner pointer of a temporary `CString` 7 | CString::new("foo").unwrap().as_ptr(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D temporary-cstring-as-ptr` implied by `-D warnings` + = note: #[deny(temporary_cstring_as_ptr)] on by default = note: that pointer will be invalid outside this expression help: assign the `CString` to a variable to extend its lifetime --> $DIR/cstring.rs:7:5 diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index 6440f73f31b..f43b8c382a4 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -1,9 +1,9 @@ - #![feature(untagged_unions)] #![allow(dead_code)] +#![warn(expl_impl_clone_on_copy)] use std::hash::{Hash, Hasher}; diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index ffeed948ba5..cbe3fe1029d 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -4,7 +4,7 @@ error: you are deriving `Hash` but have implemented `PartialEq` explicitly 17 | #[derive(Hash)] | ^^^^ | - = note: `-D derive-hash-xor-eq` implied by `-D warnings` + = note: #[deny(derive_hash_xor_eq)] on by default note: `PartialEq` implemented here --> $DIR/derive.rs:20:1 | diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs index 217a564742c..59f0d3fe39b 100644 --- a/tests/ui/dlist.rs +++ b/tests/ui/dlist.rs @@ -2,7 +2,7 @@ #![feature(associated_type_defaults)] -#![warn(clippy)] +#![warn(linkedlist)] #![allow(dead_code, needless_pass_by_value)] extern crate alloc; diff --git a/tests/ui/double_comparison.stderr b/tests/ui/double_comparison.stderr index a97b0a246af..73dd8d02877 100644 --- a/tests/ui/double_comparison.stderr +++ b/tests/ui/double_comparison.stderr @@ -4,7 +4,7 @@ error: This binary expression can be simplified 4 | if x == y || x < y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` | - = note: #[deny(double_comparisons)] on by default + = note: `-D double-comparisons` implied by `-D warnings` error: This binary expression can be simplified --> $DIR/double_comparison.rs:7:8 diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 0bf14bb723b..d24fd925e6d 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -4,7 +4,7 @@ error: Variable in the condition are not mutated in the loop body. This either l 14 | while y < 10 { | ^^^^^^ | - = note: `-D while-immutable-condition` implied by `-D warnings` + = note: #[deny(while_immutable_condition)] on by default error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. --> $DIR/infinite_loop.rs:19:11 diff --git a/tests/ui/invalid_ref.stderr b/tests/ui/invalid_ref.stderr index 420fed01744..f8420738526 100644 --- a/tests/ui/invalid_ref.stderr +++ b/tests/ui/invalid_ref.stderr @@ -4,7 +4,7 @@ error: reference to zeroed memory 27 | let ref_zero: &T = std::mem::zeroed(); // warning | ^^^^^^^^^^^^^^^^^^ | - = note: `-D invalid-ref` implied by `-D warnings` + = note: #[deny(invalid_ref)] on by default = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html error: reference to zeroed memory diff --git a/tests/ui/lint_pass.rs b/tests/ui/lint_pass.rs deleted file mode 100644 index 275be4ea1eb..00000000000 --- a/tests/ui/lint_pass.rs +++ /dev/null @@ -1,24 +0,0 @@ - -#![feature(rustc_private)] -#![feature(macro_vis_matcher)] - -#![warn(lint_without_lint_pass)] - -#[macro_use] extern crate rustc; - -use rustc::lint::{LintPass, LintArray}; - -declare_clippy_lint! { GOOD_LINT, style, "good lint" } -declare_clippy_lint! { MISSING_LINT, style, "missing lint" } - -pub struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array![GOOD_LINT] - } -} - -fn main() { - let _ = MISSING_LINT; -} diff --git a/tests/ui/lint_pass.stderr b/tests/ui/lint_pass.stderr deleted file mode 100644 index 2f9a6813b96..00000000000 --- a/tests/ui/lint_pass.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: the lint `MISSING_LINT` is not added to any `LintPass` - --> $DIR/lint_pass.rs:12:1 - | -12 | declare_lint! { MISSING_LINT, Warn, "missing lint" } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D lint-without-lint-pass` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs index 67a901f65b2..8b1ee1fdcd2 100644 --- a/tests/ui/matches.rs +++ b/tests/ui/matches.rs @@ -4,7 +4,7 @@ #![warn(clippy)] #![allow(unused, if_let_redundant_pattern_matching)] -#![warn(single_match_else)] +#![warn(single_match_else, match_same_arms)] use std::borrow::Cow; diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index 5b4c222e6dc..ab207eb32de 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -56,6 +56,14 @@ error: you seem to be trying to use match for destructuring a single pattern. Co 78 | | }; | |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }` +error: this boolean expression can be simplified + --> $DIR/matches.rs:117:11 + | +117 | match test && test { + | ^^^^^^^^^^^^ help: try: `test` + | + = note: `-D nonminimal-bool` implied by `-D warnings` + error: you seem to be trying to match on a boolean expression --> $DIR/matches.rs:96:5 | @@ -461,5 +469,5 @@ error: use as_mut() instead 329 | | }; | |_____^ help: try this: `mut_owned.as_mut()` -error: aborting due to 37 previous errors +error: aborting due to 38 previous errors diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index 4afab4c8be6..65cac8ec4ff 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -1,7 +1,7 @@ #![feature(const_fn)] -#![warn(clippy, clippy_pedantic)] +#![warn(clippy, clippy_pedantic, option_unwrap_used)] #![allow(blacklisted_name, unused, print_stdout, non_ascii_literal, new_without_default, new_without_default_derive, missing_docs_in_private_items, needless_pass_by_value)] diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index fbe695a7657..79c1030d48b 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -1,7 +1,7 @@ -#![warn(clippy, clippy_pedantic)] +#![warn(clippy, clippy_pedantic, shadow_same, shadow_reuse, shadow_unrelated)] #![allow(unused_parens, unused_variables, missing_docs_in_private_items)] fn id(x: T) -> T { x } diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index 9d5086e5497..8130b1cb31a 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -12,7 +12,7 @@ error: Suspicious use of binary operator in `AddAssign` impl 20 | *self = *self - other; | ^ | - = note: `-D suspicious-op-assign-impl` implied by `-D warnings` + = note: #[deny(suspicious_op_assign_impl)] on by default error: aborting due to 2 previous errors diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 486d2e350f2..3c1ce908022 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -62,7 +62,7 @@ error: using `clone` on a double-reference; this will copy the reference instead 55 | let z: &Vec<_> = y.clone(); | ^^^^^^^^^ | - = note: `-D clone-double-ref` implied by `-D warnings` + = note: #[deny(clone_double_ref)] on by default help: try dereferencing it | 55 | let z: &Vec<_> = &(*y).clone(); diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index bc2a70beffd..f1788fc9ec5 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -4,7 +4,7 @@ error: equal expressions as operands to `/` 7 | let nan = 0.0 / 0.0; | ^^^^^^^^^ | - = note: `-D eq-op` implied by `-D warnings` + = note: #[deny(eq_op)] on by default error: constant division of 0.0 with 0.0 will always result in NaN --> $DIR/zero_div_zero.rs:7:15 diff --git a/util/update_lints.py b/util/update_lints.py index 6c89e5fd0e0..58caa5dac0d 100755 --- a/util/update_lints.py +++ b/util/update_lints.py @@ -26,7 +26,7 @@ nl_escape_re = re.compile(r'\\\n\s*') docs_link = 'https://rust-lang-nursery.github.io/rust-clippy/master/index.html' -def collect(lints, deprecated_lints, clippy_lints, fn): +def collect(deprecated_lints, clippy_lints, fn): """Collect all lints from a file. Adds entries to the lints list as `(module, name, level, desc)`. @@ -88,6 +88,8 @@ def replace_region(fn, region_start, region_end, callback, with open(fn) as fp: lines = list(fp) + found = False + # replace old region with new region new_lines = [] in_old_region = False @@ -102,9 +104,13 @@ def replace_region(fn, region_start, region_end, callback, new_lines.append(line) # old region starts here in_old_region = True + found = True else: new_lines.append(line) + if not found: + print "regex " + region_start + " not found" + # write back to file if write_back: with open(fn, 'w') as fp: @@ -115,7 +121,6 @@ def replace_region(fn, region_start, region_end, callback, def main(print_only=False, check=False): - lints = [] deprecated_lints = [] clippy_lints = { "correctness": [], @@ -135,7 +140,7 @@ def main(print_only=False, check=False): # collect all lints from source files for fn in os.listdir('clippy_lints/src'): if fn.endswith('.rs'): - collect(lints, deprecated_lints, clippy_lints, + collect(deprecated_lints, clippy_lints, os.path.join('clippy_lints', 'src', fn)) # determine version @@ -148,7 +153,16 @@ def main(print_only=False, check=False): print('Error: version not found in Cargo.toml!') return - all_lints = lints + all_lints = [] + clippy_lint_groups = [ + "correctness", + "style", + "complexity", + "perf", + ] + clippy_lint_list = [] + for x in clippy_lint_groups: + clippy_lint_list += clippy_lints[x] for _, value in clippy_lints.iteritems(): all_lints += value @@ -159,8 +173,8 @@ def main(print_only=False, check=False): # update the lint counter in README.md changed = replace_region( 'README.md', - r'^\[There are \d+ lints included in this crate\]\(https://rust-lang-nursery.github.io/rust-clippy/master/index.html\)$', "", - lambda: ['[There are %d lints included in this crate](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)\n' % + r'^\[There are \d+ lints included in this crate!\]\(https://rust-lang-nursery.github.io/rust-clippy/master/index.html\)$', "", + lambda: ['[There are %d lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)\n' % (len(all_lints))], write_back=not check) @@ -193,10 +207,10 @@ def main(print_only=False, check=False): lambda: gen_mods(all_lints), replace_start=False, write_back=not check) - # same for "clippy" lint collection + # same for "clippy_*" lint collections changed |= replace_region( 'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy"', r'\]\);', - lambda: gen_group(lints, levels=('warn', 'deny')), + lambda: gen_group(clippy_lint_list), replace_start=False, write_back=not check) for key, value in clippy_lints.iteritems(): From 82e771d7dcabc86434c47e1ee461c62d30d91289 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 29 Mar 2018 13:04:52 +0200 Subject: [PATCH 4/5] Document lint groups --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c5c327497da..bdd2c7dcb02 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,15 @@ A collection of lints to catch common mistakes and improve your [Rust](https://g [There are 248 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html) +We have a bunch of lint categories to allow you to choose how much clippy is supposed to ~~annoy~~ help you: + +* `clippy` (everything that has no false positives) +* `clippy_pedantic` (everything) +* `clippy_style` (code that should be written in a more idiomatic way) +* `complexity` (code that does something simple but in a complex way) +* `perf` (code that can be written in a faster way) +* **`correctness`** (code that is just outright wrong or very very useless) + More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas! Table of contents: From c1bbc173da5c2b41565d7465c848bac4409c226e Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 29 Mar 2018 13:41:53 +0200 Subject: [PATCH 5/5] Address review comments --- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/lib.rs | 43 ++++++++++++---------- clippy_lints/src/loops.rs | 16 ++++---- clippy_lints/src/methods.rs | 18 ++++----- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/misc_early.rs | 2 +- clippy_lints/src/mutex_atomic.rs | 2 +- clippy_lints/src/needless_bool.rs | 2 +- clippy_lints/src/print.rs | 6 +-- clippy_lints/src/types.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- tests/ui/never_loop.stderr | 2 +- 15 files changed, 54 insertions(+), 51 deletions(-) diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index ff40839637b..1ab13a825da 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -63,7 +63,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub POSSIBLE_MISSING_COMMA, - style, + correctness, "possible missing comma in array" } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 719708d6d18..cb359daba44 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -24,7 +24,7 @@ use utils::{iter_input_pats, span_lint, type_is_unsafe_function}; /// ``` declare_clippy_lint! { pub TOO_MANY_ARGUMENTS, - style, + complexity, "functions with too many arguments" } diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 243498d2d4e..af7de542a91 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -22,7 +22,7 @@ use utils::sugg::DiagnosticBuilderExt; /// ``` declare_clippy_lint! { pub INLINE_FN_WITHOUT_BODY, - complexity, + correctness, "use of `#[inline]` on trait methods without bodies" } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 75aa4dfb418..187b1fcee82 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -85,6 +85,9 @@ macro_rules! declare_clippy_lint { { pub $name:tt, internal, $description:tt } => { declare_lint! { pub $name, Allow, $description } }; + { pub $name:tt, internal_warn, $description:tt } => { + declare_lint! { pub $name, Warn, $description } + }; } pub mod consts; @@ -443,7 +446,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { misc::USED_UNDERSCORE_BINDING, misc_early::UNSEPARATED_LITERAL_SUFFIX, mut_mut::MUT_MUT, - mutex_atomic::MUTEX_INTEGER, needless_continue::NEEDLESS_CONTINUE, non_expressive_names::SIMILAR_NAMES, replace_consts::REPLACE_CONSTS, @@ -674,10 +676,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { enum_variants::MODULE_INCEPTION, eq_op::OP_REF, eta_reduction::REDUNDANT_CLOSURE, - formatting::POSSIBLE_MISSING_COMMA, formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING, formatting::SUSPICIOUS_ELSE_FORMATTING, - functions::TOO_MANY_ARGUMENTS, if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING, len_zero::LEN_WITHOUT_IS_EMPTY, len_zero::LEN_ZERO, @@ -686,15 +686,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { literal_representation::LARGE_DIGIT_GROUPS, literal_representation::UNREADABLE_LITERAL, loops::EMPTY_LOOP, - loops::EXPLICIT_COUNTER_LOOP, loops::EXPLICIT_INTO_ITER_LOOP, loops::EXPLICIT_ITER_LOOP, loops::FOR_KV_MAP, - loops::MANUAL_MEMCPY, loops::NEEDLESS_RANGE_LOOP, - loops::NEVER_LOOP, - loops::UNUSED_COLLECT, - loops::WHILE_LET_LOOP, loops::WHILE_LET_ON_ITERATOR, map_clone::MAP_CLONE, matches::MATCH_BOOL, @@ -703,16 +698,12 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { matches::MATCH_WILD_ERR_ARM, matches::SINGLE_MATCH, methods::CHARS_LAST_CMP, - methods::CHARS_NEXT_CMP, - methods::FILTER_NEXT, methods::GET_UNWRAP, methods::ITER_CLONED_COLLECT, methods::ITER_SKIP_NEXT, methods::NEW_RET_NO_SELF, methods::OK_EXPECT, methods::OPTION_MAP_OR_NONE, - methods::OR_FUN_CALL, - methods::SEARCH_IS_SOME, methods::SHOULD_IMPLEMENT_TRAIT, methods::STRING_EXTEND_CHARS, methods::UNNECESSARY_FOLD, @@ -724,10 +715,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { misc_early::DOUBLE_NEG, misc_early::DUPLICATE_UNDERSCORE_ARGUMENT, misc_early::MIXED_CASE_HEX_LITERALS, - misc_early::REDUNDANT_CLOSURE_CALL, misc_early::UNNEEDED_FIELD_PATTERN, mut_reference::UNNECESSARY_MUT_PASSED, - needless_bool::BOOL_COMPARISON, needless_pass_by_value::NEEDLESS_PASS_BY_VALUE, neg_multiply::NEG_MULTIPLY, new_without_default::NEW_WITHOUT_DEFAULT, @@ -763,22 +752,25 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { eval_order_dependence::EVAL_ORDER_DEPENDENCE, explicit_write::EXPLICIT_WRITE, format::USELESS_FORMAT, + functions::TOO_MANY_ARGUMENTS, identity_conversion::IDENTITY_CONVERSION, identity_op::IDENTITY_OP, - inline_fn_without_body::INLINE_FN_WITHOUT_BODY, int_plus_one::INT_PLUS_ONE, lifetimes::NEEDLESS_LIFETIMES, lifetimes::UNUSED_LIFETIMES, - loops::FOR_LOOP_OVER_OPTION, - loops::FOR_LOOP_OVER_RESULT, - loops::ITER_NEXT_LOOP, + loops::EXPLICIT_COUNTER_LOOP, loops::MUT_RANGE_BOUND, + loops::WHILE_LET_LOOP, matches::MATCH_AS_REF, + methods::CHARS_NEXT_CMP, methods::CLONE_ON_COPY, + methods::FILTER_NEXT, + methods::SEARCH_IS_SOME, methods::USELESS_ASREF, - misc::FLOAT_CMP, misc::SHORT_CIRCUIT_STATEMENT, + misc_early::REDUNDANT_CLOSURE_CALL, misc_early::ZERO_PREFIXED_LITERAL, + needless_bool::BOOL_COMPARISON, needless_bool::NEEDLESS_BOOL, needless_borrow::NEEDLESS_BORROW, needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE, @@ -801,7 +793,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { transmute::TRANSMUTE_PTR_TO_REF, transmute::USELESS_TRANSMUTE, types::BORROWED_BOX, - types::BOX_VEC, types::CAST_LOSSLESS, types::CHAR_LIT_AS_U8, types::OPTION_OPTION, @@ -830,15 +821,22 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, eq_op::EQ_OP, erasing_op::ERASING_OP, + formatting::POSSIBLE_MISSING_COMMA, functions::NOT_UNSAFE_PTR_ARG_DEREF, infinite_iter::INFINITE_ITER, + inline_fn_without_body::INLINE_FN_WITHOUT_BODY, invalid_ref::INVALID_REF, + loops::FOR_LOOP_OVER_OPTION, + loops::FOR_LOOP_OVER_RESULT, + loops::ITER_NEXT_LOOP, + loops::NEVER_LOOP, loops::REVERSE_RANGE_LOOP, loops::WHILE_IMMUTABLE_CONDITION, methods::CLONE_DOUBLE_REF, methods::TEMPORARY_CSTRING_AS_PTR, minmax::MIN_MAX, misc::CMP_NAN, + misc::FLOAT_CMP, misc::MODULO_ONE, open_options::NONSENSICAL_OPEN_OPTIONS, ptr::MUT_FROM_REF, @@ -860,15 +858,20 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { entry::MAP_ENTRY, escape::BOXED_LOCAL, large_enum_variant::LARGE_ENUM_VARIANT, + loops::MANUAL_MEMCPY, + loops::UNUSED_COLLECT, methods::ITER_NTH, + methods::OR_FUN_CALL, methods::SINGLE_CHAR_PATTERN, misc::CMP_OWNED, mutex_atomic::MUTEX_ATOMIC, + types::BOX_VEC, vec::USELESS_VEC, ]); reg.register_lint_group("clippy_nursery", vec![ fallible_impl_from::FALLIBLE_IMPL_FROM, + mutex_atomic::MUTEX_INTEGER, ranges::RANGE_PLUS_ONE, ]); } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 48b77be662b..6f04940ae31 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -40,7 +40,7 @@ use utils::paths; /// ``` declare_clippy_lint! { pub MANUAL_MEMCPY, - style, + perf, "manually copying items between slices" } @@ -119,7 +119,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub ITER_NEXT_LOOP, - complexity, + correctness, "for-looping over `_.next()` which is probably not intended" } @@ -141,7 +141,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub FOR_LOOP_OVER_OPTION, - complexity, + correctness, "for-looping over an `Option`, which is more clearly expressed as an `if let`" } @@ -163,7 +163,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub FOR_LOOP_OVER_RESULT, - complexity, + correctness, "for-looping over a `Result`, which is more clearly expressed as an `if let`" } @@ -191,7 +191,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub WHILE_LET_LOOP, - style, + complexity, "`loop { if let { ... } else break }`, which can be written as a `while let` loop" } @@ -209,7 +209,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub UNUSED_COLLECT, - style, + perf, "`collect()`ing an iterator without using the result; this is usually better \ written as a for loop" } @@ -252,7 +252,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub EXPLICIT_COUNTER_LOOP, - style, + complexity, "for-looping with an explicit counter when `_.enumerate()` would do" } @@ -329,7 +329,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub NEVER_LOOP, - style, + correctness, "any loop that will always `break` or `return`" } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index abce4c2d5fb..50de299ca7d 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -160,7 +160,7 @@ declare_clippy_lint! { /// **Why is this bad?** Readability, this can be written more concisely as /// `_.map_or(_, _)`. /// -/// **Known problems:** None. +/// **Known problems:** The order of the arguments is not in execution order /// /// **Example:** /// ```rust @@ -178,7 +178,7 @@ declare_clippy_lint! { /// **Why is this bad?** Readability, this can be written more concisely as /// `_.map_or_else(_, _)`. /// -/// **Known problems:** None. +/// **Known problems:** The order of the arguments is not in execution order. /// /// **Example:** /// ```rust @@ -214,7 +214,7 @@ declare_clippy_lint! { /// **Why is this bad?** Readability, this can be written more concisely as /// `_.and_then(_)`. /// -/// **Known problems:** None. +/// **Known problems:** The order of the arguments is not in execution order. /// /// **Example:** /// ```rust @@ -240,7 +240,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub FILTER_NEXT, - style, + complexity, "using `filter(p).next()`, which is more succinctly expressed as `.find(p)`" } @@ -278,7 +278,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub SEARCH_IS_SOME, - style, + complexity, "using an iterator search followed by `is_some()`, which is more succinctly \ expressed as a call to `any()`" } @@ -297,7 +297,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub CHARS_NEXT_CMP, - style, + complexity, "using `.chars().next()` to check if a string starts with a char" } @@ -325,7 +325,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub OR_FUN_CALL, - style, + perf, "using any `*or` method with a function call, which suggests `*or_else`" } @@ -347,8 +347,8 @@ declare_clippy_lint! { } /// **What it does:** Checks for usage of `.clone()` on a ref-counted pointer, -/// (Rc, Arc, rc::Weak, or sync::Weak), and suggests calling Clone on -/// the corresponding trait instead. +/// (`Rc`, `Arc`, `rc::Weak`, or `sync::Weak`), and suggests calling Clone via unified +/// function syntax instead (e.g. `Rc::clone(foo)`). /// /// **Why is this bad?**: Calling '.clone()' on an Rc, Arc, or Weak /// can obscure the fact that only the pointer is being cloned, not the underlying diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 538a3eaaefd..e9b6865f0c9 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -72,7 +72,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub FLOAT_CMP, - complexity, + correctness, "using `==` or `!=` on float values instead of comparing difference with an epsilon" } diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 0331c976377..3f3ba6487de 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -54,7 +54,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub REDUNDANT_CLOSURE_CALL, - style, + complexity, "throwaway closures called in the expression they are defined" } diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 77af0be0ec8..b879d76e65c 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -44,7 +44,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub MUTEX_INTEGER, - pedantic, + nursery, "using a mutex for an integer type" } diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 393e0ec110c..e88d76656eb 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -44,7 +44,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub BOOL_COMPARISON, - style, + complexity, "comparing a variable to a boolean, e.g. `if x == true`" } diff --git a/clippy_lints/src/print.rs b/clippy_lints/src/print.rs index 7413ab2ac63..6d9880e1335 100644 --- a/clippy_lints/src/print.rs +++ b/clippy_lints/src/print.rs @@ -8,7 +8,7 @@ use syntax_pos::Span; use utils::{is_expn_of, match_def_path, match_path, resolve_node, span_lint, span_lint_and_sugg}; use utils::{opt_def_id, paths}; -/// **What it does:** This lint warns when you using `println!("")` to +/// **What it does:** This lint warns when you use `println!("")` to /// print a newline. /// /// **Why is this bad?** You should use `println!()`, which is simpler. @@ -22,10 +22,10 @@ use utils::{opt_def_id, paths}; declare_clippy_lint! { pub PRINTLN_EMPTY_STRING, style, - "using `print!()` with a format string that ends in a newline" + "using `println!(\"\")` with an empty string" } -/// **What it does:** This lint warns when you using `print!()` with a format +/// **What it does:** This lint warns when you use `print!()` with a format /// string that /// ends in a newline. /// diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index ba7d4bbbe0f..16a1142efb7 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -46,7 +46,7 @@ pub struct TypePass; /// ``` declare_clippy_lint! { pub BOX_VEC, - complexity, + perf, "usage of `Box>`, vector elements are already on the heap" } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 2684e3999ab..192d6671bcb 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -40,7 +40,7 @@ use std::collections::HashMap; /// ``` declare_clippy_lint! { pub LINT_AUTHOR, - style, // ok, this is not a style lint, but it's also a noop without the appropriate attribute + internal_warn, "helper for writing lints" } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index cc98df941e8..e8d07fbed0d 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -26,7 +26,7 @@ use syntax::attr; /// ``` declare_clippy_lint! { pub DEEP_CODE_INSPECTION, - style, // not a style lint, but essentially a noop without the appropriate attribute + internal_warn, "helper to dump info about code" } diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 83c10c9b193..664be379e35 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -10,7 +10,7 @@ error: this loop never actually loops 13 | | } | |_____^ | - = note: `-D never-loop` implied by `-D warnings` + = note: #[deny(never_loop)] on by default error: this loop never actually loops --> $DIR/never_loop.rs:28:5