Skip to content

feat: add simplify_match assist#22394

Open
Albab-Hasan wants to merge 2 commits into
rust-lang:masterfrom
Albab-Hasan:simplify-match-assist
Open

feat: add simplify_match assist#22394
Albab-Hasan wants to merge 2 commits into
rust-lang:masterfrom
Albab-Hasan:simplify-match-assist

Conversation

@Albab-Hasan
Copy link
Copy Markdown
Contributor

when the scrutinee of a match is a tuple struct enum variant call the outer constructor wrapper can be stripped:

  • arms matching the same constructor are simplified by removing the outer pattern wrapper (Some(n)n, Pair::Both(a, b)(a, b))
  • arms for other constructors of the same enum are removed as unreachable dead code
  • wildcard and binding arms are unchanged

the assist bails on guards, OR patterns, unit variant scrutinees and any arm pattern that doesnt resolve to the same enum.

single segment variant paths like None are syntactically parsed as IdentPat not PathPat. resolve_bind_pat_to_const is used to differentiate them from variable bindings.

closes #10443

  when the scrutinee of a match is a known tuple-struct enum variant
  call like Some(expr) arms matching that constructor are simplified
  by stripping the outer wrapper and arms for other constructors of
  the same enum are removed as unreachable dead code.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2026
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Note that we have a feature freeze on assists so this PR might get closed.

@Albab-Hasan
Copy link
Copy Markdown
Contributor Author

@ChayimFriedman2 my bad, forgot abt that

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: simplify match expression

3 participants