Skip to content

Struct field patterns with cfgs are formatted unlike anything else #5982

Open
@kpreid

Description

@kpreid

Using rustfmt 1.6.0-stable (2023-12-04 a28077b), the following formatting is produced:

struct Foo {
    #[cfg(all())]
    something_long_enough_to_wrap_foo: i32,
    #[cfg(all())]
    something_long_enough_to_wrap_bar: i32,
}

fn example() {
    let Foo {
        #[cfg(all())]
        something_long_enough_to_wrap_foo,
        #[cfg(all())]
            something_long_enough_to_wrap_bar: bar_var,
    } = Foo {
        #[cfg(all())]
        something_long_enough_to_wrap_foo: 111,
        #[cfg(all())]
        something_long_enough_to_wrap_bar: 222,
    };
}

Note that in the Foo pattern, the line something_long_enough_to_wrap_bar: bar_var is indented one more level, but in all other cases, there is no additional indentation level. This seems unusual and inconsistent, and so I suggest that it be changed to be consistent in the next "style edition".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions