From 45d4f7a2dd1c95e47d4ae4dc413dfb71e53c16ff Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 24 Nov 2017 14:45:18 +1300 Subject: [PATCH] struct_lit_multiline_style -> struct_lit_single_line (and make it a bool) --- Configurations.md | 16 +++++++-------- src/config.rs | 20 ++----------------- src/expr.rs | 5 ++--- src/lists.rs | 3 ++- ...> configs-struct_lit_single_line-false.rs} | 2 +- ...=> configs-struct_lit_single_line-true.rs} | 2 +- tests/source/struct_lits_multiline.rs | 2 +- tests/source/struct_lits_visual_multiline.rs | 2 +- ...> configs-struct_lit_single_line-false.rs} | 2 +- ...=> configs-struct_lit_single_line-true.rs} | 2 +- tests/target/struct_lits_multiline.rs | 2 +- tests/target/struct_lits_visual_multiline.rs | 2 +- 12 files changed, 22 insertions(+), 38 deletions(-) rename tests/source/{configs-struct_lit_multiline_style-force_multi.rs => configs-struct_lit_single_line-false.rs} (66%) rename tests/source/{configs-struct_lit_multiline_style-prefer_single.rs => configs-struct_lit_single_line-true.rs} (71%) rename tests/target/{configs-struct_lit_multiline_style-force_multi.rs => configs-struct_lit_single_line-false.rs} (70%) rename tests/target/{configs-struct_lit_multiline_style-prefer_single.rs => configs-struct_lit_single_line-true.rs} (71%) diff --git a/Configurations.md b/Configurations.md index c7fae70d1dd..275d4883760 100644 --- a/Configurations.md +++ b/Configurations.md @@ -246,7 +246,7 @@ let lorem = Lorem { ipsum: dolor, 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 @@ -1746,20 +1746,20 @@ let lorem: [ usize; 2 ] = [ ipsum, dolor ]; 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 { @@ -1787,7 +1787,7 @@ let lorem = Lorem { ipsum: dolor, sit: amet }; #### 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` diff --git a/src/config.rs b/src/config.rs index ebbe67dada5..88af2b5e0a0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -100,22 +100,6 @@ pub fn to_list_tactic(self) -> ListTactic { } } -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, @@ -563,8 +547,8 @@ pub fn get_toml_path(dir: &Path) -> Result, Error> { 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, diff --git a/src/expr.rs b/src/expr.rs index ad8cb25b53f..b9c33a52be7 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -21,7 +21,7 @@ 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}; @@ -2346,8 +2346,7 @@ pub fn wrap_struct_field( 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!( diff --git a/src/lists.rs b/src/lists.rs index bf0d276574e..5f8149c6f3e 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -796,7 +796,8 @@ pub fn struct_lit_tactic( 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 { diff --git a/tests/source/configs-struct_lit_multiline_style-force_multi.rs b/tests/source/configs-struct_lit_single_line-false.rs similarity index 66% rename from tests/source/configs-struct_lit_multiline_style-force_multi.rs rename to tests/source/configs-struct_lit_single_line-false.rs index 42e1b088bd1..17cad8dde29 100644 --- a/tests/source/configs-struct_lit_multiline_style-force_multi.rs +++ b/tests/source/configs-struct_lit_single_line-false.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_lit_multiline_style: ForceMulti +// rustfmt-struct_lit_single_line: false // Struct literal multiline-style fn main() { diff --git a/tests/source/configs-struct_lit_multiline_style-prefer_single.rs b/tests/source/configs-struct_lit_single_line-true.rs similarity index 71% rename from tests/source/configs-struct_lit_multiline_style-prefer_single.rs rename to tests/source/configs-struct_lit_single_line-true.rs index 9a4ac481335..363bf5b114e 100644 --- a/tests/source/configs-struct_lit_multiline_style-prefer_single.rs +++ b/tests/source/configs-struct_lit_single_line-true.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_lit_multiline_style: PreferSingle +// rustfmt-struct_lit_single_line: true // rustfmt-struct_lit_width: 100 // Struct literal multiline-style diff --git a/tests/source/struct_lits_multiline.rs b/tests/source/struct_lits_multiline.rs index 120cc93471a..256ba1bbda3 100644 --- a/tests/source/struct_lits_multiline.rs +++ b/tests/source/struct_lits_multiline.rs @@ -1,6 +1,6 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true -// rustfmt-struct_lit_multiline_style: ForceMulti +// rustfmt-struct_lit_single_line: false // Struct literal expressions. diff --git a/tests/source/struct_lits_visual_multiline.rs b/tests/source/struct_lits_visual_multiline.rs index 074853cf3da..d0b5ea6efba 100644 --- a/tests/source/struct_lits_visual_multiline.rs +++ b/tests/source/struct_lits_visual_multiline.rs @@ -1,7 +1,7 @@ // 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. diff --git a/tests/target/configs-struct_lit_multiline_style-force_multi.rs b/tests/target/configs-struct_lit_single_line-false.rs similarity index 70% rename from tests/target/configs-struct_lit_multiline_style-force_multi.rs rename to tests/target/configs-struct_lit_single_line-false.rs index 1abd2f09d9c..e2732b5a7c9 100644 --- a/tests/target/configs-struct_lit_multiline_style-force_multi.rs +++ b/tests/target/configs-struct_lit_single_line-false.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_lit_multiline_style: ForceMulti +// rustfmt-struct_lit_single_line: false // Struct literal multiline-style fn main() { diff --git a/tests/target/configs-struct_lit_multiline_style-prefer_single.rs b/tests/target/configs-struct_lit_single_line-true.rs similarity index 71% rename from tests/target/configs-struct_lit_multiline_style-prefer_single.rs rename to tests/target/configs-struct_lit_single_line-true.rs index 9a4ac481335..363bf5b114e 100644 --- a/tests/target/configs-struct_lit_multiline_style-prefer_single.rs +++ b/tests/target/configs-struct_lit_single_line-true.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_lit_multiline_style: PreferSingle +// rustfmt-struct_lit_single_line: true // rustfmt-struct_lit_width: 100 // Struct literal multiline-style diff --git a/tests/target/struct_lits_multiline.rs b/tests/target/struct_lits_multiline.rs index 0eb7b8b759f..c831dc7a8ba 100644 --- a/tests/target/struct_lits_multiline.rs +++ b/tests/target/struct_lits_multiline.rs @@ -1,6 +1,6 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true -// rustfmt-struct_lit_multiline_style: ForceMulti +// rustfmt-struct_lit_single_line: false // Struct literal expressions. diff --git a/tests/target/struct_lits_visual_multiline.rs b/tests/target/struct_lits_visual_multiline.rs index 936a4061cb4..2809d3a2612 100644 --- a/tests/target/struct_lits_visual_multiline.rs +++ b/tests/target/struct_lits_visual_multiline.rs @@ -1,7 +1,7 @@ // 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. -- 2.44.0