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

Possible suboptimal formatting on if let with multiple patterns #6113

Open
rsammelson opened this issue Mar 12, 2024 · 0 comments
Open

Possible suboptimal formatting on if let with multiple patterns #6113

rsammelson opened this issue Mar 12, 2024 · 0 comments

Comments

@rsammelson
Copy link
Contributor

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,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant