rust-lang / rust-lang/rust-analyzer

Reorder match arms

Open
#8,475 6 comments 7 reactions 1 assignee View on GitHub

@so1ve is already working on this.

Since Aug 4, 2026.

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

Description

It would be nice if there was an assist to reorder match arms based on the order of variants within the enum definition. I.e. change this:

enum Foo {
    A,
    B,
    C,
}

fn bar(foo: Foo) -> i32 {
    match foo {
        Foo::C => 3,
        Foo::B => 2,
        Foo::A => 1,
    }
}

to this:

enum Foo {
    A,
    B,
    C,
}

fn bar(foo: Foo) -> i32 {
    match foo {
        Foo::A => 1,
        Foo::B => 2,
        Foo::C => 3,
    }
}

Alternatively / in addition to this, the "fill match arms" assist could insert new arms into the correct position, rather than always placing them at the end.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.