diff --git a/src/expr.rs b/src/expr.rs index 13150015417..c1528fc6271 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1315,17 +1315,17 @@ impl Rewrite for ast::Arm { let indent_str = offset.block_indent(context.config).to_string(context.config); let (body_prefix, body_suffix) = if context.config.wrap_match_arms { if context.config.match_block_trailing_comma { - (" {", "},") + ("{", "},") } else { - (" {", "}") + ("{", "}") } } else { ("", "") }; let block_sep = match context.config.control_brace_style { - ControlBraceStyle::AlwaysNextLine => alt_block_sep, - ControlBraceStyle::AlwaysSameLine => String::from(body_prefix) + "\n", + ControlBraceStyle::AlwaysNextLine => alt_block_sep + body_prefix + "\n", + ControlBraceStyle::AlwaysSameLine => String::from(" ") + body_prefix + "\n", }; Some(format!("{}{} =>{}{}{}\n{}{}", attr_str.trim_left(), diff --git a/tests/source/long-match-arms-brace-newline.rs b/tests/source/long-match-arms-brace-newline.rs new file mode 100644 index 00000000000..79cfb927b49 --- /dev/null +++ b/tests/source/long-match-arms-brace-newline.rs @@ -0,0 +1,14 @@ +// rustfmt-max_width: 80 +// rustfmt-control_brace_style: AlwaysNextLine + +fn main() { + match x { + aaaaaaaa::Bbbbb::Ccccccccccccc(_, Some(ref x)) if x == + "aaaaaaaaaaa \ + aaaaaaa \ + aaaaaa" => { + Ok(()) + } + _ => Err(x), + } +} diff --git a/tests/target/long-match-arms-brace-newline.rs b/tests/target/long-match-arms-brace-newline.rs new file mode 100644 index 00000000000..36f0b75f6a1 --- /dev/null +++ b/tests/target/long-match-arms-brace-newline.rs @@ -0,0 +1,15 @@ +// rustfmt-max_width: 80 +// rustfmt-control_brace_style: AlwaysNextLine + +fn main() { + match x + { + aaaaaaaa::Bbbbb::Ccccccccccccc(_, Some(ref x)) if x == + "aaaaaaaaaaa \ + aaaaaaa aaaaaa" => + { + Ok(()) + } + _ => Err(x), + } +}