Skip to content

Commit 1bcc1f8

Browse files
refactor: apply heuristic config changes in lib
1 parent ea1611c commit 1bcc1f8

File tree

8 files changed

+38
-23
lines changed

8 files changed

+38
-23
lines changed

Diff for: src/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl Rewrite for ast::MetaItem {
300300
// 1 = "]"
301301
shape.sub_width(1)?,
302302
self.span,
303-
context.config.width_heuristics().attr_fn_like_width,
303+
context.config.attr_fn_like_width(),
304304
Some(if has_trailing_comma {
305305
SeparatorTactic::Always
306306
} else {

Diff for: src/chains.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl<'a> ChainFormatterShared<'a> {
577577
let one_line_budget = if self.child_count == 1 {
578578
shape.width
579579
} else {
580-
min(shape.width, context.config.width_heuristics().chain_width)
580+
min(shape.width, context.config.chain_width())
581581
}
582582
.saturating_sub(almost_total);
583583

Diff for: src/expr.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -899,22 +899,11 @@ impl<'a> ControlFlow<'a> {
899899
|| last_line_offsetted(shape.used_width(), &pat_expr_string));
900900

901901
// Try to format if-else on single line.
902-
if self.allow_single_line
903-
&& context
904-
.config
905-
.width_heuristics()
906-
.single_line_if_else_max_width
907-
> 0
908-
{
902+
if self.allow_single_line && context.config.single_line_if_else_max_width() > 0 {
909903
let trial = self.rewrite_single_line(&pat_expr_string, context, shape.width);
910904

911905
if let Some(cond_str) = trial {
912-
if cond_str.len()
913-
<= context
914-
.config
915-
.width_heuristics()
916-
.single_line_if_else_max_width
917-
{
906+
if cond_str.len() <= context.config.single_line_if_else_max_width() {
918907
return Some((cond_str, 0));
919908
}
920909
}
@@ -1246,7 +1235,7 @@ pub(crate) fn rewrite_call(
12461235
args.iter(),
12471236
shape,
12481237
span,
1249-
context.config.width_heuristics().fn_call_width,
1238+
context.config.fn_call_width(),
12501239
choose_separator_tactic(context, span),
12511240
)
12521241
}
@@ -1785,7 +1774,7 @@ pub(crate) fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
17851774
items,
17861775
shape,
17871776
span,
1788-
context.config.width_heuristics().fn_call_width,
1777+
context.config.fn_call_width(),
17891778
force_tactic,
17901779
)
17911780
} else {

Diff for: src/items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ impl<'a> FmtVisitor<'a> {
505505
)
506506
.collect()
507507
};
508-
let mut items: Vec<_> =
509-
itemize_list_with(self.config.width_heuristics().struct_variant_width);
508+
let mut items: Vec<_> = itemize_list_with(self.config.struct_variant_width());
509+
510510
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
511511
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains('\n'));
512512
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains('\n'));
@@ -1479,7 +1479,7 @@ fn format_tuple_struct(
14791479
fields.iter(),
14801480
shape,
14811481
span,
1482-
context.config.width_heuristics().fn_call_width,
1482+
context.config.fn_call_width(),
14831483
None,
14841484
)?;
14851485
}

Diff for: src/lists.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ pub(crate) fn struct_lit_shape(
863863
};
864864
let shape_width = shape.width.checked_sub(prefix_width + suffix_width);
865865
if let Some(w) = shape_width {
866-
let shape_width = cmp::min(w, context.config.width_heuristics().struct_lit_width);
866+
let shape_width = cmp::min(w, context.config.struct_lit_width());
867867
Some((Some(Shape::legacy(shape_width, shape.indent)), v_shape))
868868
} else {
869869
Some((None, v_shape))

Diff for: src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn rewrite_macro_inner(
382382
arg_vec.iter(),
383383
shape,
384384
mac.span(),
385-
context.config.width_heuristics().fn_call_width,
385+
context.config.fn_call_width(),
386386
if trailing_comma {
387387
Some(SeparatorTactic::Always)
388388
} else {

Diff for: src/overflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>
318318
span,
319319
lhs,
320320
rhs,
321-
context.config.width_heuristics().array_width,
321+
context.config.array_width(),
322322
force_separator_tactic,
323323
Some(("[", "]")),
324324
)

Diff for: tests/target/issue_4049.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// rustfmt-max_width: 110
2+
// rustfmt-use_small_heuristics: Max
3+
// rustfmt-hard_tabs: true
4+
// rustfmt-use_field_init_shorthand: true
5+
// rustfmt-overflow_delimited_expr: true
6+
7+
// https://github.com/rust-lang/rustfmt/issues/4049
8+
fn foo() {
9+
{
10+
{
11+
if let Some(MpcEv::PlayDrum(pitch, vel)) =
12+
// self.mpc.handle_input(e, /*btn_ctrl_down,*/ tx_launch_to_daw, state_view)
13+
self.mpc.handle_input(e, &mut MyBorrowedState { tx_launch_to_daw, state_view })
14+
{
15+
println!("bar");
16+
}
17+
18+
if let Some(e) =
19+
// self.note_input.handle_input(e, /*btn_ctrl_down,*/ tx_launch_to_daw, state_view)
20+
self.note_input.handle_input(e, &mut MyBorrowedState { tx_launch_to_daw, state_view })
21+
{
22+
println!("baz");
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)