Skip to content

Commit

Permalink
Don't drop opening brace on long line matches. (#1228)
Browse files Browse the repository at this point in the history
* Don't drop opening brace on long line matches.

Fixes #1225

* Added a test case for long match arms with braces on newline.
  • Loading branch information
luke-clifton authored and nrc committed Nov 28, 2016
1 parent 6bf1382 commit 56469a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/expr.rs
Expand Up @@ -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(),
Expand Down
14 changes: 14 additions & 0 deletions 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),
}
}
15 changes: 15 additions & 0 deletions 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),
}
}

0 comments on commit 56469a8

Please sign in to comment.