rust-lang / rust-lang/rustfmt

Formatting error: closing curly-brace placed to the last comment (using `visual` imports indent)

Open
#6,379 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments A-imports C-bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Valid code example (just from some crate documentation):

use binrw::{
    binrw,    // #[binrw] attribute
    BinRead,  // trait for reading
    BinWrite, // trait for writing
};

My rustfmt.toml:

imports_indent = "Visual"

Version of rustfmt: rustfmt 1.8.0-nightly (4392847410 2024-10-21)


Expected result of formatting example code above: (something like this, not sure)

use binrw::{binrw,    // #[binrw] attribute
            BinRead,  // trait for reading
            BinWrite, // trait for writing
           };

Actual result that breaks the code - closing curly-brace placed to the last comment:

use binrw::{binrw,    // #[binrw] attribute
            BinRead,  // trait for reading
            BinWrite  // trait for writing};

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 formatting of the documented Rust import with rustfmt 1.8.0-nightly and imports_indent = "Visual" in rustfmt.toml. Trace how line comments and the closing brace are handled, then ensure formatting keeps the brace outside the final comment and add coverage for this example.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.