From 224eecce5078b54771906da85788b4b836deea0e Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sun, 27 Sep 2015 19:25:04 +1300 Subject: [PATCH] Minor refactoring in compute_budgets_for_args --- src/items.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/items.rs b/src/items.rs index efd2c852c3e..3cf12b68a82 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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 {