File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -2327,9 +2327,16 @@ pub fn wrap_args_with_parens(
2327
2327
shape : Shape ,
2328
2328
nested_shape : Shape ,
2329
2329
) -> 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
+ } ;
2330
2337
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 )
2333
2340
{
2334
2341
let mut result = String :: with_capacity ( args_str. len ( ) + 4 ) ;
2335
2342
if context. config . spaces_within_parens_and_brackets ( ) && !args_str. is_empty ( ) {
@@ -2348,8 +2355,10 @@ pub fn wrap_args_with_parens(
2348
2355
let mut result =
2349
2356
String :: with_capacity ( args_str. len ( ) + 2 + indent_str. len ( ) + nested_indent_str. len ( ) ) ;
2350
2357
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
+ }
2353
2362
result. push_str ( & indent_str) ;
2354
2363
result. push_str ( ")" ) ;
2355
2364
result
You can’t perform that action at this time.
0 commit comments