-
Notifications
You must be signed in to change notification settings - Fork 925
rustfmt adds trailing whitespace on empty doc comment #5614
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
Comments
Thanks for reaching out. The only config needed to reproduce the issue is The issue is that rustfmt doesn't format doc comments
If you were to write your doc comment like: //! blah blah
//!
//! ```toml
//! blahblah = "0.1.0"
//! ```
//!
//! | Header1 | Header2 |
//! |----------|---------|
//! | A | B |
#![doc = "| C | D |"]
//! | E | F |
//!
//! blah blah
You won't run into this issue. |
@ytmimi Why does this matter? rustfmt removes trailing whitespace inside doc comments on empty lines, both for |
There's likely a bug in |
As stated above, you can avoid this issue altogether by not splitting the code fences with a doc attribute. |
This indeed seems to be the case that an empty line follows after an "opening" code fence. This reproduces the problem: //! ```
//!
//! blah blah
Whenever there's a non-empty line directly following the "opening" code fence, all other lines are formatted normally.
That's not possible in my case, as the whole point of the file is to be an input with mixed use of doc comments and attributes. While most people won't need this, sometimes this can be necessary if e.g. the doc attribute is not a string but a macro. |
Out of curiosity, why does the actual file need to contain a mix of both doc comments and doc attributes? Can you share the actual code snippet? |
The file is part of the test suite for
The code I shared in this issue is the entire file: https://github.com/msrd0/cargo-doc2readme/blob/main/tests/pass/mixing-comments-and-attrs/lib.rs |
This happened today in a project of mine: msrd0/cargo-doc2readme@7bb7690#diff-b3a721d27023ff07c5331d85424a395ed8907cc619825e7698ef8e3b5bf2a363
lib.rs
rustfmt.toml
The problem cannot be reproduced with the default rustfmt configuration.
The text was updated successfully, but these errors were encountered: