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

Trailing comments on multi byte lines of a wrapped Vec are indented strangely #4871

Closed
is8ac opened this issue Jun 15, 2021 · 1 comment
Closed

Comments

@is8ac
Copy link

is8ac commented Jun 15, 2021

fn main() {
    let _ = "foo"; // Comment
    let _ = "foo bar baz"; // Comment
    let _ = "quaks"; // Comment

    vec![
        "foo",         // Comment
        "foo bar baz", // Comment
        "quaks",       // Comment
    ];

    let _ = "foo"; // Comment
    let _ = "𝕋𝕙𝕖 𝕢𝕦𝕚𝕔𝕜 𝕓𝕣𝕠𝕨𝕟 𝕗𝕠𝕩"; // Comment
    let _ = "管道"; // Comment

    vec![
        "foo",                                                                 // Comment
        "𝕋𝕙𝕖 𝕢𝕦𝕚𝕔𝕜 𝕓𝕣𝕠𝕨𝕟 𝕗𝕠𝕩", // Comment
        "管道",                                                              // Comment
    ];
}
  • Single byte characters in multiple statements does not align.
  • Single byte characters in a Vec does allign.
  • Multi byte characters in multiple statements does not align, same as with single byte.
  • Multi byte characters a Vec aligns in a strange way.

I hypothesise that rustfmt is counting bytes not characters.

rustfmt --version:

rustfmt 1.4.37-nightly (539d7bd 2021-06-14)

Same behavior under

rustfmt 1.4.36-stable (7de6968 2021-02-07)

This bug was originally found by @LunarTulip

@calebcartwright
Copy link
Member

hi thanks for reaching out with the report! rustfmt isn't supposed to visually align anything by default but there's a known bug (#4108) where it not only attempts to do so, but often does so incorrectly. Accordingly I'm going to go ahead and close this and track in #4108 which you may want to subscribe to for updates. As part of addressing the issue we'll add test cases for the snippets you've provided here.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants