From 0df2419d1e2a04ade3088aa7b7be31a9b36f6e49 Mon Sep 17 00:00:00 2001 From: GambitingMan Date: Sun, 24 Sep 2023 10:47:49 +0200 Subject: [PATCH 1/3] Fixed error caused by combination of match_arm_blocks and control_brace_style --- src/matches.rs | 2 +- tests/source/issue_5912.rs | 15 +++++++++++++++ tests/target/issue_5912.rs | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue_5912.rs create mode 100644 tests/target/issue_5912.rs diff --git a/src/matches.rs b/src/matches.rs index 95b0ed16db8..45f8bd90206 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -451,8 +451,8 @@ fn rewrite_match_body( }; let block_sep = match context.config.control_brace_style() { - ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix), _ if body_prefix.is_empty() => "".to_owned(), + ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix), _ if forbid_same_line || !arrow_comment.is_empty() => { format!("{}{}", alt_block_sep, body_prefix) } diff --git a/tests/source/issue_5912.rs b/tests/source/issue_5912.rs new file mode 100644 index 00000000000..2265fd2146c --- /dev/null +++ b/tests/source/issue_5912.rs @@ -0,0 +1,15 @@ +// rustfmt-match_arm_blocks: false +// rustfmt-control_brace_style: AlwaysNextLine + +fn foo() { + match 0 { + 0 => { + aaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbb + + bbbbbbbbbbbbbbbbbbbbbbbbb + + bbbbbbbbbbbbbbbbbbbbbbbbb + + bbbbbbbbbbbbbbbbbbbbbbbbb + } + _ => 2, + } +} diff --git a/tests/target/issue_5912.rs b/tests/target/issue_5912.rs new file mode 100644 index 00000000000..835f2aba971 --- /dev/null +++ b/tests/target/issue_5912.rs @@ -0,0 +1,15 @@ +// rustfmt-match_arm_blocks: false +// rustfmt-control_brace_style: AlwaysNextLine + +fn foo() { + match 0 + { + 0 => + aaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbb + + bbbbbbbbbbbbbbbbbbbbbbbbb + + bbbbbbbbbbbbbbbbbbbbbbbbb + + bbbbbbbbbbbbbbbbbbbbbbbbb, + _ => 2, + } +} From bb2552d1aea70ef6933d69a41458c57ecaeec6cd Mon Sep 17 00:00:00 2001 From: GambitingMan Date: Sun, 15 Oct 2023 11:08:43 +0200 Subject: [PATCH 2/3] Added test to specifically check that no error occurs --- tests/rustfmt/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 7dcf7c8416e..b3976410d8e 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -184,3 +184,19 @@ fn dont_emit_ICE() { assert!(!stderr.contains("thread 'main' panicked")); } } + +#[test] +fn rustfmt_emits_error_when_control_bace_style_is_always_next_line() { + // See also https://github.com/rust-lang/rustfmt/issues/5912 + let args = [ + "--config=color=Never", + "--config", + "control_brace_style=AlwaysNextLine", + "--config", + "match_arm_blocks=false", + "tests/target/issue_5912.rs", + ]; + + let (_stdout, stderr) = rustfmt(&args); + assert!(!stderr.contains("error[internal]: left behind trailing whitespace")) +} From 6ac4fdb94cb56a01e5af8de8fe2677caa83e1fd8 Mon Sep 17 00:00:00 2001 From: GambitingMan <68272188+GambitingMan@users.noreply.github.com> Date: Sun, 15 Oct 2023 12:03:20 +0200 Subject: [PATCH 3/3] Typo --- tests/rustfmt/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index b3976410d8e..87b55ca1d1d 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -186,7 +186,7 @@ fn dont_emit_ICE() { } #[test] -fn rustfmt_emits_error_when_control_bace_style_is_always_next_line() { +fn rustfmt_emits_error_when_control_brace_style_is_always_next_line() { // See also https://github.com/rust-lang/rustfmt/issues/5912 let args = [ "--config=color=Never",