Skip to content

Commit 4b53581

Browse files
committed
Cleanup attributes in Clippy source files
13 parents 77b0350 + 78323ba + 27aac22 + 0831316 + 26334c7 + 8473c4f + f542e4d + f741eee + 5392763 + 78e72c4 + 8706084 + 5f08d77 + 875f463 commit 4b53581

1,718 files changed

Lines changed: 12410 additions & 11001 deletions

File tree

Some content is hidden

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

CHANGELOG.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,101 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[df995e...master](https://github.com/rust-lang/rust-clippy/compare/df995e...master)
9+
[88f787...master](https://github.com/rust-lang/rust-clippy/compare/88f787...master)
10+
11+
## Rust 1.96
12+
13+
Current stable, released 2026-05-28
14+
15+
[View all 48 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2026-02-24T12%3A30%3A17Z..2026-04-03T17%3A32%3A48Z+base%3Amaster)
16+
17+
### New Lints
18+
19+
* Added [`manual_noop_waker`] to `complexity`
20+
[#16687](https://github.com/rust-lang/rust-clippy/pull/16687)
21+
* Added [`manual_option_zip`] to `complexity`
22+
[#16600](https://github.com/rust-lang/rust-clippy/pull/16600)
23+
* Added [`manual_pop_if`] to `complexity`
24+
[#16582](https://github.com/rust-lang/rust-clippy/pull/16582)
25+
26+
### Enhancements
27+
28+
* [`explicit_counter_loop`] suggest `(init..).take(n)` when loop variable is unused and range is
29+
`0..n`
30+
[#16658](https://github.com/rust-lang/rust-clippy/pull/16658)
31+
* [`iter_kv_map`] handle identity map for `map` and `flat_map`
32+
[#16743](https://github.com/rust-lang/rust-clippy/pull/16743)
33+
* [`manual_noop_waker`] add an MSRV check
34+
[#16850](https://github.com/rust-lang/rust-clippy/pull/16850)
35+
* [`manual_pop_if`] in case the popped value is used, just emit the lint with no suggestion
36+
[#16683](https://github.com/rust-lang/rust-clippy/pull/16683)
37+
* [`manual_pop_if`] also cover `.pop().unwrap_unchecked()`
38+
[#16683](https://github.com/rust-lang/rust-clippy/pull/16683)
39+
* [`manual_pop_if`] detect manual implementations of `BinaryHeap::pop_if()`
40+
[#16734](https://github.com/rust-lang/rust-clippy/pull/16734)
41+
* [`unnecessary_option_map_or_else`] function definitions are no longer traversed when checking if
42+
an expression is the identity
43+
[#15889](https://github.com/rust-lang/rust-clippy/pull/15889)
44+
* [`unnecessary_result_map_or_else`] function definitions are no longer traversed when checking if
45+
an expression is the identity
46+
[#15889](https://github.com/rust-lang/rust-clippy/pull/15889)
47+
* [`question_mark`] fix suggestion-caused error caused by semicolon inference relying only on
48+
parent-node shape
49+
[#16656](https://github.com/rust-lang/rust-clippy/pull/16656)
50+
* Format-related lints now handle `core::panic!`
51+
[#16597](https://github.com/rust-lang/rust-clippy/pull/16597)
52+
* [`explicit_counter_loop`] fix FN when the initializer is not integral
53+
[#16647](https://github.com/rust-lang/rust-clippy/pull/16647)
54+
* [`suboptimal_flops`] fix FN on add and sub assign
55+
[#16625](https://github.com/rust-lang/rust-clippy/pull/16625)
56+
* [`infinite_loop`] fix wrong suggestion to add `-> !` when the loop is inside a conditional branch
57+
[#16619](https://github.com/rust-lang/rust-clippy/pull/16619)
58+
* [`unnecessary_cast`] preserve parentheses in presence of cascaded casts
59+
[#16483](https://github.com/rust-lang/rust-clippy/pull/16483)
60+
* [`cmp_owned`] fix wrong suggestions on `PathBuf`
61+
[#16628](https://github.com/rust-lang/rust-clippy/pull/16628)
62+
* [`redundant_closure`] fix wrong suggestions when local is dereferenced to callable
63+
[#16648](https://github.com/rust-lang/rust-clippy/pull/16648)
64+
65+
### False Positive Fixes
66+
67+
* [`collapsible_if`] fix FP when the inner if contains cfg
68+
[#16757](https://github.com/rust-lang/rust-clippy/pull/16757)
69+
* [`collapsible_match`] fix FP when the pat binding is moved or mutated
70+
[#16708](https://github.com/rust-lang/rust-clippy/pull/16708)
71+
* [`collapsible_match`] fix a case where a suggested transformation changes runtime behavior
72+
[#16878](https://github.com/rust-lang/rust-clippy/pull/16878)
73+
* [`match_same_arms`] fix FP with associated consts
74+
[#16701](https://github.com/rust-lang/rust-clippy/pull/16701)
75+
* [`semicolon_inside_block`] fix FP in `try` blocks where moving `;` changes the block's return
76+
type and causes type errors
77+
[#16697](https://github.com/rust-lang/rust-clippy/pull/16697)
78+
* [`unnecessary_safety_comment`] fix FP on code blocks inside inner docs
79+
[#16559](https://github.com/rust-lang/rust-clippy/pull/16559)
80+
* [`doc_paragraphs_missing_punctuation`] no longer lints punctuated paragraphs with a trailing
81+
emoji
82+
[#16514](https://github.com/rust-lang/rust-clippy/pull/16514)
83+
84+
### ICE Fixes
85+
86+
* [`match_same_arms`] fix ICE in `match_same_arms`
87+
[#16685](https://github.com/rust-lang/rust-clippy/pull/16685)
88+
* [`nonminimal_bool`] fix ICE in `swap_binop()` by using the proper `TypeckResults`
89+
[#16659](https://github.com/rust-lang/rust-clippy/pull/16659)
90+
* Fix ICE when using the `min_generic_const_args` incomplete feature
91+
[#16692](https://github.com/rust-lang/rust-clippy/pull/16692)
92+
93+
### Documentation Improvements
94+
95+
* [`similar_names`] changed the lint docs to reflect its actual behavior
96+
[#16300](https://github.com/rust-lang/rust-clippy/pull/16300)
97+
98+
### Performance Improvements
99+
100+
* [`repeat_vec_with_capacity`] optimized by 96.876% (784M -> 24M instructions)
101+
[#16756](https://github.com/rust-lang/rust-clippy/pull/16756)
102+
* [`manual_is_ascii_check`] optimized by 97.125% (822M -> 23M instructions)
103+
[#16755](https://github.com/rust-lang/rust-clippy/pull/16755)
10104

11105
## Rust 1.95
12106

@@ -6746,6 +6840,7 @@ Released 2018-09-13
67466840
[`for_loop_over_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_option
67476841
[`for_loop_over_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_result
67486842
[`for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
6843+
[`for_unbounded_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_unbounded_range
67496844
[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy
67506845
[`forget_non_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_non_drop
67516846
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
@@ -6906,6 +7001,7 @@ Released 2018-09-13
69067001
[`manual_is_multiple_of`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_multiple_of
69077002
[`manual_is_power_of_two`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_power_of_two
69087003
[`manual_is_variant_and`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_variant_and
7004+
[`manual_isolate_lowest_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_isolate_lowest_one
69097005
[`manual_let_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
69107006
[`manual_main_separator_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str
69117007
[`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
@@ -7376,6 +7472,7 @@ Released 2018-09-13
73767472
[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice
73777473
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice
73787474
[`unused_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
7475+
[`unused_async_trait_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async_trait_impl
73797476
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
73807477
[`unused_enumerate_index`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_enumerate_index
73817478
[`unused_format_specs`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_format_specs

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.97"
3+
version = "0.1.98"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -34,7 +34,7 @@ anstream = "0.6.18"
3434

3535
[dev-dependencies]
3636
cargo_metadata = "0.23"
37-
ui_test = "0.30.5"
37+
ui_test = "0.30.7"
3838
regex = "1.5.5"
3939
serde = { version = "1.0.145", features = ["derive"] }
4040
serde_json = "1.0.122"

book/src/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
8989
#### Lints Section in `Cargo.toml`
9090

9191
Finally, lints can be allowed/denied using [the lints
92-
section](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section)) in the `Cargo.toml` file:
92+
section](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section) in the `Cargo.toml` file:
9393

9494
To deny `clippy::enum_glob_use`, put the following in the `Cargo.toml`:
9595

book/src/development/emitting_lints.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ LL | for _ in 1..1 + 1 {}
8888
| ^^^^^^^^ help: use: `1..=1`
8989
```
9090

91+
### Applicability
92+
9193
**Not all suggestions are always right**, some of them require human
9294
supervision, that's why we have [Applicability][applicability].
9395

@@ -105,23 +107,26 @@ impl<'tcx> LateLintPass<'tcx> for LintName {
105107
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
106108
// Imagine that `some_lint_expr_logic` checks for requirements for emitting the lint
107109
if some_lint_expr_logic(expr) {
108-
span_lint_and_sugg( // < Note this change
110+
span_lint_and_then( // < Note this change
109111
cx,
110112
LINT_NAME,
111-
span,
113+
expr.span,
112114
"message on why the lint is emitted",
113-
"use",
114-
format!("foo + {} * bar", snippet(cx, expr.span, "<default>")), // < Suggestion
115-
Applicability::MachineApplicable,
115+
|diag| {
116+
// v Build and emit the suggestion
117+
let mut app = Applicability::MachineApplicable;
118+
let expr_snippet = snippet_with_applicability(cx, expr.span, "_", &mut app);
119+
let sugg = format!("foo + {expr_snippet} * bar");
120+
diag.span_suggestion(expr.span, "use", sugg, app);
121+
}
116122
);
117123
}
118124
}
119125
}
120126
```
121127

122128
Suggestions generally use the [`format!`][format_macro] macro to interpolate the
123-
old values with the new ones. To get code snippets, use one of the `snippet*`
124-
functions from `clippy_utils::source`.
129+
old values with the new ones. For information on getting code snippets, see [Snippets](emitting_lints.md#snippets).
125130

126131
## How to choose between notes, help messages and suggestions
127132

@@ -183,13 +188,50 @@ error: This `.fold` can be more succinctly expressed as `.any`
183188
|
184189
```
185190

186-
### Snippets
191+
## Snippets
187192

188193
Snippets are pieces of the source code (as a string), they are extracted
189-
generally using the [`snippet`][snippet_fn] function.
194+
generally using the various `snippet_*` functions from [`clippy_utils::source`][].
195+
196+
If you're using the snippets _not_ to build a suggestion, it's usually
197+
enough to use [`snippet`][snippet_fn] -- it accepts the span of the item, and
198+
also a fallback string (see [Fallback string](emitting_lints.md#fallback-string)).
190199

191200
For example, if you want to know how an item looks (and you know the item's
192-
span), you could use `snippet(cx, span, "..")`.
201+
span), you could use `snippet(cx, span, "_")`.
202+
203+
If you do use the snippet for a suggestion, it's recommended to use
204+
[`snippet_with_applicability`] instead. This is so that Clippy can reduce the
205+
[applicability](emitting_lints.md#applicability) of the suggestion in case it couldn't extract
206+
the snippet "cleanly" -- see the function's documentation for more information.
207+
208+
It's often necessary to create multiple snippets to build a suggestion, in which
209+
case you'll have the following pattern:
210+
211+
```rust
212+
// inside `span_lint_and_then`
213+
214+
// 1. Create initial applicability.
215+
let mut app = Applicability::MachineApplicable;
216+
217+
// 2. Use it to create all the snippets
218+
let foo_snippet = snippet_with_applicability(cx, foo.span, "_", &mut app);
219+
let bar_snippet = snippet_with_applicability(cx, bar.span, "_", &mut app);
220+
let sugg = format!("{foo_snippet} + {bar_snippet}"); // or whatever
221+
222+
// 3. Use it to emit the final suggestion
223+
diag.span_suggestion(span, msg, sugg, app);
224+
```
225+
226+
### Fallback string
227+
This is the string that is used for the snippet when the source code that the
228+
span points to is unavailable. That mostly only happens when proc-macros
229+
mishandle spans -- see [the section on proc-macros][proc-macro-spans].
230+
231+
Most of the time, the snippets in a suggestion come from a (span of a) single
232+
expression, and so `"_"` is an appropriate fallback string. If you instead
233+
find yourself suggesting to insert multiple statements, or a block--basically
234+
anything "big"--then consider using `".."` instead.
193235

194236
## Final: Run UI Tests to Emit the Lint
195237

@@ -210,8 +252,11 @@ cover in the next chapters.
210252
[`span_lint_and_help`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_help.html
211253
[`span_lint_and_sugg`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_sugg.html
212254
[`span_lint_and_then`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_then.html
255+
[`clippy_utils::source`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/source/index.html
213256
[range_plus_one]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
214257
[inclusive_range]: https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html
215258
[applicability]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_errors/enum.Applicability.html
216259
[snippet_fn]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/source/fn.snippet.html
260+
[`snippet_with_applicability`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/source/fn.snippet_with_applicability.html
261+
[proc-macro-spans]: macro_expansions.html#the-is_from_proc_macro-function
217262
[format_macro]: https://doc.rust-lang.org/std/macro.format.html

book/src/lint_configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ be filtering for common types.
780780

781781

782782
## `max-fn-params-bools`
783-
The maximum number of bool parameters a function can have
783+
The maximum number of bool parameters a function can have.
784+
Use `0` to lint on any function with a bool parameter.
784785

785786
**Default Value:** `3`
786787

@@ -925,6 +926,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
925926
* [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one)
926927
* [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check)
927928
* [`manual_is_power_of_two`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_power_of_two)
929+
* [`manual_isolate_lowest_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_isolate_lowest_one)
928930
* [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else)
929931
* [`manual_midpoint`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_midpoint)
930932
* [`manual_non_exhaustive`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive)

clippy_config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.97"
3+
version = "0.1.98"
44
edition = "2024"
55
publish = false
66

clippy_config/src/conf.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ define_Conf! {
713713
/// be filtering for common types.
714714
#[lints(manual_let_else)]
715715
matches_for_let_else: MatchLintBehaviour = MatchLintBehaviour::WellKnownTypes,
716-
/// The maximum number of bool parameters a function can have
716+
/// The maximum number of bool parameters a function can have.
717+
/// Use `0` to lint on any function with a bool parameter.
717718
#[lints(fn_params_excessive_bools)]
718719
max_fn_params_bools: u64 = 3,
719720
/// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes
@@ -786,6 +787,7 @@ define_Conf! {
786787
manual_hash_one,
787788
manual_is_ascii_check,
788789
manual_is_power_of_two,
790+
manual_isolate_lowest_one,
789791
manual_let_else,
790792
manual_midpoint,
791793
manual_non_exhaustive,

clippy_config/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#![feature(rustc_private)]
22
#![warn(
3+
rust_2018_idioms,
34
trivial_casts,
45
trivial_numeric_casts,
5-
rust_2018_idioms,
66
unused_lifetimes,
77
unused_qualifications
88
)]
9-
#![allow(clippy::must_use_candidate, clippy::missing_panics_doc)]
9+
#![expect(clippy::must_use_candidate)]
1010

1111
extern crate rustc_data_structures;
1212
extern crate rustc_errors;

clippy_dev/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
rustc_private
88
)]
99
#![warn(
10+
rust_2018_idioms,
1011
trivial_casts,
1112
trivial_numeric_casts,
12-
rust_2018_idioms,
1313
unused_lifetimes,
1414
unused_qualifications
1515
)]
16-
#![allow(clippy::missing_panics_doc)]
16+
#![expect(clippy::missing_panics_doc)]
1717

1818
extern crate rustc_arena;
1919
extern crate rustc_data_structures;

clippy_dev/src/new_lint.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,29 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
157157
let path = "clippy_lints/src/lib.rs";
158158
let mut lib_rs = fs::read_to_string(path).context("reading")?;
159159

160-
let (comment, ctor_arg) = if lint.pass == Pass::Late {
161-
("// add late passes here", "_")
162-
} else {
163-
("// add early passes here", "")
164-
};
165-
let comment_start = lib_rs.find(comment).expect("Couldn't find comment");
166160
let module_name = lint.name;
167161
let camel_name = to_camel_case(lint.name);
168162

169-
let new_lint = if enable_msrv {
170-
format!("Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ")
163+
let (comment, new_lint) = if lint.pass == Pass::Late {
164+
// Late passes are folded into the statically-combined struct, so a new
165+
// entry is just `Field: Type = constructor` (see `combined_late_pass`).
166+
let new_lint = if enable_msrv {
167+
format!("{camel_name}: {module_name}::{camel_name} = {module_name}::{camel_name}::new(conf),\n ")
168+
} else {
169+
format!("{camel_name}: {module_name}::{camel_name} = {module_name}::{camel_name},\n ")
170+
};
171+
("// add late passes here", new_lint)
171172
} else {
172-
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ")
173+
// Early passes are folded into the statically-combined struct, so a new
174+
// entry is just `Field: Type = constructor` (see `combined_early_pass`).
175+
let new_lint = if enable_msrv {
176+
format!("{camel_name}: {module_name}::{camel_name} = {module_name}::{camel_name}::new(conf),\n ")
177+
} else {
178+
format!("{camel_name}: {module_name}::{camel_name} = {module_name}::{camel_name},\n ")
179+
};
180+
("// add early passes here", new_lint)
173181
};
182+
let comment_start = lib_rs.find(comment).expect("Couldn't find comment");
174183

175184
lib_rs.insert_str(comment_start, &new_lint);
176185

0 commit comments

Comments
 (0)