Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nagisa opened this issue Jul 18, 2019 · 1 comment
Open

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

nagisa opened this issue Jul 18, 2019 · 1 comment
Labels
a-comments only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@nagisa
Copy link
Member

nagisa commented Jul 18, 2019

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.

@nagisa nagisa changed the title Comment formatting is botched Comment single-line to multi-line formatting is botched Jul 18, 2019
@topecongiro topecongiro added a-comments only-with-option requires a non-default option value to reproduce poor-formatting labels Jul 19, 2019
@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

Confirming I can reproduce this using rustfmt 1.5.1-nightly (f2c31ba0 2022-07-19) and wrap_comments=true

Linking tracking issue for wrap_comments #3347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments only-with-option requires a non-default option value to reproduce poor-formatting
Projects
None yet
Development

No branches or pull requests

3 participants