rust-lang / rust-lang/rustfmt

Fmt failure with wrap_comments = true

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

Nobody has claimed this yet.

A-call-chains A-comments I-max-width I-trailing-whitespace UO-wrap_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

When having wrap_comments = true, running rustfmt on the following code produces an error:

fn f() {
    g({
        // some trailing spaces on the line below - this needs to be inside the g call
    
        SomeStruct {
            a: b, // // This needs two sets of the slash-slash comments, and this needs to be a very long sentence so bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
        };
    })
    .x; // the .something needs to be here
}

The produces error is error[internal]: left behind trailing whitespace

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 reproducing the reported rustfmt failure with wrap_comments = true and the Rust example in the issue body. Trace the formatting path that handles trailing whitespace, wrapped comments, and the chained .x expression; done means the example formats without the internal trailing-whitespace error while preserving the comments and call structure.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.