Fix wrap_match_arms resulting in a missing comma (#1307)

* Fix match arms missing comma with "wrap_match_arms = false"

* remove assert; use body_suffix for comma

* basic test case for issue 1127
This commit is contained in:
Marcus Ball 2017-02-28 15:46:10 -05:00 committed by Nick Cameron
parent eff665c5c4
commit b8da53ad78
3 changed files with 69 additions and 9 deletions

View file

@ -1293,21 +1293,33 @@ impl Rewrite for ast::Arm {
("{", "}")
}
} else {
("", "")
("", ",")
};
let block_sep = match context.config.control_brace_style {
ControlBraceStyle::AlwaysNextLine => alt_block_sep + body_prefix + "\n",
_ => String::from(" ") + body_prefix + "\n",
};
Some(format!("{}{} =>{}{}{}\n{}{}",
attr_str.trim_left(),
pats_str,
block_sep,
indent_str,
next_line_body,
shape.indent.to_string(context.config),
body_suffix))
if context.config.wrap_match_arms {
Some(format!("{}{} =>{}{}{}\n{}{}",
attr_str.trim_left(),
pats_str,
block_sep,
indent_str,
next_line_body,
shape.indent.to_string(context.config),
body_suffix))
} else {
Some(format!("{}{} =>{}{}{}{}",
attr_str.trim_left(),
pats_str,
block_sep,
indent_str,
next_line_body,
body_suffix))
}
}
}

View file

@ -0,0 +1,23 @@
// rustfmt-max_width:120
// rustfmt-wrap_match_arms: false
// rustfmt-match_block_trailing_comma: true
fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 {
42
}
enum TestEnum {
AVeryVeryLongEnumName,
AnotherVeryLongEnumName,
TheLastVeryLongEnumName,
}
fn main() {
let var = TestEnum::AVeryVeryLongEnumName;
let num = match var {
TestEnum::AVeryVeryLongEnumName => a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
TestEnum::AnotherVeryLongEnumName => a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
TestEnum::TheLastVeryLongEnumName => a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
};
}

View file

@ -0,0 +1,25 @@
// rustfmt-max_width:120
// rustfmt-wrap_match_arms: false
// rustfmt-match_block_trailing_comma: true
fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 {
42
}
enum TestEnum {
AVeryVeryLongEnumName,
AnotherVeryLongEnumName,
TheLastVeryLongEnumName,
}
fn main() {
let var = TestEnum::AVeryVeryLongEnumName;
let num = match var {
TestEnum::AVeryVeryLongEnumName =>
a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
TestEnum::AnotherVeryLongEnumName =>
a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
TestEnum::TheLastVeryLongEnumName =>
a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
};
}