refactor: apply heuristic config changes in lib

This commit is contained in:
Caleb Cartwright 2020-02-22 22:07:50 -06:00 committed by Caleb Cartwright
parent ea1611c06e
commit 1bcc1f8df5
8 changed files with 38 additions and 23 deletions

View File

@ -300,7 +300,7 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
// 1 = "]"
shape.sub_width(1)?,
self.span,
context.config.width_heuristics().attr_fn_like_width,
context.config.attr_fn_like_width(),
Some(if has_trailing_comma {
SeparatorTactic::Always
} else {

View File

@ -577,7 +577,7 @@ fn format_last_child(
let one_line_budget = if self.child_count == 1 {
shape.width
} else {
min(shape.width, context.config.width_heuristics().chain_width)
min(shape.width, context.config.chain_width())
}
.saturating_sub(almost_total);

View File

@ -899,22 +899,11 @@ fn rewrite_cond(
|| last_line_offsetted(shape.used_width(), &pat_expr_string));
// Try to format if-else on single line.
if self.allow_single_line
&& context
.config
.width_heuristics()
.single_line_if_else_max_width
> 0
{
if self.allow_single_line && context.config.single_line_if_else_max_width() > 0 {
let trial = self.rewrite_single_line(&pat_expr_string, context, shape.width);
if let Some(cond_str) = trial {
if cond_str.len()
<= context
.config
.width_heuristics()
.single_line_if_else_max_width
{
if cond_str.len() <= context.config.single_line_if_else_max_width() {
return Some((cond_str, 0));
}
}
@ -1246,7 +1235,7 @@ pub(crate) fn rewrite_call(
args.iter(),
shape,
span,
context.config.width_heuristics().fn_call_width,
context.config.fn_call_width(),
choose_separator_tactic(context, span),
)
}
@ -1785,7 +1774,7 @@ pub(crate) fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
items,
shape,
span,
context.config.width_heuristics().fn_call_width,
context.config.fn_call_width(),
force_tactic,
)
} else {

View File

@ -505,8 +505,8 @@ fn format_variant_list(
)
.collect()
};
let mut items: Vec<_> =
itemize_list_with(self.config.width_heuristics().struct_variant_width);
let mut items: Vec<_> = itemize_list_with(self.config.struct_variant_width());
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains('\n'));
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains('\n'));
@ -1479,7 +1479,7 @@ fn format_tuple_struct(
fields.iter(),
shape,
span,
context.config.width_heuristics().fn_call_width,
context.config.fn_call_width(),
None,
)?;
}

View File

@ -863,7 +863,7 @@ pub(crate) fn struct_lit_shape(
};
let shape_width = shape.width.checked_sub(prefix_width + suffix_width);
if let Some(w) = shape_width {
let shape_width = cmp::min(w, context.config.width_heuristics().struct_lit_width);
let shape_width = cmp::min(w, context.config.struct_lit_width());
Some((Some(Shape::legacy(shape_width, shape.indent)), v_shape))
} else {
Some((None, v_shape))

View File

@ -382,7 +382,7 @@ fn rewrite_macro_inner(
arg_vec.iter(),
shape,
mac.span(),
context.config.width_heuristics().fn_call_width,
context.config.fn_call_width(),
if trailing_comma {
Some(SeparatorTactic::Always)
} else {

View File

@ -318,7 +318,7 @@ pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>
span,
lhs,
rhs,
context.config.width_heuristics().array_width,
context.config.array_width(),
force_separator_tactic,
Some(("[", "]")),
)

View File

@ -0,0 +1,26 @@
// rustfmt-max_width: 110
// rustfmt-use_small_heuristics: Max
// rustfmt-hard_tabs: true
// rustfmt-use_field_init_shorthand: true
// rustfmt-overflow_delimited_expr: true
// https://github.com/rust-lang/rustfmt/issues/4049
fn foo() {
{
{
if let Some(MpcEv::PlayDrum(pitch, vel)) =
// self.mpc.handle_input(e, /*btn_ctrl_down,*/ tx_launch_to_daw, state_view)
self.mpc.handle_input(e, &mut MyBorrowedState { tx_launch_to_daw, state_view })
{
println!("bar");
}
if let Some(e) =
// self.note_input.handle_input(e, /*btn_ctrl_down,*/ tx_launch_to_daw, state_view)
self.note_input.handle_input(e, &mut MyBorrowedState { tx_launch_to_daw, state_view })
{
println!("baz");
}
}
}
}