Arg/line length bug
This commit is contained in:
parent
4faaa4dab2
commit
daff43f761
4 changed files with 24 additions and 3 deletions
|
@ -68,6 +68,9 @@ impl<'a> FmtVisitor<'a> {
|
||||||
let (one_line_budget, multi_line_budget, arg_indent) =
|
let (one_line_budget, multi_line_budget, arg_indent) =
|
||||||
self.compute_budgets_for_args(&mut result, indent, ret_str.len(), newline_brace);
|
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('(');
|
||||||
result.push_str(&self.rewrite_args(&fd.inputs,
|
result.push_str(&self.rewrite_args(&fd.inputs,
|
||||||
explicit_self,
|
explicit_self,
|
||||||
|
@ -252,8 +255,8 @@ impl<'a> FmtVisitor<'a> {
|
||||||
// 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
|
||||||
let mut used_space = indent + result.len() + 3 + ret_str_len;
|
let mut used_space = indent + result.len() + ret_str_len + 3;
|
||||||
if newline_brace {
|
if !newline_brace {
|
||||||
used_space += 2;
|
used_space += 2;
|
||||||
}
|
}
|
||||||
let one_line_budget = if used_space > MAX_WIDTH {
|
let one_line_budget = if used_space > MAX_WIDTH {
|
||||||
|
@ -262,11 +265,13 @@ impl<'a> FmtVisitor<'a> {
|
||||||
MAX_WIDTH - used_space
|
MAX_WIDTH - used_space
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 2 = `()`
|
||||||
let used_space = indent + result.len() + 2;
|
let used_space = indent + result.len() + 2;
|
||||||
let max_space = IDEAL_WIDTH + LEEWAY;
|
let max_space = IDEAL_WIDTH + LEEWAY;
|
||||||
|
debug!("compute_budgets_for_args: used_space: {}, max_space: {}",
|
||||||
|
used_space, max_space);
|
||||||
if used_space < max_space {
|
if used_space < max_space {
|
||||||
budgets = Some((one_line_budget,
|
budgets = Some((one_line_budget,
|
||||||
// 2 = `()`
|
|
||||||
max_space - used_space,
|
max_space - used_space,
|
||||||
indent + result.len() + 1));
|
indent + result.len() + 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// Check if we need to fallback from horizontal listing, if possible.
|
||||||
if tactic == ListTactic::HorizontalVertical {
|
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 {
|
if total_width + total_sep_len > formatting.h_width {
|
||||||
tactic = ListTactic::Vertical;
|
tactic = ListTactic::Vertical;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -157,6 +157,7 @@ fn fmt_lines(changes: &mut ChangeSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if newline_count > 1 {
|
if newline_count > 1 {
|
||||||
|
debug!("track truncate: {} {} {}", f, text.len, newline_count);
|
||||||
truncate_todo.push((f, text.len - newline_count + 1))
|
truncate_todo.push((f, text.len - newline_count + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
tests/idem/long-fn-1.rs
Normal file
13
tests/idem/long-fn-1.rs
Normal 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>) {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue