sit: amet, };
```
-See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`indent_style`](#indent_style).
+See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
### Where predicates
See also: [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets), [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets).
-## `struct_lit_multiline_style`
+## `struct_lit_single_line`
-Multiline style on literal structs
+Put small struct literals on a single line
-- **Default value**: `"PreferSingle"`
-- **Possible values**: `"ForceMulti"`, `"PreferSingle"`
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
-#### `"PreferSingle"` (default):
+#### `true` (default):
```rust
let lorem = Lorem { ipsum: dolor, sit: amet };
```
-#### `"ForceMulti"`:
+#### `false`:
```rust
let lorem = Lorem {
#### Lines longer than `struct_lit_width`:
See [`indent_style`](#indent_style).
-See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`indent_style`](#indent_style).
+See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
## `struct_variant_width`
}
}
-configuration_option_enum! { MultilineStyle:
- // Use horizontal layout if it fits in one line, fall back to vertical
- PreferSingle,
- // Use vertical layout
- ForceMulti,
-}
-
-impl MultilineStyle {
- pub fn to_list_tactic(self) -> ListTactic {
- match self {
- MultilineStyle::PreferSingle => ListTactic::HorizontalVertical,
- MultilineStyle::ForceMulti => ListTactic::Vertical,
- }
- }
-}
-
configuration_option_enum! { ReportTactic:
Always,
Unnumbered,
where_density: Density, Density::Vertical, false, "Density of a where clause";
where_single_line: bool, false, false, "To force single line where layout";
where_layout: ListTactic, ListTactic::Vertical, false, "Element layout inside a where clause";
- struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle, false,
- "Multiline style on literal structs";
+ struct_lit_single_line: bool, true, false,
+ "Put small struct literals on a single line";
report_todo: ReportTactic, ReportTactic::Never, false,
"Report all, none or unnumbered occurrences of TODO in source file comments";
report_fixme: ReportTactic, ReportTactic::Never, false,
use codemap::{LineRangeUtils, SpanUtils};
use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
rewrite_comment, rewrite_missing_comment, FindUncommented};
-use config::{Config, ControlBraceStyle, IndentStyle, MultilineStyle};
+use config::{Config, ControlBraceStyle, IndentStyle};
use lists::{definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting,
struct_lit_shape, struct_lit_tactic, write_list, DefinitiveListTactic, ListFormatting,
ListItem, ListTactic, Separator, SeparatorPlace, SeparatorTactic};
one_line_width: usize,
) -> String {
if context.config.indent_style() == IndentStyle::Block
- && (fields_str.contains('\n')
- || context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti
+ && (fields_str.contains('\n') || !context.config.struct_lit_single_line()
|| fields_str.len() > one_line_width)
{
format!(
if let Some(h_shape) = h_shape {
let prelim_tactic = match (context.config.indent_style(), items.len()) {
(IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
- _ => context.config.struct_lit_multiline_style().to_list_tactic(),
+ _ if context.config.struct_lit_single_line() => ListTactic::HorizontalVertical,
+ _ => ListTactic::Vertical,
};
definitive_tactic(items, prelim_tactic, Separator::Comma, h_shape.width)
} else {
+++ /dev/null
-// rustfmt-struct_lit_multiline_style: ForceMulti
-// Struct literal multiline-style
-
-fn main() {
- let lorem = Lorem { ipsum: dolor, sit: amet };
-}
+++ /dev/null
-// rustfmt-struct_lit_multiline_style: PreferSingle
-// rustfmt-struct_lit_width: 100
-// Struct literal multiline-style
-
-fn main() {
- let lorem = Lorem { ipsum: dolor, sit: amet };
-}
--- /dev/null
+// rustfmt-struct_lit_single_line: false
+// Struct literal multiline-style
+
+fn main() {
+ let lorem = Lorem { ipsum: dolor, sit: amet };
+}
--- /dev/null
+// rustfmt-struct_lit_single_line: true
+// rustfmt-struct_lit_width: 100
+// Struct literal multiline-style
+
+fn main() {
+ let lorem = Lorem { ipsum: dolor, sit: amet };
+}
// rustfmt-normalize_comments: true
// rustfmt-wrap_comments: true
-// rustfmt-struct_lit_multiline_style: ForceMulti
+// rustfmt-struct_lit_single_line: false
// Struct literal expressions.
// rustfmt-normalize_comments: true
// rustfmt-wrap_comments: true
// rustfmt-indent_style: Visual
-// rustfmt-struct_lit_multiline_style: ForceMulti
+// rustfmt-struct_lit_single_line: false
// rustfmt-error_on_line_overflow: false
// Struct literal expressions.
+++ /dev/null
-// rustfmt-struct_lit_multiline_style: ForceMulti
-// Struct literal multiline-style
-
-fn main() {
- let lorem = Lorem {
- ipsum: dolor,
- sit: amet,
- };
-}
+++ /dev/null
-// rustfmt-struct_lit_multiline_style: PreferSingle
-// rustfmt-struct_lit_width: 100
-// Struct literal multiline-style
-
-fn main() {
- let lorem = Lorem { ipsum: dolor, sit: amet };
-}
--- /dev/null
+// rustfmt-struct_lit_single_line: false
+// Struct literal multiline-style
+
+fn main() {
+ let lorem = Lorem {
+ ipsum: dolor,
+ sit: amet,
+ };
+}
--- /dev/null
+// rustfmt-struct_lit_single_line: true
+// rustfmt-struct_lit_width: 100
+// Struct literal multiline-style
+
+fn main() {
+ let lorem = Lorem { ipsum: dolor, sit: amet };
+}
// rustfmt-normalize_comments: true
// rustfmt-wrap_comments: true
-// rustfmt-struct_lit_multiline_style: ForceMulti
+// rustfmt-struct_lit_single_line: false
// Struct literal expressions.
// rustfmt-normalize_comments: true
// rustfmt-wrap_comments: true
// rustfmt-indent_style: Visual
-// rustfmt-struct_lit_multiline_style: ForceMulti
+// rustfmt-struct_lit_single_line: false
// rustfmt-error_on_line_overflow: false
// Struct literal expressions.