Clarify indent calcs in compute_budget_for_args

This commit is contained in:
Tomasz Dudziak 2015-05-25 21:29:02 +02:00
parent fdd7baeae9
commit 21a0f1b787

View File

@ -136,11 +136,12 @@ impl<'a> FmtVisitor<'a> {
debug!("rewrite_fn: one_line_budget: {}, multi_line_budget: {}, arg_indent: {}",
one_line_budget, multi_line_budget, arg_indent);
// Check if vertical layout was forced by compute_budget_for_args.
if one_line_budget <= 0 {
if config!(fn_args_paren_newline) {
result.push('\n');
result.push_str(&make_indent(arg_indent));
arg_indent = arg_indent + 1;
arg_indent = arg_indent + 1; // extra space for `(`
result.push('(');
} else {
result.push_str("(\n");
@ -378,15 +379,14 @@ impl<'a> FmtVisitor<'a> {
// Didn't work. we must force vertical layout and put args on a newline.
if let None = budgets {
// 6 = new indent + `()`
let used_space = indent + 6;
let new_indent = indent + 4;
let used_space = new_indent + 2; // account for `(` and `)`
let max_space = config!(ideal_width) + config!(leeway);
if used_space > max_space {
// Whoops! bankrupt.
// TODO take evasive action, perhaps kill the indent or something.
} else {
// 5 = new indent + `(`
budgets = Some((0, max_space - used_space, indent + 4));
budgets = Some((0, max_space - used_space, new_indent));
}
}