Skip to content

Avoiding extra linebreaks when doc-comment added to enum #5662

@xldenis

Description

@xldenis

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions