Skip to content

Comment single-line to multi-line formatting is botched #3695

@nagisa

Description

@nagisa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-poor-formattingIssue: poor formattingUO-wrap_commentsUnstable option: wrap_commentsonly-with-optionRequires a non-default option value to reproduce

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions