Skip to content

Commit b7bfb37

Browse files
refactor: apply heuristic config changes in lib
1 parent d0a741f commit b7bfb37

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
@@ -231,7 +231,7 @@ impl Rewrite for ast::MetaItem {
231231
// 1 = "]"
232232
shape.sub_width(1)?,
233233
self.span,
234-
context.config.width_heuristics().attr_fn_like_width,
234+
context.config.attr_fn_like_width(),
235235
Some(if has_trailing_comma {
236236
SeparatorTactic::Always
237237
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'a> ChainFormatterShared<'a> {
558558
let one_line_budget = if self.child_count == 1 {
559559
shape.width
560560
} else {
561-
min(shape.width, context.config.width_heuristics().chain_width)
561+
min(shape.width, context.config.chain_width())
562562
}
563563
.saturating_sub(almost_total);
564564

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
}
@@ -1295,7 +1284,7 @@ pub(crate) fn rewrite_call(
12951284
args.iter(),
12961285
shape,
12971286
span,
1298-
context.config.width_heuristics().fn_call_width,
1287+
context.config.fn_call_width(),
12991288
choose_separator_tactic(context, span),
13001289
)
13011290
}
@@ -1831,7 +1820,7 @@ pub(crate) fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
18311820
items,
18321821
shape,
18331822
span,
1834-
context.config.width_heuristics().fn_call_width,
1823+
context.config.fn_call_width(),
18351824
force_tactic,
18361825
)
18371826
} else {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ impl<'a> FmtVisitor<'a> {
566566
)
567567
.collect()
568568
};
569-
let mut items: Vec<_> =
570-
itemize_list_with(self.config.width_heuristics().struct_variant_width);
569+
let mut items: Vec<_> = itemize_list_with(self.config.struct_variant_width());
570+
571571
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
572572
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains('\n'));
573573
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains('\n'));
@@ -1527,7 +1527,7 @@ fn format_tuple_struct(
15271527
fields.iter(),
15281528
shape,
15291529
span,
1530-
context.config.width_heuristics().fn_call_width,
1530+
context.config.fn_call_width(),
15311531
None,
15321532
)?;
15331533
}

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)