Skip to content

Commit e405c68

Browse files
committed
Auto merge of #7350 - camsteffen:suspicious, r=flip1995
Add suspicious group changelog: Introduce `clippy::suspicious` 🤔 group and move several lints into the group Closes #6366. CC #6626. A number of lints are moved from each of `correctness`, `style` and `complexity` groups. Notably I didn't move `suspicious_splitn` since I think that is a `correctness` lint despite the name. Lints moved to `clippy::suspicious`: * `blanket_clippy_restriction_lints` (was `clippy::style`) * `empty_loop` (was `clippy::style`) * `eval_order_dependence` (was `clippy::complexity`) * `float_equality_without_abs` (was `clippy::correctness`) * `for_loops_over_fallibles` (was `clippy::correctness`) * `misrefactored_assign_op` (was `clippy::complexity`) * `mut_range_bound` (was `clippy::complexity`) * `mutable_key_type` (was `clippy::correctness`) * `suspicious_arithmetic_impl` (was `clippy::correctness`) * `suspicious_assignment_formatting` (was `clippy::style`) * `suspicious_else_formatting` (was `clippy::style`) * `suspicious_map` (was `clippy::complexity`) * `suspicious_op_assign_impl` (was `clippy::correctness`) * `suspicious_unary_op_formatting` (was `clippy::style`)
2 parents 8d427b6 + 5b5f0ea commit e405c68

19 files changed

+62
-46
lines changed

.github/workflows/remark.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: actions/[email protected]
2323

2424
- name: Install remark
25-
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended
25+
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended remark-gfm
2626

2727
# Run
2828
- name: Check *.md files

.remarkrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"plugins": [
33
"remark-preset-lint-recommended",
4+
"remark-gfm",
45
["remark-lint-list-item-indent", false],
56
["remark-lint-no-literal-urls", false],
67
["remark-lint-no-shortcut-reference-link", false],

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ A collection of lints to catch common mistakes and improve your [Rust](https://g
1010
Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html).
1111
You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category.
1212

13-
| Category | Description | Default level |
14-
| --------------------- | ----------------------------------------------------------------------- | ------------- |
15-
| `clippy::all` | all lints that are on by default (correctness, style, complexity, perf) | **warn/deny** |
16-
| `clippy::correctness` | code that is outright wrong or very useless | **deny** |
17-
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
18-
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
19-
| `clippy::perf` | code that can be written to run faster | **warn** |
20-
| `clippy::pedantic` | lints which are rather strict or might have false positives | allow |
21-
| `clippy::nursery` | new lints that are still under development | allow |
22-
| `clippy::cargo` | lints for the cargo manifest | allow |
13+
| Category | Description | Default level |
14+
| --------------------- | ----------------------------------------------------------------------------------- | ------------- |
15+
| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** |
16+
| `clippy::correctness` | code that is outright wrong or useless | **deny** |
17+
| `clippy::suspicious` | code that is most likely wrong or useless | **warn** |
18+
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
19+
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
20+
| `clippy::perf` | code that can be written to run faster | **warn** |
21+
| `clippy::pedantic` | lints which are rather strict or might have false positives | allow |
22+
| `clippy::nursery` | new lints that are still under development | allow |
23+
| `clippy::cargo` | lints for the cargo manifest | allow |
2324

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

clippy_dev/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
137137
.possible_values(&[
138138
"style",
139139
"correctness",
140+
"suspicious",
140141
"complexity",
141142
"perf",
142143
"pedantic",

clippy_dev/src/update_lints.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ pub fn run(update_mode: UpdateMode) {
9292
|| {
9393
// clippy::all should only include the following lint groups:
9494
let all_group_lints = usable_lints.iter().filter(|l| {
95-
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
95+
matches!(
96+
&*l.group,
97+
"correctness" | "suspicious" | "style" | "complexity" | "perf"
98+
)
9699
});
97100

98101
gen_lint_group_list(all_group_lints)

clippy_lints/src/assign_ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare_clippy_lint! {
5555
/// a += a + b;
5656
/// ```
5757
pub MISREFACTORED_ASSIGN_OP,
58-
complexity,
58+
suspicious,
5959
"having a variable on both sides of an assign op"
6060
}
6161

clippy_lints/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ declare_clippy_lint! {
173173
/// #![deny(clippy::as_conversions)]
174174
/// ```
175175
pub BLANKET_CLIPPY_RESTRICTION_LINTS,
176-
style,
176+
suspicious,
177177
"enabling the complete restriction group"
178178
}
179179

clippy_lints/src/eval_order_dependence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare_clippy_lint! {
3838
/// let a = tmp + x;
3939
/// ```
4040
pub EVAL_ORDER_DEPENDENCE,
41-
complexity,
41+
suspicious,
4242
"whether a variable read occurs before a write depends on sub-expression evaluation order"
4343
}
4444

clippy_lints/src/float_equality_without_abs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare_clippy_lint! {
3636
/// }
3737
/// ```
3838
pub FLOAT_EQUALITY_WITHOUT_ABS,
39-
correctness,
39+
suspicious,
4040
"float equality check without `.abs()`"
4141
}
4242

clippy_lints/src/formatting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare_clippy_lint! {
2222
/// a =- 42; // confusing, should it be `a -= 42` or `a = -42`?
2323
/// ```
2424
pub SUSPICIOUS_ASSIGNMENT_FORMATTING,
25-
style,
25+
suspicious,
2626
"suspicious formatting of `*=`, `-=` or `!=`"
2727
}
2828

@@ -44,7 +44,7 @@ declare_clippy_lint! {
4444
/// }
4545
/// ```
4646
pub SUSPICIOUS_UNARY_OP_FORMATTING,
47-
style,
47+
suspicious,
4848
"suspicious formatting of unary `-` or `!` on the RHS of a BinOp"
4949
}
5050

@@ -80,7 +80,7 @@ declare_clippy_lint! {
8080
/// }
8181
/// ```
8282
pub SUSPICIOUS_ELSE_FORMATTING,
83-
style,
83+
suspicious,
8484
"suspicious formatting of `else`"
8585
}
8686

clippy_lints/src/lib.rs

+25-17
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ use rustc_session::Session;
6060
/// 4. The `description` that contains a short explanation on what's wrong with code where the
6161
/// lint is triggered.
6262
///
63-
/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default.
64-
/// As said in the README.md of this repository, if the lint level mapping changes, please update
65-
/// README.md.
63+
/// Currently the categories `style`, `correctness`, `suspicious`, `complexity` and `perf` are
64+
/// enabled by default. As said in the README.md of this repository, if the lint level mapping
65+
/// changes, please update README.md.
6666
///
6767
/// # Example
6868
///
@@ -106,6 +106,11 @@ macro_rules! declare_clippy_lint {
106106
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
107107
}
108108
};
109+
{ $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
110+
declare_tool_lint! {
111+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
112+
}
113+
};
109114
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
110115
declare_tool_lint! {
111116
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
@@ -1456,7 +1461,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14561461
store.register_group(true, "clippy::style", Some("clippy_style"), vec![
14571462
LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
14581463
LintId::of(assign_ops::ASSIGN_OP_PATTERN),
1459-
LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
14601464
LintId::of(blacklisted_name::BLACKLISTED_NAME),
14611465
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
14621466
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
@@ -1474,9 +1478,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14741478
LintId::of(eq_op::OP_REF),
14751479
LintId::of(eta_reduction::REDUNDANT_CLOSURE),
14761480
LintId::of(float_literal::EXCESSIVE_PRECISION),
1477-
LintId::of(formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING),
1478-
LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING),
1479-
LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
14801481
LintId::of(from_over_into::FROM_OVER_INTO),
14811482
LintId::of(from_str_radix_10::FROM_STR_RADIX_10),
14821483
LintId::of(functions::DOUBLE_MUST_USE),
@@ -1489,7 +1490,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14891490
LintId::of(len_zero::LEN_ZERO),
14901491
LintId::of(literal_representation::INCONSISTENT_DIGIT_GROUPING),
14911492
LintId::of(literal_representation::UNUSUAL_BYTE_GROUPINGS),
1492-
LintId::of(loops::EMPTY_LOOP),
14931493
LintId::of(loops::FOR_KV_MAP),
14941494
LintId::of(loops::NEEDLESS_RANGE_LOOP),
14951495
LintId::of(loops::SAME_ITEM_PUSH),
@@ -1569,7 +1569,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15691569
]);
15701570

15711571
store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec![
1572-
LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP),
15731572
LintId::of(attrs::DEPRECATED_CFG_ATTR),
15741573
LintId::of(booleans::NONMINIMAL_BOOL),
15751574
LintId::of(casts::CHAR_LIT_AS_U8),
@@ -1579,7 +1578,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15791578
LintId::of(double_parens::DOUBLE_PARENS),
15801579
LintId::of(duration_subsec::DURATION_SUBSEC),
15811580
LintId::of(eval_order_dependence::DIVERGING_SUB_EXPRESSION),
1582-
LintId::of(eval_order_dependence::EVAL_ORDER_DEPENDENCE),
15831581
LintId::of(explicit_write::EXPLICIT_WRITE),
15841582
LintId::of(format::USELESS_FORMAT),
15851583
LintId::of(functions::TOO_MANY_ARGUMENTS),
@@ -1590,7 +1588,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15901588
LintId::of(lifetimes::NEEDLESS_LIFETIMES),
15911589
LintId::of(loops::EXPLICIT_COUNTER_LOOP),
15921590
LintId::of(loops::MANUAL_FLATTEN),
1593-
LintId::of(loops::MUT_RANGE_BOUND),
15941591
LintId::of(loops::SINGLE_ELEMENT_LOOP),
15951592
LintId::of(loops::WHILE_LET_LOOP),
15961593
LintId::of(manual_strip::MANUAL_STRIP),
@@ -1614,7 +1611,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16141611
LintId::of(methods::OPTION_FILTER_MAP),
16151612
LintId::of(methods::SEARCH_IS_SOME),
16161613
LintId::of(methods::SKIP_WHILE_NEXT),
1617-
LintId::of(methods::SUSPICIOUS_MAP),
16181614
LintId::of(methods::UNNECESSARY_FILTER_MAP),
16191615
LintId::of(methods::USELESS_ASREF),
16201616
LintId::of(misc::SHORT_CIRCUIT_STATEMENT),
@@ -1683,7 +1679,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16831679
LintId::of(enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT),
16841680
LintId::of(eq_op::EQ_OP),
16851681
LintId::of(erasing_op::ERASING_OP),
1686-
LintId::of(float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS),
16871682
LintId::of(formatting::POSSIBLE_MISSING_COMMA),
16881683
LintId::of(functions::NOT_UNSAFE_PTR_ARG_DEREF),
16891684
LintId::of(if_let_mutex::IF_LET_MUTEX),
@@ -1693,7 +1688,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16931688
LintId::of(inline_fn_without_body::INLINE_FN_WITHOUT_BODY),
16941689
LintId::of(let_underscore::LET_UNDERSCORE_LOCK),
16951690
LintId::of(literal_representation::MISTYPED_LITERAL_SUFFIXES),
1696-
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
16971691
LintId::of(loops::ITER_NEXT_LOOP),
16981692
LintId::of(loops::NEVER_LOOP),
16991693
LintId::of(loops::WHILE_IMMUTABLE_CONDITION),
@@ -1708,7 +1702,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17081702
LintId::of(misc::CMP_NAN),
17091703
LintId::of(misc::FLOAT_CMP),
17101704
LintId::of(misc::MODULO_ONE),
1711-
LintId::of(mut_key::MUTABLE_KEY_TYPE),
17121705
LintId::of(non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS),
17131706
LintId::of(open_options::NONSENSICAL_OPEN_OPTIONS),
17141707
LintId::of(option_env_unwrap::OPTION_ENV_UNWRAP),
@@ -1719,8 +1712,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17191712
LintId::of(self_assignment::SELF_ASSIGNMENT),
17201713
LintId::of(serde_api::SERDE_API_MISUSE),
17211714
LintId::of(size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT),
1722-
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
1723-
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
17241715
LintId::of(swap::ALMOST_SWAPPED),
17251716
LintId::of(to_string_in_display::TO_STRING_IN_DISPLAY),
17261717
LintId::of(transmute::UNSOUND_COLLECTION_TRANSMUTE),
@@ -1737,6 +1728,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17371728
LintId::of(vec_resize_to_zero::VEC_RESIZE_TO_ZERO),
17381729
]);
17391730

1731+
store.register_group(true, "clippy::suspicious", None, vec![
1732+
LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP),
1733+
LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
1734+
LintId::of(eval_order_dependence::EVAL_ORDER_DEPENDENCE),
1735+
LintId::of(float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS),
1736+
LintId::of(formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING),
1737+
LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING),
1738+
LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
1739+
LintId::of(loops::EMPTY_LOOP),
1740+
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
1741+
LintId::of(loops::MUT_RANGE_BOUND),
1742+
LintId::of(methods::SUSPICIOUS_MAP),
1743+
LintId::of(mut_key::MUTABLE_KEY_TYPE),
1744+
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
1745+
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
1746+
]);
1747+
17401748
store.register_group(true, "clippy::perf", Some("clippy_perf"), vec![
17411749
LintId::of(entry::MAP_ENTRY),
17421750
LintId::of(escape::BOXED_LOCAL),

clippy_lints/src/loops/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ declare_clippy_lint! {
199199
/// }
200200
/// ```
201201
pub FOR_LOOPS_OVER_FALLIBLES,
202-
correctness,
202+
suspicious,
203203
"for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
204204
}
205205

@@ -313,7 +313,7 @@ declare_clippy_lint! {
313313
/// loop {}
314314
/// ```
315315
pub EMPTY_LOOP,
316-
style,
316+
suspicious,
317317
"empty `loop {}`, which should block or sleep"
318318
}
319319

@@ -401,7 +401,7 @@ declare_clippy_lint! {
401401
/// }
402402
/// ```
403403
pub MUT_RANGE_BOUND,
404-
complexity,
404+
suspicious,
405405
"for loop over a range where one of the bounds is a mutable variable"
406406
}
407407

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ declare_clippy_lint! {
12481248
/// let _ = (0..3).map(|x| x + 2).count();
12491249
/// ```
12501250
pub SUSPICIOUS_MAP,
1251-
complexity,
1251+
suspicious,
12521252
"suspicious usage of map"
12531253
}
12541254

clippy_lints/src/mut_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ declare_clippy_lint! {
5050
/// }
5151
/// ```
5252
pub MUTABLE_KEY_TYPE,
53-
correctness,
53+
suspicious,
5454
"Check for mutable `Map`/`Set` key type"
5555
}
5656

clippy_lints/src/suspicious_trait_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ declare_clippy_lint! {
2626
/// }
2727
/// ```
2828
pub SUSPICIOUS_ARITHMETIC_IMPL,
29-
correctness,
29+
suspicious,
3030
"suspicious use of operators in impl of arithmetic trait"
3131
}
3232

@@ -47,7 +47,7 @@ declare_clippy_lint! {
4747
/// }
4848
/// ```
4949
pub SUSPICIOUS_OP_ASSIGN_IMPL,
50-
correctness,
50+
suspicious,
5151
"suspicious use of operators in impl of OpAssign trait"
5252
}
5353

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const DEPRECATED_LINT_GROUP_STR: &str = "deprecated";
4747
const DEPRECATED_LINT_LEVEL: &str = "none";
4848
/// This array holds Clippy's lint groups with their corresponding default lint level. The
4949
/// lint level for deprecated lints is set in `DEPRECATED_LINT_LEVEL`.
50-
const DEFAULT_LINT_LEVELS: [(&str, &str); 8] = [
50+
const DEFAULT_LINT_LEVELS: &[(&str, &str)] = &[
5151
("correctness", "deny"),
52+
("suspicious", "warn"),
5253
("restriction", "allow"),
5354
("style", "warn"),
5455
("pedantic", "allow"),

tests/ui/mut_key.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: mutable key type
44
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[deny(clippy::mutable_key_type)]` on by default
7+
= note: `-D clippy::mutable-key-type` implied by `-D warnings`
88

99
error: mutable key type
1010
--> $DIR/mut_key.rs:27:72

tests/ui/suspicious_arithmetic_impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error: suspicious use of binary operator in `AddAssign` impl
1212
LL | *self = *self - other;
1313
| ^
1414
|
15-
= note: `#[deny(clippy::suspicious_op_assign_impl)]` on by default
15+
= note: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings`
1616

1717
error: suspicious use of binary operator in `MulAssign` impl
1818
--> $DIR/suspicious_arithmetic_impl.rs:32:16

util/lintlib.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
lint_levels = {
2121
"correctness": 'Deny',
22+
"suspicious": 'Warn',
2223
"style": 'Warn',
2324
"complexity": 'Warn',
2425
"perf": 'Warn',

0 commit comments

Comments
 (0)