-
Notifications
You must be signed in to change notification settings - Fork 892
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
Avoiding extra linebreaks when doc-comment added to enum #5662
Comments
Thanks for reaching out. Confirming that I'm able to reproduce the behavior with the latest master I also want to point out that this isn't unique to doc comments. It could be any attribute. For example, this input: enum MyType {
A { field1: bool, field2: bool },
#[something]
B { field1: bool, field2: bool },
} will be reformatted as: enum MyType {
A {
field1: bool,
field2: bool,
},
#[something]
B {
field1: bool,
field2: bool,
},
} If you want to take a look at implementing this you'll want to check out Lines 518 to 523 in ee2bed9
In your example the It might make sense to try and make the multi-lined check smarter by ignoring the first lines that start with |
It's not as simple as "doc comments make the enum multiline", see #6120. I have no idea at all what the underlying pattern is here. |
Made this first fix attempt with the hint at [1] [1] rust-lang#5662 (comment)
Made this first fix attempt with the hint at [1] [1] rust-lang#5662 (comment)
This fix was made thanks to the hint at [1]. This was reported in issue rust-lang#5662 [2]. Previously, a enum item containing an attribute (rustdoc or macro) would be considered multi-line, thus forcing the formatting strategy of all the items in the enum to be Vertical (i.e. multi-line formatting). When determining the formatting strategy for enum items, we should ignore the attributes. This is what we do in the `is_multi_line_variant` function. Or else, simply adding a rustdoc comment or a macro attribute would cause the formatting of the whole enum to change, which is not a desirable behavior. We will be adding tests in the following commits. - [1] rust-lang#5662 (comment) - [2] rust-lang#5662
I've noticed what I consider to be an unfortunate decision in rustfmt: the moment a single doc-comment is added in an
enum
, the wholeenum
is laid out with a line per field, even when no fields are documented.That is, the type:
becomes
The formatting policy I would like would leave the type unchanged. If a doc-comment is added to a single field of a variant, then only that variant should be broken up on multiple lines rather than the whole type.
is this something that could potentially be customizable as an option in
rustfmt.toml
? If so, I would be happy to implement this if someone can point be in the right direction.The text was updated successfully, but these errors were encountered: