Arg/line length bug

This commit is contained in:
Nick Cameron 2015-04-23 18:30:12 +12:00
parent 4faaa4dab2
commit daff43f761
4 changed files with 24 additions and 3 deletions

View File

@ -68,6 +68,9 @@ impl<'a> FmtVisitor<'a> {
let (one_line_budget, multi_line_budget, arg_indent) =
self.compute_budgets_for_args(&mut result, indent, ret_str.len(), newline_brace);
debug!("rewrite_fn: one_line_budget: {}, multi_line_budget: {}, arg_indent: {}",
one_line_budget, multi_line_budget, arg_indent);
result.push('(');
result.push_str(&self.rewrite_args(&fd.inputs,
explicit_self,
@ -252,8 +255,8 @@ impl<'a> FmtVisitor<'a> {
// Try keeping everything on the same line
if !result.contains("\n") {
// 3 = `() `, space is before ret_string
let mut used_space = indent + result.len() + 3 + ret_str_len;
if newline_brace {
let mut used_space = indent + result.len() + ret_str_len + 3;
if !newline_brace {
used_space += 2;
}
let one_line_budget = if used_space > MAX_WIDTH {
@ -262,11 +265,13 @@ impl<'a> FmtVisitor<'a> {
MAX_WIDTH - used_space
};
// 2 = `()`
let used_space = indent + result.len() + 2;
let max_space = IDEAL_WIDTH + LEEWAY;
debug!("compute_budgets_for_args: used_space: {}, max_space: {}",
used_space, max_space);
if used_space < max_space {
budgets = Some((one_line_budget,
// 2 = `()`
max_space - used_space,
indent + result.len() + 1));
}

View File

@ -63,6 +63,8 @@ pub fn write_list<'b>(items: &[(String, String)], formatting: &ListFormatting<'b
// Check if we need to fallback from horizontal listing, if possible.
if tactic == ListTactic::HorizontalVertical {
debug!("write_list: total_width: {}, total_sep_len: {}, h_width: {}",
total_width, total_sep_len, formatting.h_width);
if total_width + total_sep_len > formatting.h_width {
tactic = ListTactic::Vertical;
} else {

View File

@ -157,6 +157,7 @@ fn fmt_lines(changes: &mut ChangeSet) {
}
if newline_count > 1 {
debug!("track truncate: {} {} {}", f, text.len, newline_count);
truncate_todo.push((f, text.len - newline_count + 1))
}

13
tests/idem/long-fn-1.rs Normal file
View File

@ -0,0 +1,13 @@
// Tests that a function which is almost short enough, but not quite, gets
// formatted correctly.
impl Foo {
fn some_input(&mut self,
input: Input,
input_path: Option<PathBuf>)
-> (Input, Option<PathBuf>) {
}
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {
}
}