mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 12:43:36 +00:00
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:
parent
6bf1382927
commit
56469a8745
@ -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(),
|
||||
|
14
tests/source/long-match-arms-brace-newline.rs
Normal file
14
tests/source/long-match-arms-brace-newline.rs
Normal 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),
|
||||
}
|
||||
}
|
15
tests/target/long-match-arms-brace-newline.rs
Normal file
15
tests/target/long-match-arms-brace-newline.rs
Normal 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),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user