Skip to content

silent formatting failure in match statements #5950

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

Closed
boemjay opened this issue Oct 27, 2023 · 1 comment
Closed

silent formatting failure in match statements #5950

boemjay opened this issue Oct 27, 2023 · 1 comment
Labels
a-matches match arms, patterns, blocks, etc duplicate

Comments

@boemjay
Copy link

boemjay commented Oct 27, 2023

Error

rustfmt fails to format any branches inside a match statement if it cannot format the whole statement.

Expected Behaviour

All other branches in the match statement should be formatted correctly, even if one branch fails to format.

Steps to reproduce

Try to format the following main.rs:

fn main() {
    match true {
        false => {println!("nothing inside this match statement is formatted anymore")
        }
        _ => "String causing the failure xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    };
}

Output of rustfmt --check:
None

Now remove one of the x placeholder characters in the string and format again.

Output of rustfmt --check:

 fn main() {
     match true {
-        false => {println!("nothing inside this match statement is formatted anymore")
+        false => {
+            println!("nothing inside this match statement is formatted anymore")
         }
-        _ => "String causing the failure xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+        _ => {
+            "String causing the failure xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+        }
     };
 }

Additional Information

Tested on rustfmt 1.6.0-nightly (fcab248 2023-10-13)

@ytmimi
Copy link
Contributor

ytmimi commented Oct 27, 2023

Thanks for reaching out. This is a duplicate of #4797

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2023
@ytmimi ytmimi added duplicate a-matches match arms, patterns, blocks, etc labels Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-matches match arms, patterns, blocks, etc duplicate
Projects
None yet
Development

No branches or pull requests

2 participants