rust-lang / rust-lang/rust-analyzer

Feature request: simplify match expression

Open
#10,443 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists A-pattern C-feature S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

When I'm refactoring and inlining stuff all over the place, I often end up with cases like this:

match Some(foo()) {
  None => { do_none() }
  Some(0) => { do_0() }
  Some(1) => { do_1() }
  _ => { do_wild() }
}

I would love an assist that keeps only the Some branches and simplifies this to

match foo() {
  0 => { do_0() }
  1 => { do_1() }
  _ => { do_wild() }
}

It would also make sense for if lets and even plain ifs.

I realize this is unlikely to be actionable until match checking is librarified, but that's not too far in the future hopefully.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust match, if let, and if examples in the issue, then assess the stated prerequisite that match checking be librarified. Done means an assist can simplify the shown Some match while preserving the 0, 1, and wildcard branches, with the intended scope for if let and plain if clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.