@@ -137,13 +137,27 @@ impl<'a> FmtVisitor<'a> {
137
137
let ret_str = self . rewrite_return ( & fd. output ) ;
138
138
139
139
// Args.
140
- let ( one_line_budget, multi_line_budget, arg_indent) =
141
- self . compute_budgets_for_args ( & mut result, indent, ret_str. len ( ) , newline_brace) ;
140
+ let ( one_line_budget, multi_line_budget, mut arg_indent) =
141
+ self . compute_budgets_for_args ( & result, indent, ret_str. len ( ) , newline_brace) ;
142
142
143
143
debug ! ( "rewrite_fn: one_line_budget: {}, multi_line_budget: {}, arg_indent: {}" ,
144
144
one_line_budget, multi_line_budget, arg_indent) ;
145
145
146
- result. push ( '(' ) ;
146
+ // Check if vertical layout was forced by compute_budget_for_args.
147
+ if one_line_budget <= 0 {
148
+ if config ! ( fn_args_paren_newline) {
149
+ result. push ( '\n' ) ;
150
+ result. push_str ( & make_indent ( arg_indent) ) ;
151
+ arg_indent = arg_indent + 1 ; // extra space for `(`
152
+ result. push ( '(' ) ;
153
+ } else {
154
+ result. push_str ( "(\n " ) ;
155
+ result. push_str ( & make_indent ( arg_indent) ) ;
156
+ }
157
+ } else {
158
+ result. push ( '(' ) ;
159
+ }
160
+
147
161
result. push_str ( & self . rewrite_args ( & fd. inputs ,
148
162
explicit_self,
149
163
one_line_budget,
@@ -337,7 +351,7 @@ impl<'a> FmtVisitor<'a> {
337
351
}
338
352
339
353
fn compute_budgets_for_args ( & self ,
340
- result : & mut String ,
354
+ result : & String ,
341
355
indent : usize ,
342
356
ret_str_len : usize ,
343
357
newline_brace : bool )
@@ -372,17 +386,14 @@ impl<'a> FmtVisitor<'a> {
372
386
373
387
// Didn't work. we must force vertical layout and put args on a newline.
374
388
if let None = budgets {
375
- result. push ( '\n' ) ;
376
- result. push_str ( & make_indent ( indent + 4 ) ) ;
377
- // 6 = new indent + `()`
378
- let used_space = indent + 6 ;
389
+ let new_indent = indent + config ! ( tab_spaces) ;
390
+ let used_space = new_indent + 2 ; // account for `(` and `)`
379
391
let max_space = config ! ( ideal_width) + config ! ( leeway) ;
380
392
if used_space > max_space {
381
393
// Whoops! bankrupt.
382
394
// TODO take evasive action, perhaps kill the indent or something.
383
395
} else {
384
- // 5 = new indent + `(`
385
- budgets = Some ( ( 0 , max_space - used_space, indent + 5 ) ) ;
396
+ budgets = Some ( ( 0 , max_space - used_space, new_indent) ) ;
386
397
}
387
398
}
388
399
0 commit comments