rust-lang / rust-lang/rustfmt

Comment single-line to multi-line formatting is botched

Open
#3,695 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments C-bug I-poor-formatting only-with-option UO-wrap_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Given source like this:

fn foo(x: impl Iterator<Item = &'a PathBuf>) -> io::Result<impl Iterator<Item = &'a PathBuf>> {
    for foo in bar {
        for line in BufReader::new(File::open(banana)?)
            // A fairly long comment with https://google.github.io/flatbuffers/flatbuffers_grammar.html
            // an URL
            .lines()
        {
            let peach = match (loop {}) {
                Some(idx) => idx + open_quote, // get the absolute position from the original string
                None => loop {},
            };
        }
    }
}

rustfmt will produce the following diff:

             .lines()
         {
             let peach = match (loop {}) {
-                Some(idx) => idx + open_quote, // get the absolute position from the original string
+                Some(idx) => idx + open_quote, /* get the absolute position from the original
+                                                 * string */
                 None => loop {},
             };
         }

In this diff an incorrectly aligned 2nd line of the block comment can be seen.

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 Rust reproducer in the issue and compare the single-line comment's conversion with the shown diff. No source file or test is named; locate the comment-formatting entry point and add coverage that preserves correct alignment when the comment becomes multi-line.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.