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

rustfmt misformat when comment blocks are used #6426

Open
knoxfighter opened this issue Dec 24, 2024 · 1 comment
Open

rustfmt misformat when comment blocks are used #6426

knoxfighter opened this issue Dec 24, 2024 · 1 comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@knoxfighter
Copy link

misformat if two consecutive lines start with /* and the first line only contains comments and no actual code.

rustfmt doesn't correctly parse the end (*/) of /* code blocks. I use a code block to better see the offsets of each field of a type. Unfortunately this causes the second line /* to be changed to just * as if it is a continued comment line.
It only happens if the line starts with /* and has only comments in this line.

.rustfmt.toml:

wrap_comments = true

Input:

pub struct Type {
    /* 0x34 */ // _buf2: Buf<0x4>, // padding
    /* 0x4C */ pub field: u32,
}

Output:

pub struct Type {
    /* 0x34 */ // _buf2: Buf<0x4>, // padding
     * 0x4C */ pub field: u32,
}
@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. a-comments only-with-option requires a non-default option value to reproduce labels Dec 24, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Dec 24, 2024

This seems related to #4421, which was originally triggered by format_code_in_doc_comments=true. I checked and #4421 also seems to be triggered by wrap_comments=true, though the original issue has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants