rust-lang / rust-lang/rust-analyzer

Fill in match arms helper damages the structure when nested matches are present

Open
#12,424 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

before adding missing arms

        match &msg {
            Event::OmsMsg(OmsMsg { severity, message }) => match severity {
                Severity::Info => info!(%message),
                Severity::Warning => warn!(%message),
                Severity::Error => error!(%message),
                Severity::Success | Severity::Silent => {}
            },
            Event::OmsOrderMsg(OmsOrderMsg {
                severity,
                message,
                order_id: oid,
                request_id: _,
            }) => match severity {
                Severity::Info => info!(?oid, %message),
                Severity::Warning => warn!(?oid, %message),
                Severity::Error => error!(?oid, %message),
                Severity::Success | Severity::Silent => {}
            },
            Event::ExchangeAck(ack) => trace!(?ack),
            Event::Exec(exec) => trace!(?exec),
            Event::TimerExpired(tid) => {
                trace!(tid = tid.get(), "Timer expired")
            }
        }

after adding missing arms

        match &msg {Event::OmsMsg(OmsMsg{severity,message})=>matchseverity{Severity::Info=>info!(%message),Severity::Warning=>warn!(%message),Severity::Error=>error!(%message),Severity::Success|Severity::Silent=>{}},Event::OmsOrderMsg(OmsOrderMsg{severity,message,order_id:oid,request_id:_,})=>matchseverity{Severity::Info=>info!(?oid, %message),Severity::Warning=>warn!(?oid, %message),Severity::Error=>error!(?oid, %message),Severity::Success|Severity::Silent=>{}},Event::ExchangeAck(ack)=>trace!(?ack),Event::Exec(exec)=>trace!(?exec),Event::TimerExpired(tid)=>{trace!(tid=tid.get(),"Timer expired")}

note matchseverity in two places. With spaces added everything works as expected.

I wasn't able to construct a simple standalone test case but saw this problem multiple times in different places.

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

The issue names the fill-in-match-arms helper but no file or test; start by reproducing the nested-match example and tracing how the resulting structure is assembled. Done means nested matches retain their spacing and structure, without tokens such as matchseverity, with a regression test covering the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.