From ba1a7b9e7f56c0c9fa8e6ef9d4b2ebec192ddc89 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Thu, 11 May 2017 13:38:26 +0900 Subject: [PATCH] Try multi-line only when fn_call_style is Block and rewriting function call --- src/expr.rs | 7 ++++++- tests/source/configs-fn_call_style-block-trailing-comma.rs | 7 +++++++ .../source/configs-fn_call_style-visual-trailing-comma.rs | 7 +++++++ tests/target/configs-fn_call_style-block-trailing-comma.rs | 7 +++++++ .../target/configs-fn_call_style-visual-trailing-comma.rs | 7 +++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/source/configs-fn_call_style-block-trailing-comma.rs create mode 100644 tests/source/configs-fn_call_style-visual-trailing-comma.rs create mode 100644 tests/target/configs-fn_call_style-block-trailing-comma.rs create mode 100644 tests/target/configs-fn_call_style-visual-trailing-comma.rs diff --git a/src/expr.rs b/src/expr.rs index cf92b7ecc0e..da9a96bf19f 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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) } diff --git a/tests/source/configs-fn_call_style-block-trailing-comma.rs b/tests/source/configs-fn_call_style-block-trailing-comma.rs new file mode 100644 index 00000000000..3f3d1dec2ea --- /dev/null +++ b/tests/source/configs-fn_call_style-block-trailing-comma.rs @@ -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:"); +} diff --git a/tests/source/configs-fn_call_style-visual-trailing-comma.rs b/tests/source/configs-fn_call_style-visual-trailing-comma.rs new file mode 100644 index 00000000000..61be7c5ea93 --- /dev/null +++ b/tests/source/configs-fn_call_style-visual-trailing-comma.rs @@ -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:"); +} diff --git a/tests/target/configs-fn_call_style-block-trailing-comma.rs b/tests/target/configs-fn_call_style-block-trailing-comma.rs new file mode 100644 index 00000000000..3f3d1dec2ea --- /dev/null +++ b/tests/target/configs-fn_call_style-block-trailing-comma.rs @@ -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:"); +} diff --git a/tests/target/configs-fn_call_style-visual-trailing-comma.rs b/tests/target/configs-fn_call_style-visual-trailing-comma.rs new file mode 100644 index 00000000000..61be7c5ea93 --- /dev/null +++ b/tests/target/configs-fn_call_style-visual-trailing-comma.rs @@ -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:"); +}