]> git.lizzy.rs Git - rust.git/blobdiff - Configurations.md
cargo update
[rust.git] / Configurations.md
index 0b0a55703561bb64f17b601d299864714bd5a259..5c75030d480846ed7be2ac4f3f15f78c930c33c6 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"`:
@@ -166,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`.
@@ -207,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
@@ -386,7 +505,7 @@ trait Lorem {
 
 Layout of function arguments and tuple structs
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -431,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`:
@@ -526,7 +645,7 @@ fn lorem<T>(ipsum: T)
 
 Indentation for function calls, etc.
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -734,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"`:
@@ -860,6 +979,87 @@ match lorem {
 
 See also: [`match_block_trailing_comma`](#match_block_trailing_comma), [`wrap_match_arms`](#wrap_match_arms).
 
+## `imports_indent`
+
+Indent style of imports
+
+- **Default Value**: `"Visual"`
+- **Possible values**: `"Block"`, `"Visual"`
+
+#### `"Block"`
+
+```rust
+use foo::{
+    xxx,
+    yyy,
+    zzz,
+};
+```
+
+#### `"Visual"`
+
+```rust
+use foo::{xxx,
+          yyy,
+          zzz};
+```
+
+See also: [`imports_layout`](#imports_layout).
+
+## `imports_layout`
+
+Item layout inside a imports block
+
+- **Default value**: "Mixed"
+- **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
+
+#### `"Mixed"`
+
+```rust
+use foo::{xxx, yyy, zzz};
+
+use foo::{aaa, bbb, ccc,
+          ddd, eee, fff};
+```
+
+#### `"Horizontal"`
+
+**Note**: This option forces to put everything on one line and may exceeds `max_width`.
+
+```rust
+use foo::{xxx, yyy, zzz};
+
+use foo::{aaa, bbb, ccc, ddd, eee, fff};
+```
+
+#### `"HorizontalVertical"`
+
+```rust
+use foo::{xxx, yyy, zzz};
+
+use foo::{aaa,
+          bbb,
+          ccc,
+          ddd, 
+          eee, 
+          fff};
+```
+
+#### `"Vertical"`
+
+```rust
+use foo::{xxx,
+          yyy,
+          zzz};
+
+use foo::{aaa,
+          bbb,
+          ccc,
+          ddd,
+          eee,
+          fff};
+```
+
 ## `item_brace_style`
 
 Brace style for structs and enums
@@ -1123,6 +1323,33 @@ 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
@@ -1204,7 +1431,7 @@ See also: [`space_after_bound_colon`](#space_after_bound_colon).
 
 Leave a space before the colon in a struct literal field
 
-- **Default value**: `true`
+- **Default value**: `false`
 - **Possible values**: `true`, `false`
 
 #### `false`:
@@ -1386,7 +1613,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).
@@ -1552,6 +1779,27 @@ let Lorem {
 
 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
 
+## `trailing_semicolon`
+
+Add trailing semicolon after break, continue and return
+
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
+
+#### `true`:
+```rust
+fn foo() -> usize {
+    return 0;
+}
+```
+
+#### `false`:
+```rust
+fn foo() -> usize {
+    return 0
+}
+```
+
 ## `type_punctuation_density`
 
 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
@@ -1783,31 +2031,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
 }
@@ -1840,7 +2088,7 @@ Break comments to fit on the line
 
 ## `wrap_match_arms`
 
-Wrap multiline match arms in blocks
+Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
 
 - **Default value**: `true`
 - **Possible values**: `true`, `false`
@@ -1849,13 +2097,9 @@ Wrap multiline match arms in blocks
 
 ```rust
 match lorem {
-    true => {
-        let ipsum = dolor;
-        println!("{}", ipsum);
-    }
-    false => {
-        println!("{}", sit)
-    }
+    true =>
+        foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
+    false => println!("{}", sit),
 }
 ```
 
@@ -1864,8 +2108,7 @@ match lorem {
 ```rust
 match lorem {
     true => {
-        let ipsum = dolor;
-        println!("{}", ipsum);
+        foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
     }
     false => println!("{}", sit),
 }
@@ -1877,5 +2120,5 @@ See also: [`indent_match_arms`](#indent_match_arms), [`match_block_trailing_comm
 
 What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage
 
-- **Default value**: `"Replace"`
+- **Default value**: `"Overwrite"`
 - **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"`