Skip to content

Remove extra whitespace after match arrow #5072

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ fn rewrite_match_body(
};

let block_sep = match context.config.control_brace_style() {
ControlBraceStyle::AlwaysNextLine if !context.config.match_arm_blocks() => {
format!("{}", body_prefix)
}
ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix),
_ if body_prefix.is_empty() => "".to_owned(),
_ if forbid_same_line || !arrow_comment.is_empty() => {
Expand Down
13 changes: 13 additions & 0 deletions tests/source/match_arm_blocks/false-always-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// rustfmt-control_brace_style: AlwaysNextLine
// rustfmt-match_arm_blocks: false

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>

fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
12 changes: 12 additions & 0 deletions tests/source/match_arm_blocks/false-always-same-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rustfmt-match_arm_blocks: false

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>

fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
13 changes: 13 additions & 0 deletions tests/source/match_arm_blocks/false-closing-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// rustfmt-control_brace_style: ClosingNextLine
// rustfmt-match_arm_blocks: false

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>

fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
12 changes: 12 additions & 0 deletions tests/source/match_arm_blocks/true-always-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rustfmt-control_brace_style: AlwaysNextLine

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>

fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
10 changes: 10 additions & 0 deletions tests/source/match_arm_blocks/true-always-same-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>

fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
12 changes: 12 additions & 0 deletions tests/source/match_arm_blocks/true-closing-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rustfmt-control_brace_style: ClosingNextLine

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>

fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
12 changes: 12 additions & 0 deletions tests/target/match_arm_blocks/false-always-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rustfmt-control_brace_style: AlwaysNextLine
// rustfmt-match_arm_blocks: false

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>
fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
10 changes: 10 additions & 0 deletions tests/target/match_arm_blocks/false-always-same-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// rustfmt-match_arm_blocks: false

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo {
"100000000000000000000000" =>
fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
11 changes: 11 additions & 0 deletions tests/target/match_arm_blocks/false-closing-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// rustfmt-control_brace_style: ClosingNextLine
// rustfmt-match_arm_blocks: false

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo {
"100000000000000000000000" =>
fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
_ => unreachable!("Should not happen"),
};
}
13 changes: 13 additions & 0 deletions tests/target/match_arm_blocks/true-always-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// rustfmt-control_brace_style: AlwaysNextLine

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo
{
"100000000000000000000000" =>
{
fooooooo.len() == 1 && fooooooo.contains("222222222222222222")
}
_ => unreachable!("Should not happen"),
};
}
9 changes: 9 additions & 0 deletions tests/target/match_arm_blocks/true-always-same-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo {
"100000000000000000000000" => {
fooooooo.len() == 1 && fooooooo.contains("222222222222222222")
}
_ => unreachable!("Should not happen"),
};
}
11 changes: 11 additions & 0 deletions tests/target/match_arm_blocks/true-closing-next-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// rustfmt-control_brace_style: ClosingNextLine

fn main() {
let fooooooo = "100000000000000000000000";
let _bar = match fooooooo {
"100000000000000000000000" => {
fooooooo.len() == 1 && fooooooo.contains("222222222222222222")
}
_ => unreachable!("Should not happen"),
};
}