rust-lang / rust-lang/rustfmt

A long string in a match arm breaks formatting for the whole match expression

Open
#4,797 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

1x-backport:pending A-matches C-bug E-help-wanted I-max-width P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Describe the bug

If an arm of a match expression contains a string with >= 87 characters, formatting fails on the whole match

To Reproduce

match 0 {
    0 => {"hello"} 1 => { ""}
      _ => {"veeeeeeeeeeery loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string"}
};

Expected behavior

 match 0 {
    0 => "hello",
    1 => "",
    _ => {
        "veeeeeeeeeeery loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string"
    }
};

If the third string is less than 86 characters, formatting works as expected.

Meta

  • rustfmt version: rustfmt 1.4.36-stable (7de6968 2021-02-07)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: rustfmt, cargo-fmt, and rust-analyzer formatting in VSCode.

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 by running rustfmt on the match-expression reproduction in the issue and inspect the match-arm formatting path that handles long strings. Done means the provided example formats successfully, including the long-string arm, without breaking formatting for the whole match expression; add a regression test if the existing test layout identifies a suitable location.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.