-
Notifications
You must be signed in to change notification settings - Fork 996
Description
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
struct MyTuple(
/// Doc Comments
// TODO note to add more to Doc Comments
u32,
);
Output - correctness issue
struct MyTuple(
/// Doc Comments
// TODO note to add more to Doc Commentsu32,
);
The same applies for /* block comments */, but in this case the issue is purely cosmetic (does not change the struct definition).
Input (block comment)
struct MyTuple(
/// Doc Comments
/* TODO note to add more to Doc Comments */
u32,
);
Output (block comment) - cosmetic issue
struct MyTuple(
/// Doc Comments
/* TODO note to add more to Doc Comments */u32,
);
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 comment
- /* TODO note to add more to Doc Comments */u32,
+ /* TODO note to add more to Doc Comments */ u32,Working cases
However, this issue doesn't seem to appear when the /// doc comment is removed, nor in named-field structs:
- No doc comment - works as expected
struct MyTuple( // TODO note to add more to Doc Comments u32, ); - Struct with named fields (non-tuple) - works as expected
struct MyStruct { /// Doc Comments // TODO note to add more to Doc Comments field: u32, }
To Reproduce
- Tuple struct with doc comment, single line comment (broken) - Playground
- Tuple struct with doc comment, block comment (broken, cosmetic only) - Playground
- Tuple struct with single line comment, only (not broken, just for comparison) - Playground
- Struct (named fields) with doc comment, single line comment (not broken, just for comparison) - Playground
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
- rustfmt version: rustfmt 1.4.38-nightly (2022-02-02 27f5d83)
- From where did you install rustfmt?: using playground only
- How do you run rustfmt: using playground only
Additional remarks
- I didn't find any existing issues matching this problem description, but corrupted output when using comments within generic type parameters of a trait #4643 may be similar.
- One of my first issues reported to rustfmt. Let me know if this is not actually a bug.