Skip to content

Commit a47734c

Browse files
authored
Merge pull request #2579 from rust-lang-nursery/lint_audit_mcve
lint audit: Implementation + move one lint
2 parents 411d9c7 + c1bbc17 commit a47734c

File tree

127 files changed

+931
-659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+931
-659
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 208 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
10+
[There are 248 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
11+
12+
We have a bunch of lint categories to allow you to choose how much clippy is supposed to ~~annoy~~ help you:
13+
14+
* `clippy` (everything that has no false positives)
15+
* `clippy_pedantic` (everything)
16+
* `clippy_style` (code that should be written in a more idiomatic way)
17+
* `complexity` (code that does something simple but in a complex way)
18+
* `perf` (code that can be written in a faster way)
19+
* **`correctness`** (code that is just outright wrong or very very useless)
1120

1221
More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas!
1322

clippy_lints/src/approx_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use utils::span_lint;
2626
/// ```rust
2727
/// let x = 3.14;
2828
/// ```
29-
declare_lint! {
29+
declare_clippy_lint! {
3030
pub APPROX_CONSTANT,
31-
Warn,
31+
correctness,
3232
"the approximate of a known float constant (in `std::fXX::consts`)"
3333
}
3434

clippy_lints/src/arithmetic.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use utils::span_lint;
1515
/// ```rust
1616
/// a + 1
1717
/// ```
18-
declare_restriction_lint! {
18+
declare_clippy_lint! {
1919
pub INTEGER_ARITHMETIC,
20+
restriction,
2021
"any integer arithmetic statement"
2122
}
2223

@@ -31,8 +32,9 @@ declare_restriction_lint! {
3132
/// ```rust
3233
/// a + 1.0
3334
/// ```
34-
declare_restriction_lint! {
35+
declare_clippy_lint! {
3536
pub FLOAT_ARITHMETIC,
37+
restriction,
3638
"any floating-point arithmetic statement"
3739
}
3840

clippy_lints/src/array_indexing.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use consts::{constant, Constant};
1919
/// x[9];
2020
/// &x[2..9];
2121
/// ```
22-
declare_lint! {
22+
declare_clippy_lint! {
2323
pub OUT_OF_BOUNDS_INDEXING,
24-
Deny,
24+
correctness,
2525
"out of bounds constant indexing"
2626
}
2727

@@ -39,8 +39,9 @@ declare_lint! {
3939
/// x[2];
4040
/// &x[0..2];
4141
/// ```
42-
declare_restriction_lint! {
42+
declare_clippy_lint! {
4343
pub INDEXING_SLICING,
44+
restriction,
4445
"indexing/slicing usage"
4546
}
4647

clippy_lints/src/assign_ops.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ use utils::{higher, sugg};
1818
/// ```rust
1919
/// a += 1;
2020
/// ```
21-
declare_restriction_lint! {
21+
declare_clippy_lint! {
2222
pub ASSIGN_OPS,
23+
restriction,
2324
"any compound assignment operation"
2425
}
2526

@@ -37,9 +38,9 @@ declare_restriction_lint! {
3738
/// ...
3839
/// a = a + b;
3940
/// ```
40-
declare_lint! {
41+
declare_clippy_lint! {
4142
pub ASSIGN_OP_PATTERN,
42-
Warn,
43+
style,
4344
"assigning the result of an operation on a variable to that same variable"
4445
}
4546

@@ -57,9 +58,9 @@ declare_lint! {
5758
/// ...
5859
/// a += a + b;
5960
/// ```
60-
declare_lint! {
61+
declare_clippy_lint! {
6162
pub MISREFACTORED_ASSIGN_OP,
62-
Warn,
63+
complexity,
6364
"having a variable on both sides of an assign op"
6465
}
6566

clippy_lints/src/attrs.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use utils::{in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snip
2929
/// #[inline(always)]
3030
/// fn not_quite_hot_code(..) { ... }
3131
/// ```
32-
declare_lint! {
32+
declare_clippy_lint! {
3333
pub INLINE_ALWAYS,
34-
Warn,
34+
pedantic,
3535
"use of `#[inline(always)]`"
3636
}
3737

@@ -53,9 +53,9 @@ declare_lint! {
5353
/// #[allow(unused_import)]
5454
/// use foo::bar;
5555
/// ```
56-
declare_lint! {
56+
declare_clippy_lint! {
5757
pub USELESS_ATTRIBUTE,
58-
Warn,
58+
correctness,
5959
"use of lint attributes on `extern crate` items"
6060
}
6161

@@ -72,9 +72,9 @@ declare_lint! {
7272
/// #[deprecated(since = "forever")]
7373
/// fn something_else(..) { ... }
7474
/// ```
75-
declare_lint! {
75+
declare_clippy_lint! {
7676
pub DEPRECATED_SEMVER,
77-
Warn,
77+
correctness,
7878
"use of `#[deprecated(since = \"x\")]` where x is not semver"
7979
}
8080

@@ -103,9 +103,9 @@ declare_lint! {
103103
/// #[inline(always)]
104104
/// fn this_is_fine_too(..) { ... }
105105
/// ```
106-
declare_lint! {
106+
declare_clippy_lint! {
107107
pub EMPTY_LINE_AFTER_OUTER_ATTR,
108-
Warn,
108+
style,
109109
"empty line after outer attribute"
110110
}
111111

clippy_lints/src/bit_mask.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ use consts::{constant, Constant};
3636
/// ```rust
3737
/// if (x & 1 == 2) { … }
3838
/// ```
39-
declare_lint! {
39+
declare_clippy_lint! {
4040
pub BAD_BIT_MASK,
41-
Warn,
41+
correctness,
4242
"expressions of the form `_ & mask == select` that will only ever return `true` or `false`"
4343
}
4444

@@ -64,9 +64,9 @@ declare_lint! {
6464
/// ```rust
6565
/// if (x | 1 > 3) { … }
6666
/// ```
67-
declare_lint! {
67+
declare_clippy_lint! {
6868
pub INEFFECTIVE_BIT_MASK,
69-
Warn,
69+
correctness,
7070
"expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`"
7171
}
7272

@@ -82,9 +82,9 @@ declare_lint! {
8282
/// ```rust
8383
/// x & 0x1111 == 0
8484
/// ```
85-
declare_lint! {
85+
declare_clippy_lint! {
8686
pub VERBOSE_BIT_MASK,
87-
Warn,
87+
style,
8888
"expressions where a bit mask is less readable than the corresponding method call"
8989
}
9090

clippy_lints/src/blacklisted_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use utils::span_lint;
1414
/// ```rust
1515
/// let foo = 3.14;
1616
/// ```
17-
declare_lint! {
17+
declare_clippy_lint! {
1818
pub BLACKLISTED_NAME,
19-
Warn,
19+
style,
2020
"usage of a blacklisted/placeholder name"
2121
}
2222

clippy_lints/src/block_in_if_condition.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use utils::*;
1515
/// ```rust
1616
/// if { true } ..
1717
/// ```
18-
declare_lint! {
18+
declare_clippy_lint! {
1919
pub BLOCK_IN_IF_CONDITION_EXPR,
20-
Warn,
20+
style,
2121
"braces that can be eliminated in conditions, e.g. `if { true } ...`"
2222
}
2323

@@ -34,9 +34,9 @@ declare_lint! {
3434
/// // or
3535
/// if somefunc(|x| { x == 47 }) ..
3636
/// ```
37-
declare_lint! {
37+
declare_clippy_lint! {
3838
pub BLOCK_IN_IF_CONDITION_STMT,
39-
Warn,
39+
style,
4040
"complex blocks in conditions, e.g. `if { let x = true; x } ...`"
4141
}
4242

clippy_lints/src/booleans.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use utils::{in_macro, snippet_opt, span_lint_and_then, SpanlessEq};
2020
/// if a && true // should be: if a
2121
/// if !(a == b) // should be: if a != b
2222
/// ```
23-
declare_lint! {
23+
declare_clippy_lint! {
2424
pub NONMINIMAL_BOOL,
25-
Allow,
25+
complexity,
2626
"boolean expressions that can be written more concisely"
2727
}
2828

@@ -38,9 +38,9 @@ declare_lint! {
3838
/// if a && b || a { ... }
3939
/// ```
4040
/// The `b` is unnecessary, the expression is equivalent to `if a`.
41-
declare_lint! {
41+
declare_clippy_lint! {
4242
pub LOGIC_BUG,
43-
Warn,
43+
correctness,
4444
"boolean expressions that contain terminals which can be eliminated"
4545
}
4646

clippy_lints/src/bytecount.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use utils::{contains_name, get_pat_name, match_type, paths, single_segment_path,
2020
/// ```rust
2121
/// &my_data.filter(|&x| x == 0u8).count() // use bytecount::count instead
2222
/// ```
23-
declare_lint! {
23+
declare_clippy_lint! {
2424
pub NAIVE_BYTECOUNT,
25-
Warn,
25+
perf,
2626
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"
2727
}
2828

clippy_lints/src/collapsible_if.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ use utils::sugg::Sugg;
6262
/// …
6363
/// }
6464
/// ```
65-
declare_lint! {
65+
declare_clippy_lint! {
6666
pub COLLAPSIBLE_IF,
67-
Warn,
67+
style,
6868
"`if`s that can be collapsed (e.g. `if x { if y { ... } }` and `else { if x { ... } }`)"
6969
}
7070

clippy_lints/src/const_static_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use utils::{in_macro, snippet, span_lint_and_then};
1818
/// ```rust
1919
/// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...]
2020
/// ```
21-
declare_lint! {
21+
declare_clippy_lint! {
2222
pub CONST_STATIC_LIFETIME,
23-
Warn,
23+
style,
2424
"Using explicit `'static` lifetime for constants when elision rules would allow omitting them."
2525
}
2626

clippy_lints/src/copies.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use utils::{get_parent_expr, in_macro, snippet, span_lint_and_then, span_note_an
3333
/// …
3434
/// }
3535
/// ```
36-
declare_lint! {
36+
declare_clippy_lint! {
3737
pub IFS_SAME_COND,
38-
Warn,
38+
correctness,
3939
"consecutive `ifs` with the same condition"
4040
}
4141

@@ -54,9 +54,9 @@ declare_lint! {
5454
/// 42
5555
/// };
5656
/// ```
57-
declare_lint! {
57+
declare_clippy_lint! {
5858
pub IF_SAME_THEN_ELSE,
59-
Warn,
59+
correctness,
6060
"if with the same *then* and *else* blocks"
6161
}
6262

@@ -95,9 +95,9 @@ declare_lint! {
9595
/// Quz => quz(),
9696
/// }
9797
/// ```
98-
declare_lint! {
98+
declare_clippy_lint! {
9999
pub MATCH_SAME_ARMS,
100-
Warn,
100+
pedantic,
101101
"`match` with identical arm bodies"
102102
}
103103

clippy_lints/src/cyclomatic_complexity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitSt
1919
/// complexity.
2020
///
2121
/// **Example:** No. You'll see it when you get the warning.
22-
declare_lint! {
22+
declare_clippy_lint! {
2323
pub CYCLOMATIC_COMPLEXITY,
24-
Warn,
24+
complexity,
2525
"functions that should be split up into multiple functions"
2626
}
2727

clippy_lints/src/derive.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ use utils::{is_automatically_derived, is_copy, match_path, span_lint_and_then};
2828
/// ...
2929
/// }
3030
/// ```
31-
declare_lint! {
31+
declare_clippy_lint! {
3232
pub DERIVE_HASH_XOR_EQ,
33-
Warn,
33+
correctness,
3434
"deriving `Hash` but implementing `PartialEq` explicitly"
3535
}
3636

@@ -43,7 +43,7 @@ declare_lint! {
4343
/// nothing more than copy the object, which is what `#[derive(Copy, Clone)]`
4444
/// gets you.
4545
///
46-
/// **Known problems:** None.
46+
/// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925
4747
///
4848
/// **Example:**
4949
/// ```rust
@@ -54,9 +54,9 @@ declare_lint! {
5454
/// ..
5555
/// }
5656
/// ```
57-
declare_lint! {
57+
declare_clippy_lint! {
5858
pub EXPL_IMPL_CLONE_ON_COPY,
59-
Warn,
59+
pedantic,
6060
"implementing `Clone` explicitly on `Copy` types"
6161
}
6262

clippy_lints/src/doc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use url::Url;
2525
/// // ^ `foo_bar` and `that::other::module::foo` should be ticked.
2626
/// fn doit(foo_bar) { .. }
2727
/// ```
28-
declare_lint! {
28+
declare_clippy_lint! {
2929
pub DOC_MARKDOWN,
30-
Warn,
30+
pedantic,
3131
"presence of `_`, `::` or camel-case outside backticks in documentation"
3232
}
3333

clippy_lints/src/double_comparison.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use utils::{snippet, span_lint_and_sugg, SpanlessEq};
2323
/// ```rust
2424
/// x <= y
2525
/// ```
26-
declare_lint! {
26+
declare_clippy_lint! {
2727
pub DOUBLE_COMPARISONS,
28-
Deny,
28+
complexity,
2929
"unnecessary double comparisons that can be simplified"
3030
}
3131

0 commit comments

Comments
 (0)