-
Notifications
You must be signed in to change notification settings - Fork 900
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
Poor formatting for function with attribute and doc comment #4398
Comments
I should mention that I can't easily reproduce this with other kinds of attributes, such as |
It may be that PR #4399 that fixed this issue is a patch that does not fix the root cause. The root cause seem to be because Documentation comment is regarded as an Attribute (AST attribute kind The resolution should probably be one of the following:
I am currently trying to resolve issue #4499, and a decision about the above is needed, as currently Documentation is handled as any other attributes, and PR #4399 change is causing a conflict. |
Myself, I think I find solution (2) most intuitive. If I put the |
An issue with (2) is that comments within the attributes block will also be formatted. Issue #4499 is about a comment between
Just to make sure, I assume that the first line after the #[rustfmt::skip]
pub fn foo1(&self) -> usize {
0 // fn body
} However, the following code: impl Struct {
#[rustfmt::skip]
pub fn foo2(&self) -> usize {
0 // fn body
}
} is formatted as: impl Struct {
#[rustfmt::skip]
pub fn foo2(&self) -> usize {
0 // fn body
}
} I assume that line |
I agree with you on all counts. So as a result, seems like (1) is the best solution? (Note that I'm not any kind of authority, not a contributor to rustfmt, etc.) |
rustfmt
un-indents the attribute in this small example. Interestingly, if either the doc comment or the inline comment are removed,rustfmt
lets the attribute stay indented, which I believe to be the intuitive behavior.Input
Output
Expected output
(no change)
Meta
The text was updated successfully, but these errors were encountered: