Skip to content

Commit f1035d9

Browse files
authored
Merge pull request #2116 from topecongiro/config-options-indent
Rename config options related to indent
2 parents 15894e9 + 9cd5d88 commit f1035d9

File tree

69 files changed

+116
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+116
-116
lines changed

Configurations.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Rustfmt is designed to be very configurable. You can create a TOML file called `
55
A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
66

77
```toml
8-
array_layout = "Block"
8+
array_indent = "Block"
99
array_width = 80
1010
reorder_imported_names = true
1111
```
@@ -22,7 +22,7 @@ Use this option to prevent a huge array from being vertically formatted.
2222
- **Default value**: `0`
2323
- **Possible values**: any positive integer
2424

25-
**Note:** A value of `0` results in [`array_layout`](#array_layout) being applied regardless of a line's width.
25+
**Note:** A value of `0` results in [`array_indent`](#array_indent) being applied regardless of a line's width.
2626

2727
#### `0` (default):
2828

@@ -50,7 +50,7 @@ let a = vec![
5050
];
5151
```
5252

53-
## `array_layout`
53+
## `array_indent`
5454

5555
Indent on arrays
5656

@@ -90,15 +90,15 @@ Maximum width of an array literal before falling back to vertical formatting
9090
- **Default value**: `60`
9191
- **Possible values**: any positive integer
9292

93-
**Note:** A value of `0` results in [`array_layout`](#array_layout) being applied regardless of a line's width.
93+
**Note:** A value of `0` results in [`array_indent`](#array_indent) being applied regardless of a line's width.
9494

9595
#### Lines shorter than `array_width`:
9696
```rust
9797
let lorem = vec!["ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"];
9898
```
9999

100100
#### Lines longer than `array_width`:
101-
See [`array_layout`](#array_layout).
101+
See [`array_indent`](#array_indent).
102102

103103
## `attributes_on_same_line_as_field`
104104

@@ -298,7 +298,7 @@ lorem_ipsum(|| {
298298
});
299299
```
300300

301-
**Note**: This option only takes effect when `fn_call_style` is set to `"Visual"`.
301+
**Note**: This option only takes effect when `fn_call_indent` is set to `"Visual"`.
302302

303303
## `combine_control_expr`
304304

@@ -614,7 +614,7 @@ trait Lorem {
614614
}
615615
```
616616

617-
## `fn_args_layout`
617+
## `fn_args_indent`
618618

619619
Layout of function arguments and tuple structs
620620

@@ -758,7 +758,7 @@ where
758758
}
759759
```
760760

761-
## `fn_call_style`
761+
## `fn_call_indent`
762762

763763
Indentation for function calls, etc.
764764

@@ -809,7 +809,7 @@ lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "el
809809

810810
#### Function call longer than `fn_call_width`:
811811

812-
See [`fn_call_style`](#fn_call_style).
812+
See [`fn_call_indent`](#fn_call_indent).
813813

814814
## `fn_empty_single_line`
815815

@@ -874,7 +874,7 @@ fn lorem(ipsum: Ipsum,
874874

875875
```
876876

877-
**Note**: This option only takes effect when `fn_call_style` is set to `"Visual"`.
877+
**Note**: This option only takes effect when `fn_call_indent` is set to `"Visual"`.
878878

879879
## `fn_single_line`
880880

@@ -1868,9 +1868,9 @@ let lorem = Lorem {
18681868
};
18691869
```
18701870

1871-
See also: [`struct_lit_style`](#struct_lit_style), [`struct_lit_width`](#struct_lit_width).
1871+
See also: [`struct_lit_indent`](#struct_lit_indent), [`struct_lit_width`](#struct_lit_width).
18721872

1873-
## `struct_lit_style`
1873+
## `struct_lit_indent`
18741874

18751875
Style of struct definition
18761876

@@ -1893,7 +1893,7 @@ let lorem = Lorem { ipsum: dolor,
18931893
sit: amet, };
18941894
```
18951895

1896-
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
1896+
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_indent`](#struct_lit_indent).
18971897

18981898
## `struct_lit_width`
18991899

@@ -1910,9 +1910,9 @@ let lorem = Lorem { ipsum: dolor, sit: amet };
19101910
```
19111911

19121912
#### Lines longer than `struct_lit_width`:
1913-
See [`struct_lit_style`](#struct_lit_style).
1913+
See [`struct_lit_indent`](#struct_lit_indent).
19141914

1915-
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
1915+
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_indent`](#struct_lit_indent).
19161916

19171917
## `struct_variant_width`
19181918

legacy-rustfmt.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
fn_args_layout = "Visual"
2-
array_layout = "Visual"
1+
fn_args_indent = "Visual"
2+
array_indent = "Visual"
33
control_style = "Legacy"
44
where_style = "Legacy"
55
generics_indent = "Visual"
6-
fn_call_style = "Visual"
6+
fn_call_indent = "Visual"
77
combine_control_expr = false
88
fn_args_paren_newline = true

src/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ create_config! {
559559
"Location of return type in function declaration";
560560
fn_args_paren_newline: bool, false, false, "If function argument parenthesis goes on a newline";
561561
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
562-
fn_args_layout: IndentStyle, IndentStyle::Block, false,
562+
fn_args_indent: IndentStyle, IndentStyle::Block, false,
563563
"Layout of function arguments and tuple structs";
564-
array_layout: IndentStyle, IndentStyle::Block, false, "Indent on arrays";
564+
array_indent: IndentStyle, IndentStyle::Block, false, "Indent on arrays";
565565
array_width: usize, 60, false,
566566
"Maximum width of an array literal before falling back to vertical formatting";
567567
array_horizontal_layout_threshold: usize, 0, false,
@@ -578,10 +578,10 @@ create_config! {
578578
where_pred_indent: IndentStyle, IndentStyle::Visual, false,
579579
"Indentation style of a where predicate";
580580
generics_indent: IndentStyle, IndentStyle::Block, false, "Indentation of generics";
581-
struct_lit_style: IndentStyle, IndentStyle::Block, false, "Style of struct definition";
581+
struct_lit_indent: IndentStyle, IndentStyle::Block, false, "Style of struct definition";
582582
struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle, false,
583583
"Multiline style on literal structs";
584-
fn_call_style: IndentStyle, IndentStyle::Block, false, "Indentation for function calls, etc.";
584+
fn_call_indent: IndentStyle, IndentStyle::Block, false, "Indentation for function calls, etc.";
585585
report_todo: ReportTactic, ReportTactic::Never, false,
586586
"Report all, none or unnumbered occurrences of TODO in source file comments";
587587
report_fixme: ReportTactic, ReportTactic::Never, false,

src/expr.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ where
419419
1 // "["
420420
};
421421

422-
let nested_shape = match context.config.array_layout() {
422+
let nested_shape = match context.config.array_indent() {
423423
IndentStyle::Block => shape
424424
.block()
425425
.block_indent(context.config.tab_spaces())
@@ -454,7 +454,7 @@ where
454454
.iter()
455455
.any(|li| li.item.as_ref().map(|s| s.len() > 10).unwrap_or(false));
456456

457-
let mut tactic = match context.config.array_layout() {
457+
let mut tactic = match context.config.array_indent() {
458458
IndentStyle::Block => {
459459
// FIXME wrong shape in one-line case
460460
match shape.width.checked_sub(2 * bracket_size) {
@@ -477,7 +477,7 @@ where
477477
DefinitiveListTactic::Mixed
478478
},
479479
};
480-
let ends_with_newline = tactic.ends_with_newline(context.config.array_layout());
480+
let ends_with_newline = tactic.ends_with_newline(context.config.array_indent());
481481
if context.config.array_horizontal_layout_threshold() > 0
482482
&& items.len() > context.config.array_horizontal_layout_threshold()
483483
{
@@ -489,7 +489,7 @@ where
489489
separator: ",",
490490
trailing_separator: if trailing_comma {
491491
SeparatorTactic::Always
492-
} else if context.inside_macro || context.config.array_layout() == IndentStyle::Visual {
492+
} else if context.inside_macro || context.config.array_indent() == IndentStyle::Visual {
493493
SeparatorTactic::Never
494494
} else {
495495
SeparatorTactic::Vertical
@@ -502,7 +502,7 @@ where
502502
};
503503
let list_str = write_list(&items, &fmt)?;
504504

505-
let result = if context.config.array_layout() == IndentStyle::Visual
505+
let result = if context.config.array_indent() == IndentStyle::Visual
506506
|| tactic == DefinitiveListTactic::Horizontal
507507
{
508508
if context.config.spaces_within_square_brackets() && !list_str.is_empty() {
@@ -2033,7 +2033,7 @@ where
20332033
let used_width = extra_offset(callee_str, shape);
20342034
let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;
20352035

2036-
let nested_shape = shape_from_fn_call_style(
2036+
let nested_shape = shape_from_fn_call_indent(
20372037
context,
20382038
shape,
20392039
used_width + 2 * paren_overhead,
@@ -2379,7 +2379,7 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l
23792379
match expr.node {
23802380
ast::ExprKind::Match(..) => {
23812381
(context.use_block_indent() && args_len == 1)
2382-
|| (context.config.fn_call_style() == IndentStyle::Visual && args_len > 1)
2382+
|| (context.config.fn_call_indent() == IndentStyle::Visual && args_len > 1)
23832383
}
23842384
ast::ExprKind::If(..) |
23852385
ast::ExprKind::IfLet(..) |
@@ -2391,7 +2391,7 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l
23912391
}
23922392
ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => {
23932393
context.use_block_indent()
2394-
|| context.config.fn_call_style() == IndentStyle::Visual && args_len > 1
2394+
|| context.config.fn_call_indent() == IndentStyle::Visual && args_len > 1
23952395
}
23962396
ast::ExprKind::Array(..) |
23972397
ast::ExprKind::Call(..) |
@@ -2640,7 +2640,7 @@ fn rewrite_struct_lit<'a>(
26402640
let fields_str = wrap_struct_field(context, &fields_str, shape, v_shape, one_line_width);
26412641
Some(format!("{} {{{}}}", path_str, fields_str))
26422642

2643-
// FIXME if context.config.struct_lit_style() == Visual, but we run out
2643+
// FIXME if context.config.struct_lit_indent() == Visual, but we run out
26442644
// of space, we should fall back to BlockIndent.
26452645
}
26462646

@@ -2651,7 +2651,7 @@ pub fn wrap_struct_field(
26512651
nested_shape: Shape,
26522652
one_line_width: usize,
26532653
) -> String {
2654-
if context.config.struct_lit_style() == IndentStyle::Block
2654+
if context.config.struct_lit_indent() == IndentStyle::Block
26552655
&& (fields_str.contains('\n')
26562656
|| context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti
26572657
|| fields_str.len() > one_line_width)
@@ -2722,7 +2722,7 @@ pub fn rewrite_field(
27222722
}
27232723
}
27242724

2725-
fn shape_from_fn_call_style(
2725+
fn shape_from_fn_call_indent(
27262726
context: &RewriteContext,
27272727
shape: Shape,
27282728
overhead: usize,

src/items.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
933933
let has_body = !trait_items.is_empty();
934934

935935
let where_density = if (context.config.where_density() == Density::Compressed
936-
&& (!result.contains('\n') || context.config.fn_args_layout() == IndentStyle::Block))
937-
|| (context.config.fn_args_layout() == IndentStyle::Block && result.is_empty())
936+
&& (!result.contains('\n') || context.config.fn_args_indent() == IndentStyle::Block))
937+
|| (context.config.fn_args_indent() == IndentStyle::Block && result.is_empty())
938938
|| (context.config.where_density() == Density::CompressedIfEmpty && !has_body
939939
&& !result.contains('\n'))
940940
{
@@ -1770,13 +1770,13 @@ fn rewrite_fn_base(
17701770
} else if context.config.fn_args_paren_newline() {
17711771
result.push('\n');
17721772
result.push_str(&arg_indent.to_string(context.config));
1773-
if context.config.fn_args_layout() == IndentStyle::Visual {
1773+
if context.config.fn_args_indent() == IndentStyle::Visual {
17741774
arg_indent = arg_indent + 1; // extra space for `(`
17751775
}
17761776
result.push('(');
17771777
} else {
17781778
result.push_str("(");
1779-
if context.config.fn_args_layout() == IndentStyle::Visual {
1779+
if context.config.fn_args_indent() == IndentStyle::Visual {
17801780
result.push('\n');
17811781
result.push_str(&arg_indent.to_string(context.config));
17821782
}
@@ -1823,7 +1823,7 @@ fn rewrite_fn_base(
18231823
generics_str.contains('\n'),
18241824
)?;
18251825

1826-
let put_args_in_block = match context.config.fn_args_layout() {
1826+
let put_args_in_block = match context.config.fn_args_indent() {
18271827
IndentStyle::Block => arg_str.contains('\n') || arg_str.len() > one_line_budget,
18281828
_ => false,
18291829
} && !fd.inputs.is_empty();
@@ -1864,7 +1864,7 @@ fn rewrite_fn_base(
18641864

18651865
// Return type.
18661866
if let ast::FunctionRetTy::Ty(..) = fd.output {
1867-
let ret_should_indent = match context.config.fn_args_layout() {
1867+
let ret_should_indent = match context.config.fn_args_indent() {
18681868
// If our args are block layout then we surely must have space.
18691869
IndentStyle::Block if put_args_in_block || fd.inputs.is_empty() => false,
18701870
_ if args_last_line_contains_comment => false,
@@ -2149,7 +2149,7 @@ fn rewrite_args(
21492149
.and_then(|item| item.post_comment.as_ref())
21502150
.map_or(false, |s| s.trim().starts_with("//"));
21512151

2152-
let (indent, trailing_comma) = match context.config.fn_args_layout() {
2152+
let (indent, trailing_comma) = match context.config.fn_args_indent() {
21532153
IndentStyle::Block if fits_in_one_line => {
21542154
(indent.block_indent(context.config), SeparatorTactic::Never)
21552155
}
@@ -2186,7 +2186,7 @@ fn rewrite_args(
21862186
},
21872187
separator_place: SeparatorPlace::Back,
21882188
shape: Shape::legacy(budget, indent),
2189-
ends_with_newline: tactic.ends_with_newline(context.config.fn_args_layout()),
2189+
ends_with_newline: tactic.ends_with_newline(context.config.fn_args_indent()),
21902190
preserve_newline: true,
21912191
config: context.config,
21922192
};
@@ -2236,7 +2236,7 @@ fn compute_budgets_for_args(
22362236

22372237
if one_line_budget > 0 {
22382238
// 4 = "() {".len()
2239-
let (indent, multi_line_budget) = match context.config.fn_args_layout() {
2239+
let (indent, multi_line_budget) = match context.config.fn_args_indent() {
22402240
IndentStyle::Block => {
22412241
let indent = indent.block_indent(context.config);
22422242
(indent, context.budget(indent.width() + 1))
@@ -2254,7 +2254,7 @@ fn compute_budgets_for_args(
22542254

22552255
// Didn't work. we must force vertical layout and put args on a newline.
22562256
let new_indent = indent.block_indent(context.config);
2257-
let used_space = match context.config.fn_args_layout() {
2257+
let used_space = match context.config.fn_args_indent() {
22582258
// 1 = `,`
22592259
IndentStyle::Block => new_indent.width() + 1,
22602260
// Account for `)` and possibly ` {`.

src/lists.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ pub fn struct_lit_shape(
737737
prefix_width: usize,
738738
suffix_width: usize,
739739
) -> Option<(Option<Shape>, Shape)> {
740-
let v_shape = match context.config.struct_lit_style() {
740+
let v_shape = match context.config.struct_lit_indent() {
741741
IndentStyle::Visual => shape
742742
.visual_indent(0)
743743
.shrink_left(prefix_width)?
@@ -766,7 +766,7 @@ pub fn struct_lit_tactic(
766766
items: &[ListItem],
767767
) -> DefinitiveListTactic {
768768
if let Some(h_shape) = h_shape {
769-
let prelim_tactic = match (context.config.struct_lit_style(), items.len()) {
769+
let prelim_tactic = match (context.config.struct_lit_indent(), items.len()) {
770770
(IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
771771
_ => context.config.struct_lit_multiline_style().to_list_tactic(),
772772
};
@@ -797,7 +797,7 @@ pub fn struct_lit_formatting<'a>(
797797
context: &'a RewriteContext,
798798
force_no_trailing_comma: bool,
799799
) -> ListFormatting<'a> {
800-
let ends_with_newline = context.config.struct_lit_style() != IndentStyle::Visual
800+
let ends_with_newline = context.config.struct_lit_indent() != IndentStyle::Visual
801801
&& tactic == DefinitiveListTactic::Vertical;
802802
ListFormatting {
803803
tactic: tactic,

src/rewrite.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a> RewriteContext<'a> {
4343

4444
/// Return true if we should use block indent style for rewriting function call.
4545
pub fn use_block_indent(&self) -> bool {
46-
self.config.fn_call_style() == IndentStyle::Block || self.use_block
46+
self.config.fn_call_indent() == IndentStyle::Block || self.use_block
4747
}
4848

4949
pub fn budget(&self, used_width: usize) -> usize {

0 commit comments

Comments
 (0)