Skip to content

struct_field_align_threshold = 30 doesn't apply when using use_field_init_shorthand = true #6096

Open
@saying121

Description

@saying121

Formatting incorrectly

I have this code

pub struct Test {
    one:         i32,
    two:         i32,
    three_three: i32,
    four:        i32,
}

impl Test {
    pub fn new(one: i32, bbb: i32, ccccc: i32, ddddd: i32) -> Self {
        Self {
            one:         one,
            two:         bbb,
            three_three: ccccc,
            four:        ddddd,
        }
    }
}

Executing formatting

pub struct Test {
    one:         i32,
    two:         i32,
    three_three: i32,
    four:        i32,
}

impl Test {
    pub fn new(one: i32, bbb: i32, ccccc: i32, ddddd: i32) -> Self {
        Self {
            one,
            two:         bbb,
            three_three: ccccc,
            four:        ddddd,
        }
    }
}

Formatting again

pub struct Test {
    one:         i32,
    two:         i32,
    three_three: i32,
    four:        i32,
}

impl Test {
    pub fn new(one: i32, bbb: i32, ccccc: i32, ddddd: i32) -> Self {
        Self {
            one,
            two: bbb,
            three_three: ccccc,
            four: ddddd,
        }
    }
}

When use_field_init_shorthand is in effect,
the struct_field_align_threshold behaves incorrectly.

Version

rustfmt 1.7.0-nightly (0ecbd06 2024-02-25)

Rustfmt Config

struct_field_align_threshold        = 30
use_field_init_shorthand            = true

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproducep-low

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions