]> git.lizzy.rs Git - rust.git/commitdiff
Try multi-line only when fn_call_style is Block and rewriting function call
authortopecongiro <seuchida@gmail.com>
Thu, 11 May 2017 04:38:26 +0000 (13:38 +0900)
committertopecongiro <seuchida@gmail.com>
Fri, 12 May 2017 01:33:05 +0000 (10:33 +0900)
src/expr.rs
tests/source/configs-fn_call_style-block-trailing-comma.rs [new file with mode: 0644]
tests/source/configs-fn_call_style-visual-trailing-comma.rs [new file with mode: 0644]
tests/target/configs-fn_call_style-block-trailing-comma.rs [new file with mode: 0644]
tests/target/configs-fn_call_style-visual-trailing-comma.rs [new file with mode: 0644]

index cf92b7ecc0e353183e2f75f0165006d9b900105e..da9a96bf19f303bae84a716c7f27458a03922493 100644 (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)
         }
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 (file)
index 0000000..3f3d1de
--- /dev/null
@@ -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 (file)
index 0000000..61be7c5
--- /dev/null
@@ -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 (file)
index 0000000..3f3d1de
--- /dev/null
@@ -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 (file)
index 0000000..61be7c5
--- /dev/null
@@ -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:");
+}