Be precise with one_line_budget for fn_base

This commit is contained in:
Seiichi Uchida 2017-05-25 22:55:11 +09:00
parent a7b8dcc60d
commit 10c7934700

View File

@ -1565,7 +1565,12 @@ fn rewrite_fn_base(context: &RewriteContext,
// Args.
let (mut one_line_budget, mut multi_line_budget, mut arg_indent) =
try_opt!(compute_budgets_for_args(context, &result, indent, ret_str_len, newline_brace));
try_opt!(compute_budgets_for_args(context,
&result,
indent,
ret_str_len,
newline_brace,
has_braces));
if context.config.fn_args_layout() == IndentStyle::Block {
arg_indent = indent.block_indent(context.config);
@ -1907,7 +1912,8 @@ fn compute_budgets_for_args(context: &RewriteContext,
result: &str,
indent: Indent,
ret_str_len: usize,
newline_brace: bool)
newline_brace: bool,
has_braces: bool)
-> Option<((usize, usize, Indent))> {
debug!("compute_budgets_for_args {} {:?}, {}, {}",
result.len(),
@ -1916,10 +1922,17 @@ fn compute_budgets_for_args(context: &RewriteContext,
newline_brace);
// Try keeping everything on the same line.
if !result.contains('\n') {
// 3 = `() `, space is before ret_string.
let mut used_space = indent.width() + result.len() + ret_str_len + 3;
if !newline_brace {
used_space += 2;
// 2 = `()`, 3 = `() `, space is before ret_string.
let overhead = if ret_str_len == 0 { 2 } else { 3 };
let mut used_space = indent.width() + result.len() + ret_str_len + overhead;
if has_braces {
if !newline_brace {
// 2 = `{}`
used_space += 2;
}
} else {
// 1 = `;`
used_space += 1;
}
let one_line_budget = context
.config