-
-
Notifications
You must be signed in to change notification settings - Fork 16
chore: Let rustfmt format code in doc comments #1125
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
base: main
Are you sure you want to change the base?
Conversation
e4340c1 to
282a975
Compare
| /// .service_name("test") | ||
| /// .build() | ||
| /// .init()?; | ||
| /// tracing::info!("log a message"); | ||
| /// Ok(()) // < Scope ends here, guard is dropped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change we don't want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a lint that allows for aligned comments, we could enable it here?
But we also want the empty lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a lint that allows for aligned comments
I have no clue if such a thing exists... But others also asked for this: https://users.rust-lang.org/t/rustfmt-and-alignment-of-trailing-comments/39121
I think the best option would be to use #[rustfmt::skip] here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first try with #[rustfmt::skip] didn't work, now it did 🤷 7690e04
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will technically disable formatting for the actual code (struct) as well, but I guess there is no other way around it. Or can we disable doc code formatting just for these doc comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these changes are a little weird.
Enable
format_code_in_doc_commentsand letcargo +nightly-2025-10-23 fmt --allformat the code.The unstable feature isn't perfect (there are some weird spaces being added), but in my opinion this is a significant improvement.