]> git.lizzy.rs Git - rust.git/commitdiff
Continue formatting function calls even if it does not fit in a single line
authortopecongiro <seuchida@gmail.com>
Thu, 22 Feb 2018 23:11:10 +0000 (08:11 +0900)
committertopecongiro <seuchida@gmail.com>
Thu, 22 Feb 2018 23:11:10 +0000 (08:11 +0900)
We may be able to format it using multiple lines.

rustfmt-core/src/expr.rs

index 1ed85619235b3db33dde0b4f5f72e2f0504716eb..f681b45498ba8d0e27d522113793a05d25001e8e 100644 (file)
@@ -1908,12 +1908,16 @@ pub fn rewrite_call_inner<'a, T>(
         1
     };
     let used_width = extra_offset(callee_str, shape);
-    let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;
+    let one_line_width = shape
+        .width
+        .checked_sub(used_width + 2 * paren_overhead)
+        .unwrap_or(0);
 
     // 1 = "(" or ")"
     let one_line_shape = shape
-        .offset_left(last_line_width(callee_str) + 1)?
-        .sub_width(1)?;
+        .offset_left(last_line_width(callee_str) + 1)
+        .and_then(|shape| shape.sub_width(1))
+        .unwrap_or(Shape { width: 0, ..shape });
     let nested_shape = shape_from_indent_style(
         context,
         shape,
@@ -1950,7 +1954,13 @@ pub fn rewrite_call_inner<'a, T>(
         );
     }
 
-    let args_shape = shape.sub_width(last_line_width(callee_str))?;
+    let args_shape = Shape {
+        width: shape
+            .width
+            .checked_sub(last_line_width(callee_str))
+            .unwrap_or(0),
+        ..shape
+    };
     Some(format!(
         "{}{}",
         callee_str,