Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saying121 opened this issue Feb 26, 2024 · 1 comment
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce p-low

Comments

@saying121
Copy link

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
@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce p-low labels Feb 26, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Feb 26, 2024

Thanks for the report!

This is definitely a bug since it takes rustfmt two runs before it settles on stable formatting. Seems like a strange interaction with these two options. Also, linking the tracking issue for struct_field_align_threshold #3371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce p-low
Projects
None yet
Development

No branches or pull requests

2 participants