Skip to content

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

@programmerjake

Description

@programmerjake
Member

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)

Activity

VeaaC

VeaaC commented on Oct 31, 2018

@VeaaC

Might be a duplicate of/related to #3135

ytmimi

ytmimi commented on Jul 19, 2022

@ytmimi
Contributor

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.

added
a-matchesmatch arms, patterns, blocks, etc
and removed
a-matchesmatch arms, patterns, blocks, etc
on Jul 20, 2022
ytmimi

ytmimi commented on Jul 20, 2022

@ytmimi
Contributor

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----------------------------------------------------------------------.
"#
        }
    };
}
added 2 commits that reference this issue on Feb 11, 2025
0cb377c
a605205
added a commit that references this issue on Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nrc@programmerjake@VeaaC@ytmimi

        Issue actions

          Fail to format match arm when other arm has long line · Issue #3156 · rust-lang/rustfmt