]> git.lizzy.rs Git - rust.git/commitdiff
Use correct shape when rewriting the last arg with overflowing
authortopecongiro <seuchida@gmail.com>
Wed, 29 Nov 2017 08:32:31 +0000 (17:32 +0900)
committertopecongiro <seuchida@gmail.com>
Wed, 29 Nov 2017 08:32:31 +0000 (17:32 +0900)
src/expr.rs

index 812ebd5cf3a264e634aea12c86391e23507be3c3..96132229c9038920b43b7ff3c418abcc5f56dbcb 100644 (file)
@@ -1814,6 +1814,10 @@ pub fn rewrite_call_inner<'a, T>(
     let used_width = extra_offset(callee_str, shape);
     let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;
 
+    // 1 = "(" or ")"
+    let one_line_shape = shape
+        .offset_left(last_line_width(callee_str) + 1)?
+        .sub_width(1)?;
     let nested_shape = shape_from_indent_style(
         context,
         shape,
@@ -1828,6 +1832,7 @@ pub fn rewrite_call_inner<'a, T>(
         context,
         args,
         args_span,
+        one_line_shape,
         nested_shape,
         one_line_width,
         args_max_width,
@@ -1867,7 +1872,8 @@ fn rewrite_call_args<'a, T>(
     context: &RewriteContext,
     args: &[&T],
     span: Span,
-    shape: Shape,
+    one_line_shape: Shape,
+    nested_shape: Shape,
     one_line_width: usize,
     args_max_width: usize,
     force_trailing_comma: bool,
@@ -1882,7 +1888,7 @@ fn rewrite_call_args<'a, T>(
         ",",
         |item| item.span().lo(),
         |item| item.span().hi(),
-        |item| item.rewrite(context, shape),
+        |item| item.rewrite(context, nested_shape),
         span.lo(),
         span.hi(),
         true,
@@ -1896,7 +1902,8 @@ fn rewrite_call_args<'a, T>(
         context,
         &mut item_vec,
         &args[..],
-        shape,
+        one_line_shape,
+        nested_shape,
         one_line_width,
         args_max_width,
     );
@@ -1912,7 +1919,7 @@ fn rewrite_call_args<'a, T>(
             context.config.trailing_comma()
         },
         separator_place: SeparatorPlace::Back,
-        shape: shape,
+        shape: nested_shape,
         ends_with_newline: context.use_block_indent() && tactic == DefinitiveListTactic::Vertical,
         preserve_newline: false,
         config: context.config,
@@ -1927,7 +1934,8 @@ fn try_overflow_last_arg<'a, T>(
     context: &RewriteContext,
     item_vec: &mut Vec<ListItem>,
     args: &[&T],
-    shape: Shape,
+    one_line_shape: Shape,
+    nested_shape: Shape,
     one_line_width: usize,
     args_max_width: usize,
 ) -> DefinitiveListTactic
@@ -1945,7 +1953,7 @@ fn try_overflow_last_arg<'a, T>(
                 context.force_one_line_chain = true;
             }
         }
-        last_arg_shape(&context, item_vec, shape, args_max_width).and_then(|arg_shape| {
+        last_arg_shape(&context, item_vec, one_line_shape, args_max_width).and_then(|arg_shape| {
             rewrite_last_arg_with_overflow(&context, args, &mut item_vec[args.len() - 1], arg_shape)
         })
     } else {