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

Incorrect comment aligning with strange unicode characters #5504

Closed
A-Walrus opened this issue Aug 17, 2022 · 1 comment · Fixed by #5505
Closed

Incorrect comment aligning with strange unicode characters #5504

A-Walrus opened this issue Aug 17, 2022 · 1 comment · Fixed by #5505

Comments

@A-Walrus
Copy link
Contributor

A-Walrus commented Aug 17, 2022

With this code:

fn main() {}

pub struct WhitespaceCharacters {
    pub space: char,
    pub nbsp: char,
    pub tab: char,
    pub newline: char,
}

impl Default for WhitespaceCharacters {
    fn default() -> Self {
        Self {
            space: '·',    // U+00B7
            nbsp: '⍽',    // U+237D
            tab: '→',     // U+2192
            newline: '⏎', // U+23CE
        }
    }
}

rustfmt incorrectly aligns the comments, so that the one next to space is one character past the others.
Note that in utf8 the character next to space is 2 bytes, while the others they are 3 bytes.
Changing the chars to more basic ASCII chars resolves the issue:

impl Default for WhitespaceCharacters {
    fn default() -> Self {
        Self {
            space: 'h',   // U+00B7
            nbsp: 'i',    // U+237D
            tab: 'j',     // U+2192
            newline: 'k', // U+23CE
        }
    }
}
cargo fmt --version
rustfmt 1.5.1-stable (4b91a6e 2022-08-08)
@calebcartwright
Copy link
Member

technically this is a bug within buggy behavior (rustfmt isn't supposed to vertically align comments in these positions by default anyway), but the overarching point about unicode still holds true

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

Successfully merging a pull request may close this issue.

3 participants