Minor refactoring in compute_budgets_for_args
This commit is contained in:
parent
dad4626517
commit
224eecce50
1 changed files with 12 additions and 17 deletions
17
src/items.rs
17
src/items.rs
|
@ -513,8 +513,6 @@ impl<'a> FmtVisitor<'a> {
|
||||||
ret_str_len: usize,
|
ret_str_len: usize,
|
||||||
newline_brace: bool)
|
newline_brace: bool)
|
||||||
-> (usize, usize, Indent) {
|
-> (usize, usize, Indent) {
|
||||||
let mut budgets = None;
|
|
||||||
|
|
||||||
// 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
|
// 3 = `() `, space is before ret_string
|
||||||
|
@ -535,28 +533,25 @@ impl<'a> FmtVisitor<'a> {
|
||||||
used_space,
|
used_space,
|
||||||
max_space);
|
max_space);
|
||||||
if used_space < max_space {
|
if used_space < max_space {
|
||||||
budgets = Some((one_line_budget,
|
return (one_line_budget,
|
||||||
max_space - used_space,
|
max_space - used_space,
|
||||||
indent + result.len() + 1));
|
indent + result.len() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Didn't work. we must force vertical layout and put args on a newline.
|
// 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 new_indent = indent.block_indent(self.config);
|
||||||
let used_space = new_indent.width() + 2; // account for `(` and `)`
|
let used_space = new_indent.width() + 2; // account for `(` and `)`
|
||||||
let max_space = self.config.ideal_width + self.config.leeway;
|
let max_space = self.config.ideal_width + self.config.leeway;
|
||||||
if used_space > max_space {
|
if used_space <= max_space {
|
||||||
|
(0, max_space - used_space, new_indent)
|
||||||
|
} else {
|
||||||
// Whoops! bankrupt.
|
// Whoops! bankrupt.
|
||||||
// TODO: take evasive action, perhaps kill the indent or something.
|
// TODO: take evasive action, perhaps kill the indent or something.
|
||||||
} else {
|
panic!("in compute_budgets_for_args");
|
||||||
budgets = Some((0, max_space - used_space, new_indent));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
budgets.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn newline_for_brace(&self, where_clause: &ast::WhereClause) -> bool {
|
fn newline_for_brace(&self, where_clause: &ast::WhereClause) -> bool {
|
||||||
match self.config.fn_brace_style {
|
match self.config.fn_brace_style {
|
||||||
BraceStyle::AlwaysNextLine => true,
|
BraceStyle::AlwaysNextLine => true,
|
||||||
|
|
Loading…
Reference in a new issue