Make definitive_tactic more generic with separator length
This commit is contained in:
parent
74f5a515ef
commit
570a3505b9
14
src/expr.rs
14
src/expr.rs
@ -485,7 +485,7 @@ pub fn rewrite_array<'a, I>(
|
||||
Some(width) => {
|
||||
let tactic =
|
||||
ListTactic::LimitedHorizontalVertical(context.config.array_width());
|
||||
definitive_tactic(&items, tactic, width)
|
||||
definitive_tactic(&items, tactic, 2, width)
|
||||
}
|
||||
None => DefinitiveListTactic::Vertical,
|
||||
}
|
||||
@ -494,6 +494,7 @@ pub fn rewrite_array<'a, I>(
|
||||
definitive_tactic(
|
||||
&items,
|
||||
ListTactic::LimitedHorizontalVertical(context.config.array_width()),
|
||||
2,
|
||||
nested_shape.width,
|
||||
)
|
||||
} else {
|
||||
@ -591,7 +592,12 @@ fn rewrite_closure_fn_decl(
|
||||
.width
|
||||
.checked_sub(ret_str.len() + 1)
|
||||
.unwrap_or(0);
|
||||
let tactic = definitive_tactic(&item_vec, ListTactic::HorizontalVertical, horizontal_budget);
|
||||
let tactic = definitive_tactic(
|
||||
&item_vec,
|
||||
ListTactic::HorizontalVertical,
|
||||
2,
|
||||
horizontal_budget,
|
||||
);
|
||||
let arg_shape = match tactic {
|
||||
DefinitiveListTactic::Horizontal => try_opt!(arg_shape.sub_width(ret_str.len() + 1)),
|
||||
_ => arg_shape,
|
||||
@ -1668,7 +1674,7 @@ fn rewrite_match_pattern(
|
||||
);
|
||||
|
||||
let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect();
|
||||
let tactic = definitive_tactic(&items, ListTactic::HorizontalVertical, pat_shape.width);
|
||||
let tactic = definitive_tactic(&items, ListTactic::HorizontalVertical, 3, pat_shape.width);
|
||||
let fmt = ListFormatting {
|
||||
tactic: tactic,
|
||||
separator: " |",
|
||||
@ -2216,6 +2222,7 @@ fn try_overflow_last_arg<'a, T>(
|
||||
let tactic = definitive_tactic(
|
||||
&*item_vec,
|
||||
ListTactic::LimitedHorizontalVertical(args_max_width),
|
||||
2,
|
||||
one_line_width,
|
||||
);
|
||||
|
||||
@ -2756,6 +2763,7 @@ fn rewrite_tuple_in_visual_indent_style<'a, T>(
|
||||
let tactic = definitive_tactic(
|
||||
&item_vec,
|
||||
ListTactic::HorizontalVertical,
|
||||
2,
|
||||
nested_shape.width,
|
||||
);
|
||||
let fmt = ListFormatting {
|
||||
|
@ -451,6 +451,7 @@ fn rewrite_use_list(
|
||||
let tactic = definitive_tactic(
|
||||
&items[first_index..],
|
||||
context.config.imports_layout(),
|
||||
2,
|
||||
remaining_width,
|
||||
);
|
||||
|
||||
|
10
src/items.rs
10
src/items.rs
@ -2241,6 +2241,7 @@ enum ArgumentKind<'a> {
|
||||
let tactic = definitive_tactic(
|
||||
&arg_items,
|
||||
context.config.fn_args_density().to_list_tactic(),
|
||||
2,
|
||||
one_line_budget,
|
||||
);
|
||||
let budget = match tactic {
|
||||
@ -2423,7 +2424,12 @@ pub fn format_generics_item_list<I>(
|
||||
{
|
||||
let item_vec = items.collect::<Vec<_>>();
|
||||
|
||||
let tactic = definitive_tactic(&item_vec, ListTactic::HorizontalVertical, one_line_budget);
|
||||
let tactic = definitive_tactic(
|
||||
&item_vec,
|
||||
ListTactic::HorizontalVertical,
|
||||
2,
|
||||
one_line_budget,
|
||||
);
|
||||
let fmt = ListFormatting {
|
||||
tactic: tactic,
|
||||
separator: ",",
|
||||
@ -2636,7 +2642,7 @@ fn rewrite_where_clause(
|
||||
let item_vec = items.collect::<Vec<_>>();
|
||||
// FIXME: we don't need to collect here if the where_layout isn't
|
||||
// HorizontalVertical.
|
||||
let tactic = definitive_tactic(&item_vec, context.config.where_layout(), budget);
|
||||
let tactic = definitive_tactic(&item_vec, context.config.where_layout(), 2, budget);
|
||||
|
||||
let mut comma_tactic = context.config.trailing_comma();
|
||||
// Kind of a hack because we don't usually have trailing commas in where clauses.
|
||||
|
10
src/lists.rs
10
src/lists.rs
@ -135,7 +135,12 @@ pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn definitive_tactic<I, T>(items: I, tactic: ListTactic, width: usize) -> DefinitiveListTactic
|
||||
pub fn definitive_tactic<I, T>(
|
||||
items: I,
|
||||
tactic: ListTactic,
|
||||
sep_len: usize,
|
||||
width: usize,
|
||||
) -> DefinitiveListTactic
|
||||
where
|
||||
I: IntoIterator<Item = T> + Clone,
|
||||
T: AsRef<ListItem>,
|
||||
@ -155,7 +160,6 @@ pub fn definitive_tactic<I, T>(items: I, tactic: ListTactic, width: usize) -> De
|
||||
};
|
||||
|
||||
let (sep_count, total_width) = calculate_width(items.clone());
|
||||
let sep_len = ", ".len(); // FIXME: make more generic?
|
||||
let total_sep_len = sep_len * sep_count.checked_sub(1).unwrap_or(0);
|
||||
let real_total = total_width + total_sep_len;
|
||||
|
||||
@ -640,7 +644,7 @@ pub fn struct_lit_tactic(
|
||||
(IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
|
||||
_ => context.config.struct_lit_multiline_style().to_list_tactic(),
|
||||
};
|
||||
definitive_tactic(items, prelim_tactic, h_shape.width)
|
||||
definitive_tactic(items, prelim_tactic, 2, h_shape.width)
|
||||
} else {
|
||||
DefinitiveListTactic::Vertical
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ enum ArgumentKind<T>
|
||||
|
||||
let item_vec: Vec<_> = items.collect();
|
||||
|
||||
let tactic = definitive_tactic(&*item_vec, ListTactic::HorizontalVertical, budget);
|
||||
let tactic = definitive_tactic(&*item_vec, ListTactic::HorizontalVertical, 2, budget);
|
||||
|
||||
let fmt = ListFormatting {
|
||||
tactic: tactic,
|
||||
|
@ -221,7 +221,7 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
|
||||
span.hi,
|
||||
).collect::<Vec<_>>();
|
||||
|
||||
let tactic = definitive_tactic(&items, ListTactic::HorizontalVertical, one_line_width);
|
||||
let tactic = definitive_tactic(&items, ListTactic::HorizontalVertical, 2, one_line_width);
|
||||
|
||||
let fmt = ListFormatting {
|
||||
tactic: tactic,
|
||||
|
Loading…
Reference in New Issue
Block a user