[beta] Clippy backport#156793
Merged
Merged
Conversation
Fixes rust-lang/rust-clippy#16849 changelog: [`manual_noop_waker`]: Add MSRV check
…t changes runtime behavior. (rust-lang#16878) Closes rust-lang/rust-clippy#16875 ### What was wrong The lint suggested collapsing `pattern => { if test { body } }` into `pattern if test => { body }`. These are not equivalent. In the original, once `pattern` matches, the match exits regardless of `test`. In the suggestion, a failing guard allows fall-through to subsequent arms, which can match values that previously never reached them. ```rust // Before (original) match a { Some(_) => { if b == 0 { res = 1 } } _ if b == 1 => res = 2, // unreachable when a is Some(_) _ => {} } // After (suggestion — WRONG, changes behavior) match a { Some(_) if b == 0 => res = 1, _ if b == 1 => res = 2, // now reachable when a is Some(_) and b != 0 _ => {} } ``` ### Fix The `if`-guard collapsing is only safe when there are no non-wildcard arms between the current arm and the wildcard arm. The fix adds a check that all arms after the current one are "wild-like" (a bare `_`, a binding, or `None`, all without guards) before suggesting the transformation. As a side effect, three `#[expect(clippy::collapsible_match)]` suppressions in `clippy_lints/src/methods/mod.rs` are removed. They had been added to suppress this exact false positive and are no longer needed. ### Still lints correctly When only wildcard arms follow, the transformation is safe and the lint still fires: ```rust // This still lints — only `_ => {}` follows, fall-through is harmless match a { Some(_) => { if b == 0 { res = 1 } // triggers collapsible_match } _ => {} } ``` changelog: [`collapsible_match`]: no longer suggests collapsing `pattern => { if test { body } }` into a match guard when non-wildcard arms follow, as this changes the semantics of the match. <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> ### Summary Notes - [Beta-nomination](rust-lang/rust-clippy#16878 (review)) by [samueltardieu](https://github.com/samueltardieu) *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/note.html) for details* <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
Collaborator
|
The Clippy subtree was changed cc @rust-lang/clippy |
Collaborator
This was referenced May 21, 2026
Member
Contributor
Member
|
@bors p=5 |
This comment has been minimized.
This comment has been minimized.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backporting two fixes in Clippy
manual_noop_wakerrust-clippy#16850collapsible_matchsuggested a transformation that changes runtime behavior. rust-clippy#16878The first one fixes a lint that was added in 1.96.0 (current beta), so that this bug doesn't go to stable. The second one fixes a suggestion that can cause bugs in the code of our users.
Both commits are already on the r-l/r main branch.
r? Mark-Simulacrum