Skip to content

Commit 56469a8

Browse files
luke-cliftonnrc
authored andcommitted
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.
1 parent 6bf1382 commit 56469a8

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,17 +1315,17 @@ impl Rewrite for ast::Arm {
13151315
let indent_str = offset.block_indent(context.config).to_string(context.config);
13161316
let (body_prefix, body_suffix) = if context.config.wrap_match_arms {
13171317
if context.config.match_block_trailing_comma {
1318-
(" {", "},")
1318+
("{", "},")
13191319
} else {
1320-
(" {", "}")
1320+
("{", "}")
13211321
}
13221322
} else {
13231323
("", "")
13241324
};
13251325

13261326
let block_sep = match context.config.control_brace_style {
1327-
ControlBraceStyle::AlwaysNextLine => alt_block_sep,
1328-
ControlBraceStyle::AlwaysSameLine => String::from(body_prefix) + "\n",
1327+
ControlBraceStyle::AlwaysNextLine => alt_block_sep + body_prefix + "\n",
1328+
ControlBraceStyle::AlwaysSameLine => String::from(" ") + body_prefix + "\n",
13291329
};
13301330
Some(format!("{}{} =>{}{}{}\n{}{}",
13311331
attr_str.trim_left(),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// rustfmt-max_width: 80
2+
// rustfmt-control_brace_style: AlwaysNextLine
3+
4+
fn main() {
5+
match x {
6+
aaaaaaaa::Bbbbb::Ccccccccccccc(_, Some(ref x)) if x ==
7+
"aaaaaaaaaaa \
8+
aaaaaaa \
9+
aaaaaa" => {
10+
Ok(())
11+
}
12+
_ => Err(x),
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-max_width: 80
2+
// rustfmt-control_brace_style: AlwaysNextLine
3+
4+
fn main() {
5+
match x
6+
{
7+
aaaaaaaa::Bbbbb::Ccccccccccccc(_, Some(ref x)) if x ==
8+
"aaaaaaaaaaa \
9+
aaaaaaa aaaaaa" =>
10+
{
11+
Ok(())
12+
}
13+
_ => Err(x),
14+
}
15+
}

0 commit comments

Comments
 (0)