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

Fail to format match arm when other arm has long line #3156

Open
programmerjake opened this issue Oct 30, 2018 · 3 comments
Open

Fail to format match arm when other arm has long line #3156

programmerjake opened this issue Oct 30, 2018 · 3 comments

Comments

@programmerjake
Copy link
Member

programmerjake commented Oct 30, 2018

Rustfmt is not formatting the let a=0; part in this reduced testcase:

fn f() {
    let mut a = Vec::new();
    a.push(match 0 {
        0 => {let a=0;""}
        _ => r#"
--------------------loong line----------------------------------------------------------------------.
"#,
    });
}

I am using rustfmt version:
rustfmt 0.99.6-nightly (750b252 2018-10-18)

@VeaaC
Copy link

VeaaC commented Oct 31, 2018

Might be a duplicate of/related to #3135

@ytmimi
Copy link
Contributor

ytmimi commented Jul 19, 2022

I can confirm that this is reproducible on rustfmt 1.5.1-nightly (a7bf0090 2022-07-17). The input from the issue description is left unchanged.

@ytmimi ytmimi added a-matches match arms, patterns, blocks, etc a-strings String literals a-chains duplicate and removed a-matches match arms, patterns, blocks, etc labels Jul 20, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

I believe this is also a duplicate of #3416 and #3863

If we remove the call to a.push in the example above rustfmt is able to format the match statement, which leads me to believe that we're dealing with the same issue as #3416 and #3863.

Input

fn f() {
    let mut a = Vec::new();
    match 0 {
        0 => {let a=0;""}
        _ => r#"
--------------------loong line----------------------------------------------------------------------.
"#,
    };
}

Output

fn f() {
    let mut a = Vec::new();
    match 0 {
        0 => {
            let a = 0;
            ""
        }
        _ => {
            r#"
--------------------loong line----------------------------------------------------------------------.
"#
        }
    };
}

jhpratt added a commit to jhpratt/rust that referenced this issue Feb 11, 2025
…braheemdev

Fix long lines which rustfmt fails to format

rustfmt fails to format this match expression, because it has several long string literals over the maximum line width. This seems to exhibit rustfmt issues [rust-lang#3863](rust-lang/rustfmt#3863) (Gives up on chains if any line is too long) and [rust-lang#3156](rust-lang/rustfmt#3156) (Fail to format match arm when other arm has long line).

Format it with a large line width (e.g., by setting `max_width = 200` in rustfmt.toml) and, in case the rustfmt bugs are later fixed, mark it with `#[rustfmt::skip]`, as it is more legible with each case on one line.
jhpratt added a commit to jhpratt/rust that referenced this issue Feb 11, 2025
…braheemdev

Fix long lines which rustfmt fails to format

rustfmt fails to format this match expression, because it has several long string literals over the maximum line width. This seems to exhibit rustfmt issues [rust-lang#3863](rust-lang/rustfmt#3863) (Gives up on chains if any line is too long) and [rust-lang#3156](rust-lang/rustfmt#3156) (Fail to format match arm when other arm has long line).

Format it with a large line width (e.g., by setting `max_width = 200` in rustfmt.toml) and, in case the rustfmt bugs are later fixed, mark it with `#[rustfmt::skip]`, as it is more legible with each case on one line.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2025
Rollup merge of rust-lang#136606 - thaliaarchi:format-long-lines, r=ibraheemdev

Fix long lines which rustfmt fails to format

rustfmt fails to format this match expression, because it has several long string literals over the maximum line width. This seems to exhibit rustfmt issues [rust-lang#3863](rust-lang/rustfmt#3863) (Gives up on chains if any line is too long) and [rust-lang#3156](rust-lang/rustfmt#3156) (Fail to format match arm when other arm has long line).

Format it with a large line width (e.g., by setting `max_width = 200` in rustfmt.toml) and, in case the rustfmt bugs are later fixed, mark it with `#[rustfmt::skip]`, as it is more legible with each case on one line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants