rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.06k stars 892 forks source link

Funny indentation when destructuring a struct with cfg toggled fields #5920

Open grahamc opened 1 year ago

grahamc commented 1 year ago

On rustfmt 1.6.0, I get surprising indentation when destructuring a struct where some fields are cfg-specific.

struct Demo {
    field_name_foo: (),
    field_name_bar: (),
    #[cfg(feature = "diagnostics")]
    field_name_baz: (),
    field_name_tux: (),
}

fn main() {
    let Demo {
        field_name_foo,
        #[cfg(feature = "diagnostics")]
            field_name_baz: _,
        field_name_bar,
        field_name_tux,
    } = Demo {
        field_name_foo: (),
        field_name_bar: (),
        #[cfg(feature = "diagnostics")]
        field_name_baz: (),
        field_name_tux: (),
    };
}
ytmimi commented 1 year ago

Thanks for reaching out. I also tested this with rustfmt 1.5.3-nightly (f4b80cac 2023-06-30) and reproduced the issue.