rust-lang / rust-lang/rustfmt

Extra whitespace inserted between literal and line comment.

Open
#5,826 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When inserting line comments in an array literal, rustfmt sometimes insert unnecessary empty space.

Simplest example:

let example_correct = [
    0, 0, // comment 1
    0, // comment 2
];

let example_incorrect = [
    0, 0x0, // comment 1
    0,   // comment 2
];

Notice how there are three spaces between the trailing comma and the comment 2 in the incorrect example.

Examples can be reproduced on the Rust Playground, which uses rustfmt 1.6.0-nighty (2023-07-10 8ca44ef), as well as with rust-analyzer v0.3.1583 VS Code extension.

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

Reproduce the issue with the array-literal examples in the report using rustfmt or the Rust Playground. Compare formatting around the trailing comma and line comment, then trace the formatter behavior responsible for comment spacing. Done means the incorrect example no longer gains extra whitespace while the existing formatting remains unchanged.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.