Skip to content

Fix collapsible_match suggestion causing non-exhaustive pattern error#16865

Open
JasmineLCY wants to merge 2 commits intorust-lang:masterfrom
JasmineLCY:fix/collapsible-match-wildcard
Open

Fix collapsible_match suggestion causing non-exhaustive pattern error#16865
JasmineLCY wants to merge 2 commits intorust-lang:masterfrom
JasmineLCY:fix/collapsible-match-wildcard

Conversation

@JasmineLCY
Copy link
Copy Markdown

When collapsing a bare if inside a match arm into a match guard, the else arm's pattern must be a true wildcard for exhaustiveness. If the else arm is None (which arm_is_wild_like considers wild-like but isn't a true wildcard for exhaustiveness), the suggestion now replaces it with _.

Drafted with AI assistance, reviewed and tested by me.

Fixes #16860

changelog: Fix [collapsible_match] suggestion causing non-exhaustive patterns error when else arm is not a wildcard

When collapsing a bare `if` inside a match arm into a match guard, the
else arm's pattern must be a true wildcard for exhaustiveness. If the
else arm is `None` (which `arm_is_wild_like` considers wild-like but
isn't a true wildcard for exhaustiveness), the suggestion now replaces
it with `_`.

Fixes rust-lang#16860

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 16, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 2026

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

Lintcheck changes for de932e4

Lint Added Removed Changed
clippy::collapsible_match 0 0 3

This comment will be updated if you push new changes

@samueltardieu
Copy link
Copy Markdown
Member

Please:

  • claim the issue
  • don't reference issue number in commit message
  • look at the lintcheck changes, one looks clearly incorrect (wildcard matching everything while other clauses follow), and include a test to ensure this is now fixed
  • ensure CI is green

@dswij dswij added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Apr 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 20, 2026

☔ The latest upstream changes (possibly #16878) made this pull request unmergeable. Please resolve the merge conflicts.

@JasmineLCY
Copy link
Copy Markdown
Author

Sorry for the slow response — I missed this.

I'll address each point:

  1. Claiming the issue now
  2. Will remove the issue number from the commit message
  3. Will look into the lintcheck wildcard change and add a test
  4. Will ensure CI is green

Working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

collapsible_match suggestion causes error

4 participants