Merge pull request #2210 from topecongiro/issue-2178
Combine a short callee and a single argument
This commit is contained in:
commit
8f6b6c28f7
17
src/expr.rs
17
src/expr.rs
@ -1850,6 +1850,9 @@ where
|
||||
};
|
||||
let used_width = extra_offset(callee_str, shape);
|
||||
let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;
|
||||
// 1 = "("
|
||||
let combine_arg_with_callee =
|
||||
callee_str.len() + 1 <= context.config.tab_spaces() && args.len() == 1;
|
||||
|
||||
// 1 = "(" or ")"
|
||||
let one_line_shape = shape
|
||||
@ -1874,6 +1877,7 @@ where
|
||||
one_line_width,
|
||||
args_max_width,
|
||||
force_trailing_comma,
|
||||
combine_arg_with_callee,
|
||||
)?;
|
||||
|
||||
if !context.use_block_indent() && need_block_indent(&list_str, nested_shape) && !extendable {
|
||||
@ -1914,6 +1918,7 @@ fn rewrite_call_args<'a, T>(
|
||||
one_line_width: usize,
|
||||
args_max_width: usize,
|
||||
force_trailing_comma: bool,
|
||||
combine_arg_with_callee: bool,
|
||||
) -> Option<(bool, String)>
|
||||
where
|
||||
T: Rewrite + Spanned + ToExpr + 'a,
|
||||
@ -1943,6 +1948,7 @@ where
|
||||
nested_shape,
|
||||
one_line_width,
|
||||
args_max_width,
|
||||
combine_arg_with_callee,
|
||||
);
|
||||
|
||||
let fmt = ListFormatting {
|
||||
@ -1973,19 +1979,22 @@ fn try_overflow_last_arg<'a, T>(
|
||||
nested_shape: Shape,
|
||||
one_line_width: usize,
|
||||
args_max_width: usize,
|
||||
combine_arg_with_callee: bool,
|
||||
) -> DefinitiveListTactic
|
||||
where
|
||||
T: Rewrite + Spanned + ToExpr + 'a,
|
||||
{
|
||||
let overflow_last = can_be_overflowed(context, args);
|
||||
let overflow_last = combine_arg_with_callee || can_be_overflowed(context, args);
|
||||
|
||||
// Replace the last item with its first line to see if it fits with
|
||||
// first arguments.
|
||||
let placeholder = if overflow_last {
|
||||
let mut context = context.clone();
|
||||
if let Some(expr) = args[args.len() - 1].to_expr() {
|
||||
if let ast::ExprKind::MethodCall(..) = expr.node {
|
||||
context.force_one_line_chain = true;
|
||||
if !combine_arg_with_callee {
|
||||
if let Some(expr) = args[args.len() - 1].to_expr() {
|
||||
if let ast::ExprKind::MethodCall(..) = expr.node {
|
||||
context.force_one_line_chain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
last_arg_shape(args, item_vec, one_line_shape, args_max_width).and_then(|arg_shape| {
|
||||
|
@ -355,3 +355,7 @@ fn newlines_between_list_like_expr() {
|
||||
_ => bar(),
|
||||
};
|
||||
}
|
||||
|
||||
fn issue2178() {
|
||||
Ok(result.iter().map(|item| ls_util::rls_to_location(item)).collect())
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ fn main() {
|
||||
// Test case where first chain element isn't a path, but is shorter than
|
||||
// the size of a tab.
|
||||
x().y(|| match cond() {
|
||||
true => (),
|
||||
false => (),
|
||||
});
|
||||
true => (),
|
||||
false => (),
|
||||
});
|
||||
|
||||
loong_func().quux(move || if true { 1 } else { 2 });
|
||||
|
||||
|
@ -408,3 +408,10 @@ fn newlines_between_list_like_expr() {
|
||||
_ => bar(),
|
||||
};
|
||||
}
|
||||
|
||||
fn issue2178() {
|
||||
Ok(result
|
||||
.iter()
|
||||
.map(|item| ls_util::rls_to_location(item))
|
||||
.collect())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user