@@ -1301,7 +1301,7 @@ fn rewrite_fn_base(context: &RewriteContext,
1301
1301
1302
1302
// Args.
1303
1303
let ( mut one_line_budget, mut multi_line_budget, mut arg_indent) =
1304
- compute_budgets_for_args ( context, & result, indent, ret_str_len, newline_brace) ;
1304
+ try_opt ! ( compute_budgets_for_args( context, & result, indent, ret_str_len, newline_brace) ) ;
1305
1305
1306
1306
if context. config . fn_args_layout == FnArgLayoutStyle :: Block ||
1307
1307
context. config . fn_args_layout == FnArgLayoutStyle :: BlockAlways {
@@ -1617,7 +1617,7 @@ fn compute_budgets_for_args(context: &RewriteContext,
1617
1617
indent : Indent ,
1618
1618
ret_str_len : usize ,
1619
1619
newline_brace : bool )
1620
- -> ( usize , usize , Indent ) {
1620
+ -> Option < ( ( usize , usize , Indent ) ) > {
1621
1621
// Try keeping everything on the same line.
1622
1622
if !result. contains ( "\n " ) {
1623
1623
// 3 = `() `, space is before ret_string.
@@ -1628,23 +1628,23 @@ fn compute_budgets_for_args(context: &RewriteContext,
1628
1628
let one_line_budget = context. config . max_width . checked_sub ( used_space) . unwrap_or ( 0 ) ;
1629
1629
1630
1630
if one_line_budget > 0 {
1631
- let multi_line_budget = context. config . max_width -
1632
- ( indent. width ( ) + result. len ( ) + "()" . len ( ) ) ;
1631
+ // 4 = "() {".len()
1632
+ let multi_line_budget =
1633
+ try_opt ! ( context. config. max_width. checked_sub( indent. width( ) + result. len( ) + 4 ) ) ;
1633
1634
1634
- return ( one_line_budget, multi_line_budget, indent + result. len ( ) + 1 ) ;
1635
+ return Some ( ( one_line_budget, multi_line_budget, indent + result. len ( ) + 1 ) ) ;
1635
1636
}
1636
1637
}
1637
1638
1638
1639
// Didn't work. we must force vertical layout and put args on a newline.
1639
1640
let new_indent = indent. block_indent ( context. config ) ;
1640
- let used_space = new_indent. width ( ) + 2 ; // account for `(` and `)`
1641
+ let used_space = new_indent. width ( ) + 4 ; // Account for `(` and `)` and possibly ` {`.
1641
1642
let max_space = context. config . max_width ;
1642
1643
if used_space <= max_space {
1643
- ( 0 , max_space - used_space, new_indent)
1644
+ Some ( ( 0 , max_space - used_space, new_indent) )
1644
1645
} else {
1645
1646
// Whoops! bankrupt.
1646
- // FIXME: take evasive action, perhaps kill the indent or something.
1647
- panic ! ( "in compute_budgets_for_args" ) ;
1647
+ None
1648
1648
}
1649
1649
}
1650
1650
0 commit comments