Skip to content

Commit 6368fd5

Browse files
committed
Auto merge of #157072 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? Manishearth `Cargo.lock` update due to Clippy version bump.
2 parents b5d1746 + 9b01485 commit 6368fd5

159 files changed

Lines changed: 2393 additions & 849 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.

Cargo.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
660660

661661
[[package]]
662662
name = "clippy"
663-
version = "0.1.97"
663+
version = "0.1.98"
664664
dependencies = [
665665
"anstream",
666666
"askama",
@@ -687,7 +687,7 @@ dependencies = [
687687

688688
[[package]]
689689
name = "clippy_config"
690-
version = "0.1.97"
690+
version = "0.1.98"
691691
dependencies = [
692692
"clippy_utils",
693693
"itertools",
@@ -711,7 +711,7 @@ dependencies = [
711711

712712
[[package]]
713713
name = "clippy_lints"
714-
version = "0.1.97"
714+
version = "0.1.98"
715715
dependencies = [
716716
"arrayvec",
717717
"cargo_metadata 0.23.1",
@@ -743,7 +743,7 @@ dependencies = [
743743

744744
[[package]]
745745
name = "clippy_utils"
746-
version = "0.1.97"
746+
version = "0.1.98"
747747
dependencies = [
748748
"arrayvec",
749749
"itertools",
@@ -1148,7 +1148,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
11481148

11491149
[[package]]
11501150
name = "declare_clippy_lint"
1151-
version = "0.1.97"
1151+
version = "0.1.98"
11521152

11531153
[[package]]
11541154
name = "derive-where"

src/tools/clippy/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6947,6 +6947,7 @@ Released 2018-09-13
69476947
[`map_err_ignore`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_err_ignore
69486948
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
69496949
[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
6950+
[`map_or_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity
69506951
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
69516952
[`map_with_unused_argument_over_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_with_unused_argument_over_ranges
69526953
[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref
@@ -7375,6 +7376,7 @@ Released 2018-09-13
73757376
[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice
73767377
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice
73777378
[`unused_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
7379+
[`unused_async_trait_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async_trait_impl
73787380
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
73797381
[`unused_enumerate_index`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_enumerate_index
73807382
[`unused_format_specs`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_format_specs

src/tools/clippy/CONTRIBUTING.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,9 @@ an AST expression).
9393
## Getting code-completion for rustc internals to work
9494

9595
### RustRover
96-
Unfortunately, [`RustRover`][RustRover_homepage] does not (yet?) understand how Clippy uses compiler-internals
97-
using `extern crate` and it also needs to be able to read the source files of the rustc-compiler which are not
98-
available via a `rustup` component at the time of writing.
99-
To work around this, you need to have a copy of the [rustc-repo][rustc_repo] available which can be obtained via
100-
`git clone https://github.com/rust-lang/rust/`.
101-
Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies
102-
which `RustRover` will be able to understand.
103-
Run `cargo dev setup intellij --repo-path <repo-path>` where `<repo-path>` is a path to the rustc repo
104-
you just cloned.
105-
The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to
106-
Clippy's `Cargo.toml`s and should allow `RustRover` to understand most of the types that Clippy uses.
107-
Just make sure to remove the dependencies again before finally making a pull request!
108-
109-
[rustc_repo]: https://github.com/rust-lang/rust/
96+
Since [`RustRover`][RustRover_homepage] 2026.1, no additional setup is required.
97+
Just open the project in RustRover as usual.
98+
11099
[RustRover_homepage]: https://www.jetbrains.com/rust/
111100

112101
### Rust Analyzer

src/tools/clippy/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"
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"

src/tools/clippy/book/src/configuration.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ fn main() {
123123
You can also omit the patch version when specifying the MSRV, so `msrv = 1.30`
124124
is equivalent to `msrv = 1.30.0`.
125125

126-
Note: `custom_inner_attributes` is an unstable feature, so it has to be enabled explicitly.
126+
> **Note:** Some lints change their behavior depending on the configured MSRV.
127+
> In some cases, Clippy may suppress a lint entirely to avoid suggesting APIs or
128+
> syntax unavailable for the configured MSRV.
129+
> In other cases, Clippy may emit the lint but choose an older compatible suggestion.
130+
131+
> **Note:** `custom_inner_attributes` is an unstable feature, so it has to be
132+
> enabled explicitly.
127133
128134
Lints that recognize this configuration option can be
129135
found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv)

src/tools/clippy/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

src/tools/clippy/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

src/tools/clippy/clippy_lints/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_lints"
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"

src/tools/clippy/clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1515
return;
1616
}
1717
if let Some(lint_list) = &attr.meta_item_list()
18-
&& attr.name().is_some_and(|name| is_lint_level(name))
18+
&& attr.name().is_some_and(is_lint_level)
1919
{
2020
for lint in lint_list {
2121
match item.kind {

src/tools/clippy/clippy_lints/src/booleans.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,12 @@ impl<'tcx> NonminimalBoolVisitor<'_, 'tcx> {
612612
}
613613
}
614614
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
615-
if !self.cx.tcx.lint_level_spec_at_node(NONMINIMAL_BOOL, e.hir_id).is_allow() {
615+
if !self
616+
.cx
617+
.tcx
618+
.lint_level_spec_at_node(NONMINIMAL_BOOL, e.hir_id)
619+
.is_allow()
620+
{
616621
suggestions.sort();
617622
span_lint_hir_and_then(
618623
self.cx,

0 commit comments

Comments
 (0)