Don't drop opening brace on long line matches. (#1228)

* Don't drop opening brace on long line matches.

Fixes #1225

* Added a test case for long match arms with braces on newline.
This commit is contained in:
Luke Clifton 2016-11-28 08:47:38 +08:00 committed by Nick Cameron
parent 6bf1382927
commit 56469a8745
3 changed files with 33 additions and 4 deletions

View File

@ -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(),

View File

@ -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),
}
}

View File

@ -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),
}
}