rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

`struct_field_align_threshold` doesn't apply when using `..Default::default()`

Open theon opened this issue 2 years ago • 2 comments

I have been using the struct_field_align_threshold option to align struct fields and it is great, however one issue I have noticed whilst using it is that the formatting isn't applied when using ..Default::default(). For example, formatting the follow struct has no impact:

StandardMaterial {
    base_color_texture: Some(asset_server.load("textures/card_back.png")),
    cull_mode: Some(Face::Front),
    fog_enabled: false,
    unlit: true,
    alpha_mode: AlphaMode::Blend,
    ..Default::default()
}

I would expect:

StandardMaterial {
    base_color_texture: Some(asset_server.load("textures/card_back.png")),
    cull_mode:          Some(Face::Front),
    fog_enabled:        false,
    unlit:              true,
    alpha_mode:         AlphaMode::Blend,
    ..Default::default()
}

If I remove the ..Default::default() line, rustfmt will align the fields as expected:

StandardMaterial {
    base_color_texture: Some(asset_server.load("textures/card_back.png")),
    cull_mode:          Some(Face::Front),
    fog_enabled:        false,
    unlit:              true,
    alpha_mode:         AlphaMode::Blend,
}

theon avatar Feb 18 '24 23:02 theon

@theon thanks for the report. For reference, what value are you setting struct_field_align_threshold to?

ytmimi avatar Feb 18 '24 23:02 ytmimi

I've got it set really high at 200 (I wanted fields to always be aligned). From my rustfmt.toml:

struct_field_align_threshold = 200

theon avatar Feb 19 '24 00:02 theon