Skip to content

Possible suboptimal formatting on if let with multiple patterns #6113

Open
@rsammelson

Description

@rsammelson

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,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions