rust-lang / rust-lang/rustfmt

Inconsistent handling of `return` on match arm

Open
#3,192 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

I-poor-formatting P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

E.g.

fn foo(input: Option<usize>) -> usize {
    match input {
        Some(x) => return x,
        None => {
            return 0;
        }
    }
}

Technically these two returns are different on AST level (the first one is an expression whereas the second is a statement). We could normalize them from either one to the other.

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

Use the two match-arm examples in the issue as the starting case, then inspect rustfmt's handling of match arms and its existing formatting tests. Resolve whether both forms should normalize to expression or statement style, and consider the issue done when equivalent return forms are formatted consistently with regression coverage.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.