]> git.lizzy.rs Git - rust.git/blobdiff - Configurations.md
Merge pull request #1776 from topecongiro/poor-formatting/index-budget
[rust.git] / Configurations.md
index 1811c3aa5c6e34fd092cb731c5f1f5ef7e3b6c0b..cbf41b0f53730f3666a9554bdac2f9d51828b4dd 100644 (file)
@@ -14,11 +14,44 @@ reorder_imported_names = true
 
 Below you find a detailed visual guide on all the supported configuration options of rustfmt:
 
+## `array_horizontal_layout_threshold`
+
+How many elements array must have before rustfmt uses horizontal layout.  
+Use this option to prevent a huge array from being vertically formatted.
+
+- **Default value**: `0`
+- **Possible values**: any positive integer
+
+**Note:** A value of `0` results in [`array_layout`](#array_layout) being applied regardless of a line's width.
+
+#### `0`:
+
+```rust
+// Each element will be placed on its own line.
+let a = vec![
+    0,
+    1,
+    2,
+    3,
+    4,
+    ...
+    999,
+    1000,
+];
+```
+
+#### `1000`:
+```rust
+// Each element will be placed on the same line as much as possible.
+let a = vec![0, 1, 2, 3, 4, ...
+             ..., 999, 1000];
+```
+
 ## `array_layout`
 
 Indent on arrays
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -112,6 +145,28 @@ let lorem = ipsum.dolor().sit().amet().consectetur().adipiscing().elit();
 #### Lines longer than `chain_one_line_max`:
 See [`chain_indent`](#chain_indent).
 
+## `chain_split_single_child`
+
+Split a chain with a single child if its length exceeds [`chain_one_line_max`](#chain_one_line_max).
+
+- **Default value**: `false`
+- **Possible values**: `false`, `true`
+
+#### `false`
+
+```rust
+let files = fs::read_dir("tests/coverage/source").expect("Couldn't read source dir");
+```
+
+#### `true`
+
+```rust
+let files = fs::read_dir("tests/coverage/source")
+    .expect("Couldn't read source dir");
+```
+
+See also [`chain_one_line_max`](#chain_one_line_max).
+
 ## `closure_block_indent_threshold`
 
 How many lines a closure must have before it is block indented. -1 means never use block indent.
@@ -144,6 +199,62 @@ lorem_ipsum(|| {
 });
 ```
 
+## `combine_control_expr`
+
+Combine control expressions with function calls.
+
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
+
+#### `true`
+
+```rust
+fn example() {
+    // If
+    foo!(if x {
+        foo();
+    } else {
+        bar();
+    });
+
+    // IfLet
+    foo!(if let Some(..) = x {
+        foo();
+    } else {
+        bar();
+    });
+
+    // While
+    foo!(while x {
+        foo();
+        bar();
+    });
+
+    // WhileLet
+    foo!(while let Some(..) = x {
+        foo();
+        bar();
+    });
+
+    // ForLoop
+    foo!(for x in y {
+        foo();
+        bar();
+    });
+
+    // Loop
+    foo!(loop {
+        foo();
+        bar();
+    });
+}
+```
+
+#### `false`
+
+```rust
+```
+
 ## `comment_width`
 
 Maximum length of comments. No effect unless`wrap_comments = true`.
@@ -166,7 +277,7 @@ Maximum length of comments. No effect unless`wrap_comments = true`.
 
 See also [`wrap_comments`](#wrap_comments).
 
-## `condense_wildcard_suffices`
+## `condense_wildcard_suffixes`
 
 Replace strings of _ wildcards by a single .. in tuple patterns
 
@@ -185,6 +296,36 @@ let (lorem, ipsum, _, _) = (1, 2, 3, 4);
 let (lorem, ipsum, ..) = (1, 2, 3, 4);
 ```
 
+## `control_style`
+
+Indent style for control flow statements
+
+- **Default value**: `"Rfc"`
+- **Possible values**: `"Rfc"`, `"Legacy"`
+
+#### `"Rfc"`:
+
+```rust
+if lorem_ipsum &&
+    dolor_sit &&
+    amet_consectetur
+{
+    // ...
+}
+```
+
+#### `"Legacy"`:
+
+```rust
+if lorem_ipsum &&
+   dolor_sit &&
+   amet_consectetur {
+    // ...
+}
+```
+
+See also: [`control_brace_style`](#control_brace_style).
+
 ## `control_brace_style`
 
 Brace style for control flow constructs
@@ -259,10 +400,10 @@ trait Lorem {
         // body
     }
 
-    fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
+    fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
              adipiscing: Adipiscing, elit: Elit);
 
-    fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
+    fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
              adipiscing: Adipiscing, elit: Elit) {
         // body
     }
@@ -279,7 +420,7 @@ trait Lorem {
         // body
     }
 
-    fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
+    fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
              adipiscing: Adipiscing, elit: Elit);
 
     fn lorem(ipsum: Ipsum,
@@ -364,7 +505,7 @@ trait Lorem {
 
 Layout of function arguments and tuple structs
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -409,7 +550,7 @@ fn lorem(ipsum: usize,
 
 If function argument parenthesis goes on a newline
 
-- **Default value**: `true`
+- **Default value**: `false`
 - **Possible values**: `true`, `false`
 
 #### `false`:
@@ -504,7 +645,7 @@ fn lorem<T>(ipsum: T)
 
 Indentation for function calls, etc.
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -712,7 +853,7 @@ See also [`force_format_strings`](#force_format_strings), [`max_width`](#max_wid
 
 Indentation of generics
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -1101,6 +1242,60 @@ fn lorem<T: Eq>(t: T) {
 
 See also: [`space_before_bound`](#space_before_bound).
 
+## `struct_field_align_threshold`
+
+The maximum diff of width between struct fields to be aligned with each other.
+
+- **Default value** : 0
+- **Possible values**: any positive integer
+
+#### `0`:
+
+```rust
+struct Foo {
+    x: u32,
+    yy: u32,
+    zzz: u32,
+}
+```
+
+#### `20`:
+
+```rust
+struct Foo {
+    x:   u32,
+    yy:  u32,
+    zzz: u32,
+}
+```
+
+## `space_after_struct_lit_field_colon`
+
+Leave a space after the colon in a struct literal field
+
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
+
+#### `false`:
+
+```rust
+let lorem = Lorem {
+    ipsum:dolor,
+    sit:amet,
+};
+```
+
+#### `true`:
+
+```rust
+let lorem = Lorem {
+    ipsum: dolor,
+    sit: amet,
+};
+```
+
+See also: [`space_before_struct_lit_field_colon`](#space_before_struct_lit_field_colon).
+
 ## `space_after_type_annotation_colon`
 
 Leave a space after the colon in a type annotation
@@ -1151,6 +1346,33 @@ fn lorem<T : Eq>(t: T) {
 
 See also: [`space_after_bound_colon`](#space_after_bound_colon).
 
+## `space_before_struct_lit_field_colon`
+
+Leave a space before the colon in a struct literal field
+
+- **Default value**: `false`
+- **Possible values**: `true`, `false`
+
+#### `false`:
+
+```rust
+let lorem = Lorem {
+    ipsum: dolor,
+    sit: amet,
+};
+```
+
+#### `true`:
+
+```rust
+let lorem = Lorem {
+    ipsum : dolor,
+    sit : amet,
+};
+```
+
+See also: [`space_after_struct_lit_field_colon`](#space_after_struct_lit_field_colon).
+
 ## `space_before_type_annotation`
 
 Leave a space before the colon in a type annotation
@@ -1310,7 +1532,7 @@ let lorem = Lorem {
 
 ```rust
 let lorem = Lorem { ipsum: dolor,
-        sit: amet, };
+                    sit: amet, };
 ```
 
 See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
@@ -1707,31 +1929,31 @@ See also: [`where_density`](#where_density), [`where_layout`](#where_layout), [`
 
 Overall strategy for where clauses
 
-- **Default value**: `"Default"`
-- **Possible values**: `"Default"`, `"Rfc"`
+- **Default value**: `"Rfc"`
+- **Possible values**: `"Rfc"`, `"Legacy"`
 
-#### `"Default"`:
+#### `"Rfc"`:
 
 ```rust
 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
-    where Ipsum: Eq,
-          Dolor: Eq,
-          Sit: Eq,
-          Amet: Eq
+where
+    Ipsum: Eq,
+    Dolor: Eq,
+    Sit: Eq,
+    Amet: Eq,
 {
     // body
 }
 ```
 
-#### `"Rfc"`:
+#### `"Legacy"`:
 
 ```rust
 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
-where
-    Ipsum: Eq,
-    Dolor: Eq,
-    Sit: Eq,
-    Amet: Eq,
+    where Ipsum: Eq,
+          Dolor: Eq,
+          Sit: Eq,
+          Amet: Eq
 {
     // body
 }