Commit Graph

25136 Commits

Author SHA1 Message Date
Ada Alakbarova 49a2f386f9 Unneeded wildcard improvement (#16733)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16733)*

changelog: [`unneeded_wildcard_pattern`]: add support for struct
constructs.

Closes [#16638](https://github.com/rust-lang/rust-clippy/issues/16638)

The existing lint only looks at tuples and tuplestructs. This change
adds support for standard structs, looking for cases
where one or more `_` immediately preceed a `..`. The preceeding `_`
members may be omitted, as they will be collected by the `..` operator.
2026-04-06 15:04:13 +00:00
jim df2f81b8e7 add struct support to unneeded_wildcard_pattern lint
Apply suggestions from code review

Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
2026-04-05 14:26:56 -04:00
Samuel Tardieu 389a32a4c3 perf: disable nonminimal_bool by default (#16761)
After performance concers on the `nonminimal_bool` lint, we [performed a
crater run](https://github.com/rust-lang/rust/issues/153883)

This crater run revealed that in 19120 suggestions taken from 1.3
million crates, only about 36% had resulted in multi-terminal
suggestions (suggestions that were not only a single boolean).

This suggests that most cases of this lint firing, the expression that
triggered was pretty simple. And thus, we should not take such a huge
toll for a lint that isn't that useful.

In the future, a rewrite of that `bool_expr` function could be very
useful to alleviate the performance toll. Because clearly running the
Quine McCluskey algorithm on all those boolean operations is not ideal.

---

## Performance report:

`cargo clippy` -> 5,077,447,157 icount
`cargo check` -> 3,629,576,891 icount

So the Clippy that `rustup` delivers is about 1.4b instructions more
than `cargo check`.

`NonminimalBool` lint pass -> 318,169,034

$$\frac{nonminimal\\_bool}{clippy-check}*100 = 21.97496844$$

So, the `NonminimalBool` lint pass is about 22% of all Clippy-exclusive
instruction count.

---

After this change, we can now compare the Clippy BUILT FROM MASTER, NOT
DELIVERED BY RUSTUP, with the Clippy from this PR.

`master/target/release/cargo-clippy` -> 5,296,838,955 (Slower than
Rustup)
`pr/target/release/cargo-clippy` -> 4,977,035,941.

So, $master - PR = 319803014$, which is the exact icount of
`Nonminimal_bool` and about 22% of Clippy's whole execution time.

Profiled on `syn-2.0.71`, with Callgrind.

changelog:[`nonminimal_bool`]: Move to `pedantic`.
changelog:[`overly_complex_bool_expr`]: Move to `pedantic`.
2026-04-05 11:54:26 +00:00
llogiq ab9cb427b8 Rework expr_use_ctxt into an iterator over successive use sites. (#16784)
This is going to be used as part of more thoroughly checking whether we
can change the type of an expression. e.g. `range_plus_one` suggests
changing `Range` to `RangeInclusive`.

changelog: none
2026-04-05 06:02:51 +00:00
llogiq 1e0b66ef7e fix: unnecessary type cast causing a compile error (#16796)
In some cases, removing a cast that looks unnecessary can
still change type inference, even when the cast is to the
expected same type.

The lint now handles casts that flow through
intermediate expressions (e.g. calls, blocks, let
bindings, loops...). It also treats placeholder
generics (e.g. `::<_>`) as inference sensitive.

Added regression tests with similar behavior
as the original bug, some edge cases and
tests to check if false negative cases
weren't created.

Closes rust-lang/rust-clippy#16449

changelog: [`unnecessary_cast`]: fixed a suggestion to remove a cast
that can cause a compilation error if followed.
2026-04-04 20:12:58 +00:00
llogiq 3cd5a6569a [unsafe_removed_from_name]: skip linting when renaming to '_' (#16802)
closes: rust-lang/rust-clippy#16768

I agree with the:
> importing it just to get the side effects of the trait being in scope
(anonymously, via as _) is not renaming it...

even without changing the name, we still not able to see it's original
name when calling a trait method, so I think this should be fine.

---

changelog: [`unsafe_removed_from_name`]: skip linting when renaming to
'_'
2026-04-04 19:32:30 +00:00
dswij ee4aff91c5 Multiple fixes to FNs of question_mark (#16769)
Closes rust-lang/rust-clippy#16751

changelog: [`question_mark`] fix FN for manual unwrap with `if let` or
`match`
changelog: [`question_mark`] fix FN when the match scrutinee is behind
reference
changelog: [`question_mark`] fix FN when match binding is behind `ref`
or `mut`
2026-04-04 15:56:33 +00:00
llogiq 80d86e3465 Update cargo_metadata to 0.23 (#16803)
Updates cargo_metadata to 0.23 and fixes all the resultant issues.

changelog: none
2026-04-04 13:23:04 +00:00
Jacob Adam 26799d9112 Update cargo_metadata to 0.23. 2026-04-03 20:11:43 +01:00
J-ZhengLi d5f106507b [unsafe_removed_from_name]: skip lint when renaming to '_' 2026-04-04 02:07:40 +08:00
llogiq 88f787d193 Rustup (#16791)
r? @ghost

changelog: none
2026-04-03 17:24:39 +00:00
Philipp Krones f4d6d6935c Remove internal lint DERIVE_DESERIALIZE_ALLOWING_UNKNOWN
rustc doesn't keep around proc macro helper attributes in the HIR. So it is no
longer possible to lint this. In a LateLintPass the necessary information isn't
around anymore, in an EarlyPassLint derive attributes are already expanded and
dropped and it is not possible to relate an impl with the type it is implemented
on. Doing that with `ast::Path`s is brittle.
2026-04-03 14:19:09 +02:00
Guilherme Silva b269a2b71f fix: unnecessary type cast causing a compile error
In some cases, removing a cast that looks unnecessary
can still change type inference, even when the cast is
to the expected same type.

The lint now handles casts that flow through
intermediate expressions (e.g. calls, blocks, let
bindings, loops...). It also treats placeholder
generics (e.g. `::<_>`) as inference sensitive.

Added regression tests with similar behavior
as the original bug, some edge cases and
tests to check if false negative cases
weren't created.

Closes #16449
2026-04-02 22:47:35 +01:00
Jason Newcomb 174df86e5f Few small fixes for clippy_dev/new_lint (#16795)
---

*Please write a short comment explaining your change (or "none" for
internal only changes)*

changelog: none
2026-04-02 20:53:11 +00:00
Pavel Grigorenko a390a52e74 clippy_dev/new_lint: sort imports in the snippet 2026-04-02 22:33:18 +03:00
Pavel Grigorenko 750e578195 clippy_dev/new_lint: fix path to the file where MSRVs reside 2026-04-02 22:30:26 +03:00
Philipp Krones 994d5b4ac8 Bump nightly version -> 2026-04-02 2026-04-02 13:49:57 +02:00
Philipp Krones 1d55118849 Merge remote-tracking branch 'upstream/master' into rustup 2026-04-02 13:31:08 +02:00
Jason Newcomb 8322ae2cfb Rework expr_use_ctxt into an iterator over successive use sites. 2026-03-30 11:54:43 -04:00
Jonathan Brouwer 4efda7afee Rollup merge of #154074 - dianne:dbg-temp-scopes, r=Mark-Simulacrum
don't drop arguments' temporaries in `dbg!`

Fixes rust-lang/rust#153850

Credit to @theemathas for help with macro engineering ^^

r? libs
2026-03-29 21:39:26 +02:00
dianne e689235a7e update diagnostic for variables moved by dbg! 2026-03-29 09:48:41 -07:00
dianne 7d9ab57a4f don't drop arguments' temporaries in dbg! 2026-03-29 06:38:38 -07:00
llogiq c07baa4cc9 Add manual_option_zip lint (a.and_then(|x| b.map(|y| (x, y)))) (#16600)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16600)*

changelog: [`manual_option_zip`]: new lint that detects `a.and_then(|a|
b.map(|b| (a, b)))` and suggests using `a.zip(b)` instead

This PR introduces a new lint `manual_option_zip` that identifies cases
where `Option::and_then` is followed by `Option::map` in the provided
closure to construct a tuple that could be more concisely shaped using
`Option::zip`.

The lint detects the pattern:
```rust
a.and_then(|x| b.map(|y| (x, y)))
```

And suggests replacing it with:
```rust
a.zip(b)
```

Closes rust-lang/rust-clippy#16599
2026-03-28 21:58:47 +00:00
Samuel Tardieu e4683d27a9 impl manual_noop_waker lint (#16687)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16687)*

Fixes rust-lang/rust-clippy#16639

### Description

This PR introduces a new lint manual\_noop\_waker that detects manual,
empty implementations of the std::task::Wake trait. These can be
replaced with std::task::Waker::noop(), which is more performant (avoids
Arc allocation) and cleaner.

### Example

```rust
struct MyWaker;
impl Wake for MyWaker {
    fn wake(self: Arc<Self>) {}
    fn wake_by_ref(self: &Arc<Self>) {}
}
````
Can be replaced with:

```rust
let waker = Waker::noop();

````

* \[x\] I've followed the [contribution
guidelines](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md)

*   \[x\] I've added UI tests for the new lint

*   \[x\] I've run `cargo dev update_lints`

changelog: `[manual_noop_waker]`: Added a lint to detect manual no-op
Wake implementations.
2026-03-28 17:49:00 +00:00
Jaroslaw Roszyk 26740ea4ab impl manual_noop_waker lint 2026-03-28 15:17:02 +01:00
Jason Newcomb fee9100776 Issue #16110: similar_names not triggered by example (#16300)
*Please write a short comment explaining your change (or "none" for
internal only changes)*
Fixes rust-lang/rust-clippy#16110
changelog: [`similar_names`] : Changed the lint docs to reflect its
actual behavior
2026-03-28 00:33:40 +00:00
alt440 453a482373 Ran cargo dev fmt 2026-03-27 20:13:15 -04:00
alt440 ee7896e041 similar_names not triggered by example 2026-03-27 20:13:13 -04:00
alt440 837e8917a6 Revert "similar_names not triggered by example"
This reverts commit e82f527e21415da49f30473d4562adb967f867e4.
2026-03-27 20:10:48 -04:00
alt440 111b8dc87e Revert "Correct dogfood tests"
This reverts commit 74578256f1f009de382589b87fa356906c18a61b.
2026-03-27 20:10:46 -04:00
alt440 c5b3fcf243 Revert "Executed cargo fmt"
This reverts commit 9b9de0f218d504a5682649ea3745ea8887698656.
2026-03-27 20:09:44 -04:00
alt440 df8f576cdf Executed cargo fmt 2026-03-27 20:09:44 -04:00
alt440 44435734ff Correct dogfood tests 2026-03-27 20:09:42 -04:00
alt440 ea5bc07c19 similar_names not triggered by example 2026-03-27 20:07:42 -04:00
Jason Newcomb 75813d35fd Preserve parentheses in suggestion in presence of cascaded casts (#16483)
changelog: [`unnecessary_cast`]: preserve parentheses in presence of
cascaded casts

Fixes rust-lang/rust-clippy#16475
2026-03-27 23:19:50 +00:00
Jason Newcomb e43491b0df chore(deps): update rust crate tar to v0.4.45 (#16771)
Fix
[RUSTSEC-2026-0068](https://rustsec.org/advisories/RUSTSEC-2026-0068.html):
tar-rs incorrectly ignores PAX size headers if header size is nonzero
Fix
[RUSTSEC-2026-0067](https://rustsec.org/advisories/RUSTSEC-2026-0067.html):
`unpack_in` can chmod arbitrary directories by following symlinks

cc: @clubby789

changelog: none
2026-03-27 17:57:00 +00:00
xtqqczze a7a0fc3cc7 chore(deps): update rust crate tar to v0.4.45 2026-03-27 13:32:41 +00:00
Daria Sukhonina 6e68667da9 Use tcx.local_parent() more often 2026-03-27 15:36:29 +03:00
Daria Sukhonina b0c02926e5 Add typeck_root_def_id_local 2026-03-27 15:36:28 +03:00
Jason Newcomb 0a29aac07d fix(explicit_counter_loop): suggest .take(n) for for _ in 0..n co… (#16658)
When a loop variable is unused (`for _ in 0..n`) and the counter is
being
incremented, Clippy previously suggested the generic zip-based rewrite.
This PR adds a more idiomatic `.take(n)` suggestion for the common case
where the range is half-open and starts at zero:
```rust
// before
for _ in 0..MAX {
    base += 1;
}

// suggested
for base in (100..).take(MAX)
```

Non-zero starts (`5..MAX`) and inclusive ranges (`0..=MAX`) are
explicitly excluded and fall through to the existing zip suggestion.
Both cases are covered by new UI tests.

changelog: [`explicit_counter_loop`]: suggest `(init..).take(n)` when
loop variable is unused and range is `0..n`

fixes rust-lang/rust-clippy#16642
2026-03-27 11:14:04 +00:00
linshuy2 be6cf3c9af Apply question_mark to Clippy itself 2026-03-26 21:34:11 +00:00
linshuy2 cfd67fc313 fix: question_mark FN for manual unwrap with if let 2026-03-26 21:33:45 +00:00
linshuy2 72e7f28a3c fix: question_mark FN when match binding is behind ref or mut 2026-03-26 17:24:52 +00:00
linshuy2 fca46564b0 fix: question_mark FN when the match scrutinee is behind reference 2026-03-26 17:07:06 +00:00
linshuy2 7c6ac13706 fix: question_mark FN for manual unwrap with match 2026-03-26 17:04:05 +00:00
zayutaha daad0fb356 fix(explicit_counter_loop): suggest .take(n) for for _ in 0..n counter loops
fix(explicit_counter_loop): suggest `.take(n)` for `for _ in 0..n` counter loops
2026-03-26 18:41:03 +05:30
Alejandra Gonzalez 1437b428ba perf: disable nonminimal_bool by default
After performance concers on the `nonminimal_bool` lint, we performed a
crater run (rust-lang/rust issue number 153883).

This crater run revealed that in 19120 suggestions taken from 1.3
million crates, only about 36% had resulted in multi-terminal
suggestions (suggestions that were not only a single boolean).

This suggests that most cases of this lint firing, the expression that
triggered was pretty simple. And thus, we should not take such a huge
toll for a lint that isn't that useful.

changelog:[`nonminimal_bool`]: Move to `pedantic`.
changelog:[`overly_complex_bool_expr`]: Move to `pedantic`.
2026-03-26 00:32:49 +01:00
Jonathan Brouwer ddfb974bf9 Rollup merge of #153702 - SpriteOvO:guard-matcher, r=davidtwco
Add macro matcher for `guard` fragment specifier

Tracking issue #153104

This PR implements a new `guard` macro matcher to match `if-let` guards (specifically [`MatchArmGuard`](https://github.com/rust-lang/reference/blob/50a1075e879be75aeec436252c84eef0fad489f4/src/expressions/match-expr.md#match-guards)). In the upcoming PR, we can use this new matcher in the `matches!` and `assert_matches!` macros to support their use with `if-let` guards. (see #152313)

The original `Expr` used to represent a guard has been wrapped in a new `Guard` type, allowing us to carry the span information of the leading `if` keyword. However, it might be even better to include the `if` keyword in the `Guard` type as well? I've left a FIXME comment in the code.
2026-03-25 19:52:50 +01:00
dswij f7649efff7 iter_kv_map: handle identity map for map and flat_map (#16743)
fixes: rust-lang/rust-clippy#16742

properly select post operation for identity map according to map method
kind

changelog: [`iter_kv_map`]: handle identity map for `map` and `flat_map`
2026-03-24 22:06:09 +00:00
Ada Alakbarova 42139286fa manual_pop_if: lint more cases, even if we do not provide a suggestion (#16683)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16683)*

Extend the lint to detect the case where the popped value is used, but
in such cases just emit the lint with no suggestion.

changelog: [`manual_pop_if`]: in case the popped value is used, just
emit the lint with no suggestion.
changelog: [`manual_pop_if`]: also cover `.pop().unwrap_unchecked()`
2026-03-24 20:39:04 +00:00