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:
parent
eff665c5c4
commit
b8da53ad78
30
src/expr.rs
30
src/expr.rs
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
23
tests/source/issue-1127.rs
Normal file
23
tests/source/issue-1127.rs
Normal 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(),
|
||||
};
|
||||
}
|
||||
|
25
tests/target/issue-1127.rs
Normal file
25
tests/target/issue-1127.rs
Normal 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(),
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue