diff --git a/src/matches.rs b/src/matches.rs index 22d23fc1cdb..e6fe505728a 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -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() => { diff --git a/tests/source/match_arm_blocks/false-always-next-line.rs b/tests/source/match_arm_blocks/false-always-next-line.rs new file mode 100644 index 00000000000..08faecf79a3 --- /dev/null +++ b/tests/source/match_arm_blocks/false-always-next-line.rs @@ -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"), + }; +} diff --git a/tests/source/match_arm_blocks/false-always-same-line.rs b/tests/source/match_arm_blocks/false-always-same-line.rs new file mode 100644 index 00000000000..1c084b7aa88 --- /dev/null +++ b/tests/source/match_arm_blocks/false-always-same-line.rs @@ -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"), + }; +} diff --git a/tests/source/match_arm_blocks/false-closing-next-line.rs b/tests/source/match_arm_blocks/false-closing-next-line.rs new file mode 100644 index 00000000000..129afa7e52c --- /dev/null +++ b/tests/source/match_arm_blocks/false-closing-next-line.rs @@ -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"), + }; +} diff --git a/tests/source/match_arm_blocks/true-always-next-line.rs b/tests/source/match_arm_blocks/true-always-next-line.rs new file mode 100644 index 00000000000..aa1e6fe447a --- /dev/null +++ b/tests/source/match_arm_blocks/true-always-next-line.rs @@ -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"), + }; +} diff --git a/tests/source/match_arm_blocks/true-always-same-line.rs b/tests/source/match_arm_blocks/true-always-same-line.rs new file mode 100644 index 00000000000..ccc321599a7 --- /dev/null +++ b/tests/source/match_arm_blocks/true-always-same-line.rs @@ -0,0 +1,10 @@ +fn main() { + let fooooooo = "100000000000000000000000"; + let _bar = match fooooooo + { + "100000000000000000000000" => + + fooooooo.len() == 1 && fooooooo.contains("222222222222222222"), + _ => unreachable!("Should not happen"), + }; +} diff --git a/tests/source/match_arm_blocks/true-closing-next-line.rs b/tests/source/match_arm_blocks/true-closing-next-line.rs new file mode 100644 index 00000000000..375bff9af83 --- /dev/null +++ b/tests/source/match_arm_blocks/true-closing-next-line.rs @@ -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"), + }; +} diff --git a/tests/target/match_arm_blocks/false-always-next-line.rs b/tests/target/match_arm_blocks/false-always-next-line.rs new file mode 100644 index 00000000000..05b9e0d4308 --- /dev/null +++ b/tests/target/match_arm_blocks/false-always-next-line.rs @@ -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"), + }; +} diff --git a/tests/target/match_arm_blocks/false-always-same-line.rs b/tests/target/match_arm_blocks/false-always-same-line.rs new file mode 100644 index 00000000000..81cd73aacff --- /dev/null +++ b/tests/target/match_arm_blocks/false-always-same-line.rs @@ -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"), + }; +} diff --git a/tests/target/match_arm_blocks/false-closing-next-line.rs b/tests/target/match_arm_blocks/false-closing-next-line.rs new file mode 100644 index 00000000000..ac9d6accc7a --- /dev/null +++ b/tests/target/match_arm_blocks/false-closing-next-line.rs @@ -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"), + }; +} diff --git a/tests/target/match_arm_blocks/true-always-next-line.rs b/tests/target/match_arm_blocks/true-always-next-line.rs new file mode 100644 index 00000000000..c982f27c4f8 --- /dev/null +++ b/tests/target/match_arm_blocks/true-always-next-line.rs @@ -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"), + }; +} diff --git a/tests/target/match_arm_blocks/true-always-same-line.rs b/tests/target/match_arm_blocks/true-always-same-line.rs new file mode 100644 index 00000000000..d76bc9eebc3 --- /dev/null +++ b/tests/target/match_arm_blocks/true-always-same-line.rs @@ -0,0 +1,9 @@ +fn main() { + let fooooooo = "100000000000000000000000"; + let _bar = match fooooooo { + "100000000000000000000000" => { + fooooooo.len() == 1 && fooooooo.contains("222222222222222222") + } + _ => unreachable!("Should not happen"), + }; +} diff --git a/tests/target/match_arm_blocks/true-closing-next-line.rs b/tests/target/match_arm_blocks/true-closing-next-line.rs new file mode 100644 index 00000000000..51a3facdb24 --- /dev/null +++ b/tests/target/match_arm_blocks/true-closing-next-line.rs @@ -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"), + }; +}