rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Possible suboptimal formatting on `if let` with multiple patterns

Open rsammelson opened this issue 11 months ago • 0 comments

The indentation of the second pattern in these functions (especially the first one) looks kind of odd. I can look into fixing it if it should be fixed.

pub fn f(input_value: Test) -> (u8, u8) {
    let intermediate = if let Test::OptionWithLongNameA { value1, value2, .. }
    | Test::OptionWithLongNameB { value1, value2, .. } = input_value
    {
        (*value1, *value2)
    } else {
        unreachable!()
    };
    intermediate
}

pub fn g(input_value: Test) -> (u8, u8) {
    let very_very_long_name_for_intermediate =
        if let Test::OptionWithLongNameA { value1, value2, .. }
        | Test::OptionWithLongNameB { value1, value2, .. } = input_value
        {
            (*value1, *value2)
        } else {
            unreachable!()
        };
    very_very_long_name_for_intermediate
}

pub fn h(long_input_value_name: Test) -> (u8, u8) {
    if let Test::OptionWithLongNameA { value1, value2, .. }
    | Test::OptionWithLongNameB { value1, value2, .. } = long_input_value_name
    {
        (*value1, *value2)
    } else {
        unreachable!()
    }
}

enum Test {
    OptionWithLongNameA { value1: u8, value2: u8, value3: u8 },
    OptionWithLongNameB { value1: u8, value2: u8, value3: u8 },
    NeverUsed1,
}

rsammelson avatar Mar 12 '24 23:03 rsammelson