Skip to content

Commit 94a770a

Browse files
committed
Use correct shape when rewriting the last arg with overflowing
1 parent be19bab commit 94a770a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/expr.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,10 @@ where
18141814
let used_width = extra_offset(callee_str, shape);
18151815
let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;
18161816

1817+
// 1 = "(" or ")"
1818+
let one_line_shape = shape
1819+
.offset_left(last_line_width(callee_str) + 1)?
1820+
.sub_width(1)?;
18171821
let nested_shape = shape_from_indent_style(
18181822
context,
18191823
shape,
@@ -1828,6 +1832,7 @@ where
18281832
context,
18291833
args,
18301834
args_span,
1835+
one_line_shape,
18311836
nested_shape,
18321837
one_line_width,
18331838
args_max_width,
@@ -1867,7 +1872,8 @@ fn rewrite_call_args<'a, T>(
18671872
context: &RewriteContext,
18681873
args: &[&T],
18691874
span: Span,
1870-
shape: Shape,
1875+
one_line_shape: Shape,
1876+
nested_shape: Shape,
18711877
one_line_width: usize,
18721878
args_max_width: usize,
18731879
force_trailing_comma: bool,
@@ -1882,7 +1888,7 @@ where
18821888
",",
18831889
|item| item.span().lo(),
18841890
|item| item.span().hi(),
1885-
|item| item.rewrite(context, shape),
1891+
|item| item.rewrite(context, nested_shape),
18861892
span.lo(),
18871893
span.hi(),
18881894
true,
@@ -1896,7 +1902,8 @@ where
18961902
context,
18971903
&mut item_vec,
18981904
&args[..],
1899-
shape,
1905+
one_line_shape,
1906+
nested_shape,
19001907
one_line_width,
19011908
args_max_width,
19021909
);
@@ -1912,7 +1919,7 @@ where
19121919
context.config.trailing_comma()
19131920
},
19141921
separator_place: SeparatorPlace::Back,
1915-
shape: shape,
1922+
shape: nested_shape,
19161923
ends_with_newline: context.use_block_indent() && tactic == DefinitiveListTactic::Vertical,
19171924
preserve_newline: false,
19181925
config: context.config,
@@ -1927,7 +1934,8 @@ fn try_overflow_last_arg<'a, T>(
19271934
context: &RewriteContext,
19281935
item_vec: &mut Vec<ListItem>,
19291936
args: &[&T],
1930-
shape: Shape,
1937+
one_line_shape: Shape,
1938+
nested_shape: Shape,
19311939
one_line_width: usize,
19321940
args_max_width: usize,
19331941
) -> DefinitiveListTactic
@@ -1945,7 +1953,7 @@ where
19451953
context.force_one_line_chain = true;
19461954
}
19471955
}
1948-
last_arg_shape(&context, item_vec, shape, args_max_width).and_then(|arg_shape| {
1956+
last_arg_shape(&context, item_vec, one_line_shape, args_max_width).and_then(|arg_shape| {
19491957
rewrite_last_arg_with_overflow(&context, args, &mut item_vec[args.len() - 1], arg_shape)
19501958
})
19511959
} else {

0 commit comments

Comments
 (0)