rust-lang / rust-lang/rustfmt

Trailing whitespace of match arm not stripped when the body expression is very long and follows in the second line

Open
#5,689 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments A-matches I-trailing-whitespace P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Minimal reproducer:

fn this_is_a_very_long_name_to_lengthen_the_expression_so_that_rustfmt_does_not_join_the_lines() {}

fn main() {
    match () {
        _ => /* (whitespace here) => */ 
            this_is_a_very_long_name_to_lengthen_the_expression_so_that_rustfmt_does_not_join_the_lines(),
    }
}

Output:

error[internal]: left behind trailing whitespace
 --> stdin:5:5:40
  |
5 |         _ => /* (whitespace here) => */ 
  |                                        ^
  |

warning: rustfmt has failed to format. See previous 1 errors.

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 the minimal Rust reproducer through rustfmt and confirm the trailing-whitespace diagnostic at stdin:5. Trace the match-arm formatting path responsible for the second-line body expression, then verify that formatting no longer leaves whitespace after the comment marker and that the reproducer completes without the internal error.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.