Be precise with one_line_budget for fn_base
This commit is contained in:
parent
a7b8dcc60d
commit
10c7934700
1 changed files with 19 additions and 6 deletions
21
src/items.rs
21
src/items.rs
|
@ -1565,7 +1565,12 @@ fn rewrite_fn_base(context: &RewriteContext,
|
||||||
|
|
||||||
// Args.
|
// Args.
|
||||||
let (mut one_line_budget, mut multi_line_budget, mut arg_indent) =
|
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 {
|
if context.config.fn_args_layout() == IndentStyle::Block {
|
||||||
arg_indent = indent.block_indent(context.config);
|
arg_indent = indent.block_indent(context.config);
|
||||||
|
@ -1907,7 +1912,8 @@ fn compute_budgets_for_args(context: &RewriteContext,
|
||||||
result: &str,
|
result: &str,
|
||||||
indent: Indent,
|
indent: Indent,
|
||||||
ret_str_len: usize,
|
ret_str_len: usize,
|
||||||
newline_brace: bool)
|
newline_brace: bool,
|
||||||
|
has_braces: bool)
|
||||||
-> Option<((usize, usize, Indent))> {
|
-> Option<((usize, usize, Indent))> {
|
||||||
debug!("compute_budgets_for_args {} {:?}, {}, {}",
|
debug!("compute_budgets_for_args {} {:?}, {}, {}",
|
||||||
result.len(),
|
result.len(),
|
||||||
|
@ -1916,11 +1922,18 @@ fn compute_budgets_for_args(context: &RewriteContext,
|
||||||
newline_brace);
|
newline_brace);
|
||||||
// Try keeping everything on the same line.
|
// Try keeping everything on the same line.
|
||||||
if !result.contains('\n') {
|
if !result.contains('\n') {
|
||||||
// 3 = `() `, space is before ret_string.
|
// 2 = `()`, 3 = `() `, space is before ret_string.
|
||||||
let mut used_space = indent.width() + result.len() + ret_str_len + 3;
|
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 {
|
if !newline_brace {
|
||||||
|
// 2 = `{}`
|
||||||
used_space += 2;
|
used_space += 2;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 1 = `;`
|
||||||
|
used_space += 1;
|
||||||
|
}
|
||||||
let one_line_budget = context
|
let one_line_budget = context
|
||||||
.config
|
.config
|
||||||
.max_width()
|
.max_width()
|
||||||
|
|
Loading…
Reference in a new issue