]> git.lizzy.rs Git - rust.git/commitdiff
struct_lit_multiline_style -> struct_lit_single_line (and make it a bool)
authorNick Cameron <ncameron@mozilla.com>
Fri, 24 Nov 2017 01:45:18 +0000 (14:45 +1300)
committerNick Cameron <ncameron@mozilla.com>
Fri, 24 Nov 2017 01:45:18 +0000 (14:45 +1300)
16 files changed:
Configurations.md
src/config.rs
src/expr.rs
src/lists.rs
tests/source/configs-struct_lit_multiline_style-force_multi.rs [deleted file]
tests/source/configs-struct_lit_multiline_style-prefer_single.rs [deleted file]
tests/source/configs-struct_lit_single_line-false.rs [new file with mode: 0644]
tests/source/configs-struct_lit_single_line-true.rs [new file with mode: 0644]
tests/source/struct_lits_multiline.rs
tests/source/struct_lits_visual_multiline.rs
tests/target/configs-struct_lit_multiline_style-force_multi.rs [deleted file]
tests/target/configs-struct_lit_multiline_style-prefer_single.rs [deleted file]
tests/target/configs-struct_lit_single_line-false.rs [new file with mode: 0644]
tests/target/configs-struct_lit_single_line-true.rs [new file with mode: 0644]
tests/target/struct_lits_multiline.rs
tests/target/struct_lits_visual_multiline.rs

index c7fae70d1dddd3eb7e642087afc82127c067ef38..275d4883760d7d5b003b673d53ba879414f1cb98 100644 (file)
@@ -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`
 
index ebbe67dada5bd88a0d675c7771ef71614eedd44b..88af2b5e0a0abfc7cb43e295136adf6cde7ea219 100644 (file)
@@ -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<Option<PathBuf>, 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,
index ad8cb25b53f6f0abbcb8702e86353a9346f83178..b9c33a52be75758b4c0f16b47cef608559687507 100644 (file)
@@ -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!(
index bf0d276574eb4ad8a176f28d780fe462ad25900d..5f8149c6f3ee4c21bb5a34909f45989b723f71d5 100644 (file)
@@ -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_multiline_style-force_multi.rs
deleted file mode 100644 (file)
index 42e1b08..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-// rustfmt-struct_lit_multiline_style: ForceMulti
-// Struct literal multiline-style
-
-fn main() {
-    let lorem = Lorem { ipsum: dolor, sit: amet };
-}
diff --git a/tests/source/configs-struct_lit_multiline_style-prefer_single.rs b/tests/source/configs-struct_lit_multiline_style-prefer_single.rs
deleted file mode 100644 (file)
index 9a4ac48..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// rustfmt-struct_lit_multiline_style: PreferSingle
-// rustfmt-struct_lit_width: 100
-// Struct literal multiline-style
-
-fn main() {
-    let lorem = Lorem { ipsum: dolor, sit: amet };
-}
diff --git a/tests/source/configs-struct_lit_single_line-false.rs b/tests/source/configs-struct_lit_single_line-false.rs
new file mode 100644 (file)
index 0000000..17cad8d
--- /dev/null
@@ -0,0 +1,6 @@
+// rustfmt-struct_lit_single_line: false
+// Struct literal multiline-style
+
+fn main() {
+    let lorem = Lorem { ipsum: dolor, sit: amet };
+}
diff --git a/tests/source/configs-struct_lit_single_line-true.rs b/tests/source/configs-struct_lit_single_line-true.rs
new file mode 100644 (file)
index 0000000..363bf5b
--- /dev/null
@@ -0,0 +1,7 @@
+// rustfmt-struct_lit_single_line: true
+// rustfmt-struct_lit_width: 100
+// Struct literal multiline-style
+
+fn main() {
+    let lorem = Lorem { ipsum: dolor, sit: amet };
+}
index 120cc93471aa17f40c31925603e754853a4b573e..256ba1bbda3b1971bb1a53726ef28494c3e245b4 100644 (file)
@@ -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.
 
index 074853cf3dae97a623e4a87faf8b6b1766cf2fcd..d0b5ea6efbaea7f6e36aa950b4cac2fdd008cb6d 100644 (file)
@@ -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_multiline_style-force_multi.rs
deleted file mode 100644 (file)
index 1abd2f0..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// rustfmt-struct_lit_multiline_style: ForceMulti
-// Struct literal multiline-style
-
-fn main() {
-    let lorem = Lorem {
-        ipsum: dolor,
-        sit: amet,
-    };
-}
diff --git a/tests/target/configs-struct_lit_multiline_style-prefer_single.rs b/tests/target/configs-struct_lit_multiline_style-prefer_single.rs
deleted file mode 100644 (file)
index 9a4ac48..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// rustfmt-struct_lit_multiline_style: PreferSingle
-// rustfmt-struct_lit_width: 100
-// Struct literal multiline-style
-
-fn main() {
-    let lorem = Lorem { ipsum: dolor, sit: amet };
-}
diff --git a/tests/target/configs-struct_lit_single_line-false.rs b/tests/target/configs-struct_lit_single_line-false.rs
new file mode 100644 (file)
index 0000000..e2732b5
--- /dev/null
@@ -0,0 +1,9 @@
+// rustfmt-struct_lit_single_line: false
+// Struct literal multiline-style
+
+fn main() {
+    let lorem = Lorem {
+        ipsum: dolor,
+        sit: amet,
+    };
+}
diff --git a/tests/target/configs-struct_lit_single_line-true.rs b/tests/target/configs-struct_lit_single_line-true.rs
new file mode 100644 (file)
index 0000000..363bf5b
--- /dev/null
@@ -0,0 +1,7 @@
+// rustfmt-struct_lit_single_line: true
+// rustfmt-struct_lit_width: 100
+// Struct literal multiline-style
+
+fn main() {
+    let lorem = Lorem { ipsum: dolor, sit: amet };
+}
index 0eb7b8b759f72822c651423731d46b2ed4739c73..c831dc7a8ba6c99fc9de7612c6ea1d092873c33b 100644 (file)
@@ -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.
 
index 936a4061cb439610d82e39ca1cee450289c669b1..2809d3a26129077ab7855811f5f31d0de6bd02e7 100644 (file)
@@ -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.