Skip to content

Commit 39d85b0

Browse files
committed
Combine a sigle argument and a short callee
1 parent c3d6ae7 commit 39d85b0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/expr.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,9 @@ where
18141814
};
18151815
let used_width = extra_offset(callee_str, shape);
18161816
let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;
1817+
// 1 = "("
1818+
let combine_arg_with_callee =
1819+
callee_str.len() + 1 <= context.config.tab_spaces() && args.len() == 1;
18171820

18181821
// 1 = "(" or ")"
18191822
let one_line_shape = shape
@@ -1838,6 +1841,7 @@ where
18381841
one_line_width,
18391842
args_max_width,
18401843
force_trailing_comma,
1844+
combine_arg_with_callee,
18411845
)?;
18421846

18431847
if !context.use_block_indent() && need_block_indent(&list_str, nested_shape) && !extendable {
@@ -1878,6 +1882,7 @@ fn rewrite_call_args<'a, T>(
18781882
one_line_width: usize,
18791883
args_max_width: usize,
18801884
force_trailing_comma: bool,
1885+
combine_arg_with_callee: bool,
18811886
) -> Option<(bool, String)>
18821887
where
18831888
T: Rewrite + Spanned + ToExpr + 'a,
@@ -1907,6 +1912,7 @@ where
19071912
nested_shape,
19081913
one_line_width,
19091914
args_max_width,
1915+
combine_arg_with_callee,
19101916
);
19111917

19121918
let fmt = ListFormatting {
@@ -1937,19 +1943,22 @@ fn try_overflow_last_arg<'a, T>(
19371943
nested_shape: Shape,
19381944
one_line_width: usize,
19391945
args_max_width: usize,
1946+
combine_arg_with_callee: bool,
19401947
) -> DefinitiveListTactic
19411948
where
19421949
T: Rewrite + Spanned + ToExpr + 'a,
19431950
{
1944-
let overflow_last = can_be_overflowed(context, args);
1951+
let overflow_last = combine_arg_with_callee || can_be_overflowed(context, args);
19451952

19461953
// Replace the last item with its first line to see if it fits with
19471954
// first arguments.
19481955
let placeholder = if overflow_last {
19491956
let mut context = context.clone();
1950-
if let Some(expr) = args[args.len() - 1].to_expr() {
1951-
if let ast::ExprKind::MethodCall(..) = expr.node {
1952-
context.force_one_line_chain = true;
1957+
if !combine_arg_with_callee {
1958+
if let Some(expr) = args[args.len() - 1].to_expr() {
1959+
if let ast::ExprKind::MethodCall(..) = expr.node {
1960+
context.force_one_line_chain = true;
1961+
}
19531962
}
19541963
}
19551964
last_arg_shape(args, item_vec, one_line_shape, args_max_width).and_then(|arg_shape| {

0 commit comments

Comments
 (0)