Try multi-line only when fn_call_style is Block and rewriting function call

This commit is contained in:
topecongiro 2017-05-11 13:38:26 +09:00
parent 18070f4041
commit ba1a7b9e7f
5 changed files with 34 additions and 1 deletions

View File

@ -1779,7 +1779,12 @@ fn rewrite_call_args(context: &RewriteContext,
};
match write_list(&item_vec, &fmt) {
Some(ref s) if !s.contains('\n') && s.len() > one_line_width => {
// If arguments do not fit in a single line and do not contain newline,
// try to put it on the next line. Try this only when we are in block mode
// and not rewriting macro.
Some(ref s) if context.config.fn_call_style == IndentStyle::Block &&
!force_no_trailing_comma &&
(!s.contains('\n') && s.len() > one_line_width) => {
fmt.trailing_separator = SeparatorTactic::Vertical;
write_list(&item_vec, &fmt)
}

View File

@ -0,0 +1,7 @@
// rustfmt-error_on_line_overflow: false
// rustfmt-fn_call_style: Block
// rustfmt should not add trailing comma when rewriting macro. See #1528.
fn a() {
panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:");
}

View File

@ -0,0 +1,7 @@
// rustfmt-error_on_line_overflow: false
// rustfmt-fn_call_style: Visual
// rustfmt should not add trailing comma when rewriting macro. See #1528.
fn a() {
panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:");
}

View File

@ -0,0 +1,7 @@
// rustfmt-error_on_line_overflow: false
// rustfmt-fn_call_style: Block
// rustfmt should not add trailing comma when rewriting macro. See #1528.
fn a() {
panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:");
}

View File

@ -0,0 +1,7 @@
// rustfmt-error_on_line_overflow: false
// rustfmt-fn_call_style: Visual
// rustfmt should not add trailing comma when rewriting macro. See #1528.
fn a() {
panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:");
}