Avoiding extra linebreaks when doc-comment added to enum
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
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 whole enum is laid out with a line per field, even when no fields are documented.
That is, the type:
enum MyType {
A { field1: bool, field2: bool },
B { field1: bool, field2: bool },
/// OMG a comment
C { field1: bool, field2: bool },
D { field1: bool, field2: bool },
}
becomes
enum MyType {
A {
field1: bool,
field2: bool,
},
B {
field1: bool,
field2: bool,
},
/// OMG a comment
C {
field1: bool,
field2: bool,
},
D {
field1: bool,
field2: bool,
},
}
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating rustfmt’s enum-formatting logic and related formatting tests; the issue provides the enum example and desired output. Check whether the behavior belongs in a rustfmt.toml option or should be the default, then run the formatter tests. Done means coverage showing that a comment on one variant does not expand unrelated variants, while a documented field still expands its own variant.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100