Skip to content

Commit b9db337

Browse files
refactor: apply heuristic config changes in lib
1 parent 69c35a2 commit b9db337

File tree

12 files changed

+17
-28
lines changed

12 files changed

+17
-28
lines changed

rustfmt-core/rustfmt-lib/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Rewrite for ast::MetaItem {
228228
// 1 = "]"
229229
shape.sub_width(1)?,
230230
self.span,
231-
context.config.width_heuristics().attr_fn_like_width,
231+
context.config.attr_fn_like_width(),
232232
Some(if has_trailing_comma {
233233
SeparatorTactic::Always
234234
} else {

rustfmt-core/rustfmt-lib/src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ impl<'a> ChainFormatterShared<'a> {
566566
let one_line_budget = if self.child_count == 1 {
567567
shape.width
568568
} else {
569-
min(shape.width, context.config.width_heuristics().chain_width)
569+
min(shape.width, context.config.chain_width())
570570
}
571571
.saturating_sub(almost_total);
572572

rustfmt-core/rustfmt-lib/src/expr.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,22 +943,11 @@ impl<'a> ControlFlow<'a> {
943943
|| last_line_offsetted(shape.used_width(), &pat_expr_string));
944944

945945
// Try to format if-else on single line.
946-
if self.allow_single_line
947-
&& context
948-
.config
949-
.width_heuristics()
950-
.single_line_if_else_max_width
951-
> 0
952-
{
946+
if self.allow_single_line && context.config.single_line_if_else_max_width() > 0 {
953947
let trial = self.rewrite_single_line(&pat_expr_string, context, shape.width);
954948

955949
if let Some(cond_str) = trial {
956-
if cond_str.len()
957-
<= context
958-
.config
959-
.width_heuristics()
960-
.single_line_if_else_max_width
961-
{
950+
if cond_str.len() <= context.config.single_line_if_else_max_width() {
962951
return Some((cond_str, 0));
963952
}
964953
}
@@ -1297,7 +1286,7 @@ pub(crate) fn rewrite_call(
12971286
args.iter(),
12981287
shape,
12991288
span,
1300-
context.config.width_heuristics().fn_call_width,
1289+
context.config.fn_call_width(),
13011290
choose_separator_tactic(context, span),
13021291
)
13031292
}
@@ -1833,7 +1822,7 @@ pub(crate) fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
18331822
items,
18341823
shape,
18351824
span,
1836-
context.config.width_heuristics().fn_call_width,
1825+
context.config.fn_call_width(),
18371826
force_tactic,
18381827
)
18391828
} else {

rustfmt-core/rustfmt-lib/src/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ impl<'a> FmtVisitor<'a> {
572572
)
573573
.collect()
574574
};
575-
let mut items: Vec<_> =
576-
itemize_list_with(self.config.width_heuristics().struct_variant_width);
575+
let mut items: Vec<_> = itemize_list_with(self.config.struct_variant_width());
576+
577577
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
578578
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains('\n'));
579579
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains('\n'));
@@ -1532,7 +1532,7 @@ fn format_tuple_struct(
15321532
fields.iter(),
15331533
shape,
15341534
span,
1535-
context.config.width_heuristics().fn_call_width,
1535+
context.config.fn_call_width(),
15361536
None,
15371537
)?;
15381538
}

rustfmt-core/rustfmt-lib/src/lists.rs

Lines changed: 1 addition & 1 deletion
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))

rustfmt-core/rustfmt-lib/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn rewrite_macro_inner(
368368
arg_vec.iter(),
369369
shape,
370370
mac.span(),
371-
context.config.width_heuristics().fn_call_width,
371+
context.config.fn_call_width(),
372372
if trailing_comma {
373373
Some(SeparatorTactic::Always)
374374
} else {

rustfmt-core/rustfmt-lib/src/overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>
317317
span,
318318
lhs,
319319
rhs,
320-
context.config.width_heuristics().array_width,
320+
context.config.array_width(),
321321
force_separator_tactic,
322322
Some(("[", "]")),
323323
)

rustfmt-core/rustfmt-lib/tests/source/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-use_small_heuristics: Off
1+
// rustfmt-width_heuristics: Off
22
// Test chain formatting.
33

44
fn main() {

rustfmt-core/rustfmt-lib/tests/source/configs/use_small_heuristics/max.rs renamed to rustfmt-core/rustfmt-lib/tests/source/configs/width_heuristics/max.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-use_small_heuristics: Max
1+
// rustfmt-width_heuristics: Max
22

33
enum Lorem {
44
Ipsum,

rustfmt-core/rustfmt-lib/tests/target/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-use_small_heuristics: Off
1+
// rustfmt-width_heuristics: Off
22
// Test chain formatting.
33

44
fn main() {

rustfmt-core/rustfmt-lib/tests/target/configs/use_small_heuristics/max.rs renamed to rustfmt-core/rustfmt-lib/tests/target/configs/width_heuristics/max.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-use_small_heuristics: Max
1+
// rustfmt-width_heuristics: Max
22

33
enum Lorem {
44
Ipsum,

rustfmt-core/rustfmt-lib/tests/target/issue_4049.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-max_width: 110
2-
// rustfmt-use_small_heuristics: Max
2+
// rustfmt-width_heuristics: Max
33
// rustfmt-hard_tabs: true
44
// rustfmt-use_field_init_shorthand: true
55
// rustfmt-overflow_delimited_expr: true

0 commit comments

Comments
 (0)