Skip to content

Commit 45d4f7a

Browse files
committed
struct_lit_multiline_style -> struct_lit_single_line (and make it a bool)
1 parent 20805ac commit 45d4f7a

12 files changed

+22
-38
lines changed

Configurations.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ let lorem = Lorem { ipsum: dolor,
246246
sit: amet, };
247247
```
248248

249-
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`indent_style`](#indent_style).
249+
See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
250250

251251
### Where predicates
252252

@@ -1746,20 +1746,20 @@ let lorem: [ usize; 2 ] = [ ipsum, dolor ];
17461746

17471747
See also: [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets), [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets).
17481748

1749-
## `struct_lit_multiline_style`
1749+
## `struct_lit_single_line`
17501750

1751-
Multiline style on literal structs
1751+
Put small struct literals on a single line
17521752

1753-
- **Default value**: `"PreferSingle"`
1754-
- **Possible values**: `"ForceMulti"`, `"PreferSingle"`
1753+
- **Default value**: `true`
1754+
- **Possible values**: `true`, `false`
17551755

1756-
#### `"PreferSingle"` (default):
1756+
#### `true` (default):
17571757

17581758
```rust
17591759
let lorem = Lorem { ipsum: dolor, sit: amet };
17601760
```
17611761

1762-
#### `"ForceMulti"`:
1762+
#### `false`:
17631763

17641764
```rust
17651765
let lorem = Lorem {
@@ -1787,7 +1787,7 @@ let lorem = Lorem { ipsum: dolor, sit: amet };
17871787
#### Lines longer than `struct_lit_width`:
17881788
See [`indent_style`](#indent_style).
17891789

1790-
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`indent_style`](#indent_style).
1790+
See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
17911791

17921792
## `struct_variant_width`
17931793

src/config.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,6 @@ impl Density {
100100
}
101101
}
102102

103-
configuration_option_enum! { MultilineStyle:
104-
// Use horizontal layout if it fits in one line, fall back to vertical
105-
PreferSingle,
106-
// Use vertical layout
107-
ForceMulti,
108-
}
109-
110-
impl MultilineStyle {
111-
pub fn to_list_tactic(self) -> ListTactic {
112-
match self {
113-
MultilineStyle::PreferSingle => ListTactic::HorizontalVertical,
114-
MultilineStyle::ForceMulti => ListTactic::Vertical,
115-
}
116-
}
117-
}
118-
119103
configuration_option_enum! { ReportTactic:
120104
Always,
121105
Unnumbered,
@@ -563,8 +547,8 @@ create_config! {
563547
where_density: Density, Density::Vertical, false, "Density of a where clause";
564548
where_single_line: bool, false, false, "To force single line where layout";
565549
where_layout: ListTactic, ListTactic::Vertical, false, "Element layout inside a where clause";
566-
struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle, false,
567-
"Multiline style on literal structs";
550+
struct_lit_single_line: bool, true, false,
551+
"Put small struct literals on a single line";
568552
report_todo: ReportTactic, ReportTactic::Never, false,
569553
"Report all, none or unnumbered occurrences of TODO in source file comments";
570554
report_fixme: ReportTactic, ReportTactic::Never, false,

src/expr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use closures;
2121
use codemap::{LineRangeUtils, SpanUtils};
2222
use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
2323
rewrite_comment, rewrite_missing_comment, FindUncommented};
24-
use config::{Config, ControlBraceStyle, IndentStyle, MultilineStyle};
24+
use config::{Config, ControlBraceStyle, IndentStyle};
2525
use lists::{definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting,
2626
struct_lit_shape, struct_lit_tactic, write_list, DefinitiveListTactic, ListFormatting,
2727
ListItem, ListTactic, Separator, SeparatorPlace, SeparatorTactic};
@@ -2346,8 +2346,7 @@ pub fn wrap_struct_field(
23462346
one_line_width: usize,
23472347
) -> String {
23482348
if context.config.indent_style() == IndentStyle::Block
2349-
&& (fields_str.contains('\n')
2350-
|| context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti
2349+
&& (fields_str.contains('\n') || !context.config.struct_lit_single_line()
23512350
|| fields_str.len() > one_line_width)
23522351
{
23532352
format!(

src/lists.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,8 @@ pub fn struct_lit_tactic(
796796
if let Some(h_shape) = h_shape {
797797
let prelim_tactic = match (context.config.indent_style(), items.len()) {
798798
(IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
799-
_ => context.config.struct_lit_multiline_style().to_list_tactic(),
799+
_ if context.config.struct_lit_single_line() => ListTactic::HorizontalVertical,
800+
_ => ListTactic::Vertical,
800801
};
801802
definitive_tactic(items, prelim_tactic, Separator::Comma, h_shape.width)
802803
} else {

tests/source/configs-struct_lit_multiline_style-force_multi.rs renamed to tests/source/configs-struct_lit_single_line-false.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-struct_lit_multiline_style: ForceMulti
1+
// rustfmt-struct_lit_single_line: false
22
// Struct literal multiline-style
33

44
fn main() {

tests/source/configs-struct_lit_multiline_style-prefer_single.rs renamed to tests/source/configs-struct_lit_single_line-true.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-struct_lit_multiline_style: PreferSingle
1+
// rustfmt-struct_lit_single_line: true
22
// rustfmt-struct_lit_width: 100
33
// Struct literal multiline-style
44

tests/source/struct_lits_multiline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-wrap_comments: true
3-
// rustfmt-struct_lit_multiline_style: ForceMulti
3+
// rustfmt-struct_lit_single_line: false
44

55
// Struct literal expressions.
66

tests/source/struct_lits_visual_multiline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-wrap_comments: true
33
// rustfmt-indent_style: Visual
4-
// rustfmt-struct_lit_multiline_style: ForceMulti
4+
// rustfmt-struct_lit_single_line: false
55
// rustfmt-error_on_line_overflow: false
66

77
// Struct literal expressions.

tests/target/configs-struct_lit_multiline_style-force_multi.rs renamed to tests/target/configs-struct_lit_single_line-false.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-struct_lit_multiline_style: ForceMulti
1+
// rustfmt-struct_lit_single_line: false
22
// Struct literal multiline-style
33

44
fn main() {

tests/target/configs-struct_lit_multiline_style-prefer_single.rs renamed to tests/target/configs-struct_lit_single_line-true.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-struct_lit_multiline_style: PreferSingle
1+
// rustfmt-struct_lit_single_line: true
22
// rustfmt-struct_lit_width: 100
33
// Struct literal multiline-style
44

tests/target/struct_lits_multiline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-wrap_comments: true
3-
// rustfmt-struct_lit_multiline_style: ForceMulti
3+
// rustfmt-struct_lit_single_line: false
44

55
// Struct literal expressions.
66

tests/target/struct_lits_visual_multiline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-wrap_comments: true
33
// rustfmt-indent_style: Visual
4-
// rustfmt-struct_lit_multiline_style: ForceMulti
4+
// rustfmt-struct_lit_single_line: false
55
// rustfmt-error_on_line_overflow: false
66

77
// Struct literal expressions.

0 commit comments

Comments
 (0)