Skip to content

[beta] Clippy backport#156793

Merged
rust-bors[bot] merged 2 commits into
rust-lang:betafrom
flip1995:clippy-beta-backport
May 21, 2026
Merged

[beta] Clippy backport#156793
rust-bors[bot] merged 2 commits into
rust-lang:betafrom
flip1995:clippy-beta-backport

Conversation

@flip1995
Copy link
Copy Markdown
Member

Backporting two fixes in Clippy

The 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

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 -->
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 21, 2026

The Clippy subtree was changed

cc @rust-lang/clippy

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. labels May 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 21, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@Mark-Simulacrum
Copy link
Copy Markdown
Member

@bors r+ rollup=never

cc @cuviper

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 21, 2026

📌 Commit 3c8f708 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 21, 2026
@Mark-Simulacrum
Copy link
Copy Markdown
Member

@bors p=5

@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 21, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 21, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 21, 2026

☀️ Test successful - CI
Approved by: Mark-Simulacrum
Duration: 3h 12m 13s
Pushing a815754 to beta...

@rust-bors rust-bors Bot merged commit a815754 into rust-lang:beta May 21, 2026
12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. T-clippy Relevant to the Clippy team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants