Skip to content

Commit cb0097f

Browse files
committed
Use multiple lines for function calls with 0 arg which exceeds max width
e.g. foo( )
1 parent c5a8878 commit cb0097f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rustfmt-core/src/expr.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,9 +2327,16 @@ pub fn wrap_args_with_parens(
23272327
shape: Shape,
23282328
nested_shape: Shape,
23292329
) -> String {
2330+
let paren_overhead = paren_overhead(context);
2331+
let fits_one_line = args_str.len() + paren_overhead <= shape.width;
2332+
let extend_width = if args_str.is_empty() {
2333+
paren_overhead
2334+
} else {
2335+
paren_overhead / 2
2336+
};
23302337
if !context.use_block_indent()
2331-
|| (context.inside_macro && !args_str.contains('\n')
2332-
&& args_str.len() + paren_overhead(context) <= shape.width) || is_extendable
2338+
|| (context.inside_macro && !args_str.contains('\n') && fits_one_line)
2339+
|| (is_extendable && extend_width <= shape.width)
23332340
{
23342341
let mut result = String::with_capacity(args_str.len() + 4);
23352342
if context.config.spaces_within_parens_and_brackets() && !args_str.is_empty() {
@@ -2348,8 +2355,10 @@ pub fn wrap_args_with_parens(
23482355
let mut result =
23492356
String::with_capacity(args_str.len() + 2 + indent_str.len() + nested_indent_str.len());
23502357
result.push_str("(");
2351-
result.push_str(&nested_indent_str);
2352-
result.push_str(args_str);
2358+
if !args_str.is_empty() {
2359+
result.push_str(&nested_indent_str);
2360+
result.push_str(args_str);
2361+
}
23532362
result.push_str(&indent_str);
23542363
result.push_str(")");
23552364
result

0 commit comments

Comments
 (0)