-
Notifications
You must be signed in to change notification settings - Fork 891
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
Tuple struct field comments consume the field itself, only with doc comment #5215
Comments
Thank you for the report! There is a lot of great detail here! I appreciate how thorough the report is. I can confirm that I'm able to reproduce this on the current master |
Did some digging into this. The issue is that we're making the assumption that the type, prefix, and attributes can all fit on a single line if the type is written on a single line. As demonstrated by this issue, we should also consider whether or not a comment was found between the attribute and the prefix. If anyone's interested in taking this on this issue on they should look at rewrite_struct_field, but specifically these lines: Lines 1735 to 1739 in 368a9b7
|
@ytmimi I like to work on this |
@rustbot claim |
Describe the bug
When using the sequence
/// doc comment
,// regular comment
, <field definition> within a tuple struct definition, rustfmt joins the field with the regular comment above, removing the field from the struct definition.Input
Output - correctness issue
The same applies for
/* block comments */
, but in this case the issue is purely cosmetic (does not change the struct definition).Input (block comment)
Output (block comment) - cosmetic issue
At the very least, I expect there to be a separating space between the block comment and the
u32
, similar to the similar example with no doc commentWorking cases
However, this issue doesn't seem to appear when the
/// doc comment
is removed, nor in named-field structs:To Reproduce
Expected behavior
I expect rustfmt to never change the tuple struct definition (
MyStruct(u32)
-->MyStruct()
), and also preserve cosmetic newlines in the block comment case.Meta
Additional remarks
The text was updated successfully, but these errors were encountered: