Minor refactoring in compute_budgets_for_args

This commit is contained in:
Nick Cameron 2015-09-27 19:25:04 +13:00
parent dad4626517
commit 224eecce50

View file

@ -513,8 +513,6 @@ impl<'a> FmtVisitor<'a> {
ret_str_len: usize,
newline_brace: bool)
-> (usize, usize, Indent) {
let mut budgets = None;
// Try keeping everything on the same line
if !result.contains("\n") {
// 3 = `() `, space is before ret_string
@ -535,26 +533,23 @@ impl<'a> FmtVisitor<'a> {
used_space,
max_space);
if used_space < max_space {
budgets = Some((one_line_budget,
max_space - used_space,
indent + result.len() + 1));
return (one_line_budget,
max_space - used_space,
indent + result.len() + 1);
}
}
// Didn't work. we must force vertical layout and put args on a newline.
if let None = budgets {
let new_indent = indent.block_indent(self.config);
let used_space = new_indent.width() + 2; // account for `(` and `)`
let max_space = self.config.ideal_width + self.config.leeway;
if used_space > max_space {
// Whoops! bankrupt.
// TODO: take evasive action, perhaps kill the indent or something.
} else {
budgets = Some((0, max_space - used_space, new_indent));
}
let new_indent = indent.block_indent(self.config);
let used_space = new_indent.width() + 2; // account for `(` and `)`
let max_space = self.config.ideal_width + self.config.leeway;
if used_space <= max_space {
(0, max_space - used_space, new_indent)
} else {
// Whoops! bankrupt.
// TODO: take evasive action, perhaps kill the indent or something.
panic!("in compute_budgets_for_args");
}
budgets.unwrap()
}
fn newline_for_brace(&self, where_clause: &ast::WhereClause) -> bool {