diff --git a/src/functions.rs b/src/functions.rs index 32ad65befe7..777120f5b97 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -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)); } diff --git a/src/lists.rs b/src/lists.rs index 5a892e5713b..d5f058a301b 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -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 { diff --git a/src/mod.rs b/src/mod.rs index 71ce9120fe1..c5f5150b3bb 100644 --- a/src/mod.rs +++ b/src/mod.rs @@ -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)) } diff --git a/tests/idem/long-fn-1.rs b/tests/idem/long-fn-1.rs new file mode 100644 index 00000000000..0e299aaecc1 --- /dev/null +++ b/tests/idem/long-fn-1.rs @@ -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) + -> (Input, Option) { + } + + fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) { + } +}