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

control_brace_style="AlwaysSameLine" is not respected when "if" and "if let" line length is near max_width #5349

Open
pozdneev opened this issue May 22, 2022 · 2 comments
Labels
only-with-option requires a non-default option value to reproduce p-low

Comments

@pozdneev
Copy link
Contributor

If the if let of if line length is near max_width, then the control_brace_style option of rustfmt pushes the opening brace to the next line. (Notice that this option is still unstable.)

I observe this behaviour for "rustfmt 1.4.38-nightly (9257f5aa 2022-05-21)".

In the examples given below, the closing parenthesis character in the non-wrapped if let- an if- expressions is the 100th character in the line.

"AlwaysSameLine"

unstable_features = true
control_brace_style = "AlwaysSameLine"

The formatting does match the expectations neither for if let, nor for if:

fn main() {
    if let Some(x) = some_function_with_a_long_list_of_args(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
    {
        return;
    }

    if some_boolean_function_with_a_long_name_and_a_long_list_of_args(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    {
        return;
    }
}

"AlwaysSameLine" + max_width=102

unstable_features = true
control_brace_style = "AlwaysSameLine"
max_width = 102

The formatting matches the expectations for both if let and if:

fn main() {
    if let Some(x) = some_function_with_a_long_list_of_args(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) {
        return;
    }

    if some_boolean_function_with_a_long_name_and_a_long_list_of_args(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) {
        return;
    }
}

"AlwaysSameLine" + max_width=99

unstable_features = true
control_brace_style = "AlwaysSameLine"
max_width = 99

The formatting does match the expectations for if let, but matches the expectations for if:

fn main() {
    if let Some(x) =
        some_function_with_a_long_list_of_args(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
    {
        return;
    }

    if some_boolean_function_with_a_long_name_and_a_long_list_of_args(
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
    ) {
        return;
    }
}

(A similar issue to the one shown in this example is mentioned here: #3560 (comment). In that one, the content of the if let is much less than max_width, but it gets folded like here, and the opening brace is pushed to the next line as well.)

"AlwaysNextLine"

unstable_features = true
control_brace_style = "AlwaysNextLine"
max_width = 102

The formatting matches the expectations for both if let and if:

fn main() {
    if let Some(x) = some_function_with_a_long_list_of_args(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
    {
        return;
    }

    if some_boolean_function_with_a_long_name_and_a_long_list_of_args(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    {
        return;
    }
}
@ytmimi ytmimi added the only-with-option requires a non-default option value to reproduce label May 23, 2022
@ytmimi ytmimi added the p-low label Jul 27, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Jul 27, 2022

linking tracking issue for control_brace_style #3377

@mqus
Copy link

mqus commented Mar 18, 2023

I just want to note that AlwaysSameLine is the default, so at least the first buggy example should be reproducible with only stable options (or no options at all) and the others only really configure max_width which probably does not have anything to do with this bug, so the label is probably wrong

This bug seems similar to #3560.

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

No branches or pull requests

3 participants