]> git.lizzy.rs Git - rust.git/blobdiff - Configurations.md
Add explicit lifetime
[rust.git] / Configurations.md
index 73e7cb101c7b0431bf0049a276dd6fa760a38c3f..972c2e58241ac807594c4eb4b876c40bbc019c9a 100644 (file)
@@ -14,11 +14,47 @@ 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"`:
@@ -58,13 +94,72 @@ Maximum width of an array literal before falling back to vertical formatting
 
 #### Lines shorter than `array_width`:
 ```rust
-let lorem =
-    vec!["ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"];
+let lorem = vec!["ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"];
 ```
 
 #### Lines longer than `array_width`:
 See [`array_layout`](#array_layout).
 
+## `attributes_on_same_line_as_field`
+
+Try to put attributes on the same line as fields
+
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
+
+#### `true`
+
+```rust
+struct Lorem {
+    #[serde(rename = "Ipsum")] ipsum: usize,
+    #[serde(rename = "Dolor")] dolor: usize,
+    #[serde(rename = "Amet")] amet: usize,
+}
+```
+
+#### `false`
+
+```rust
+struct Lorem {
+    #[serde(rename = "Ipsum")]
+    ipsum: usize,
+    #[serde(rename = "Dolor")]
+    dolor: usize,
+    #[serde(rename = "Amet")]
+    amet: usize,
+}
+```
+
+## `attributes_on_same_line_as_variant`
+
+Try to put attributes on the same line as variants
+
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
+
+#### `true`
+
+```rust
+enum Lorem {
+    #[serde(skip_serializing)] Ipsum,
+    #[serde(skip_serializing)] Dolor,
+    #[serde(skip_serializing)] Amet,
+}
+```
+
+#### `false`
+
+```rust
+enum Lorem {
+    #[serde(skip_serializing)]
+    Ipsum,
+    #[serde(skip_serializing)]
+    Dolor,
+    #[serde(skip_serializing)]
+    Amet,
+}
+```
+
 ## `chain_indent`
 
 Indentation of chain
@@ -166,6 +261,8 @@ lorem_ipsum(|| {
 });
 ```
 
+**Note**: This option only takes effect when `fn_call_style` is set to `"Visual"`.
+
 ## `combine_control_expr`
 
 Combine control expressions with function calls.
@@ -263,6 +360,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
@@ -337,11 +464,15 @@ trait Lorem {
         // body
     }
 
-    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: Consectetur,
+        adipiscing: Adipiscing, elit: Elit,
+    );
 
-    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: Consectetur,
+        adipiscing: Adipiscing, elit: Elit,
+    ) {
         // body
     }
 }
@@ -357,16 +488,20 @@ trait Lorem {
         // body
     }
 
-    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,
-             adipiscing: Adipiscing,
-             elit: Elit) {
+    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,
+        adipiscing: Adipiscing,
+        elit: Elit,
+    ) {
         // body
     }
 }
@@ -382,21 +517,25 @@ trait Lorem {
         // body
     }
 
-    fn lorem(ipsum: Ipsum,
-             dolor: Dolor,
-             sit: Sit,
-             amet: Amet,
-             consectetur: onsectetur,
-             adipiscing: Adipiscing,
-             elit: Elit);
-
-    fn lorem(ipsum: Ipsum,
-             dolor: Dolor,
-             sit: Sit,
-             amet: Amet,
-             consectetur: onsectetur,
-             adipiscing: Adipiscing,
-             elit: Elit) {
+    fn lorem(
+        ipsum: Ipsum,
+        dolor: Dolor,
+        sit: Sit,
+        amet: Amet,
+        consectetur: onsectetur,
+        adipiscing: Adipiscing,
+        elit: Elit,
+    );
+
+    fn lorem(
+        ipsum: Ipsum,
+        dolor: Dolor,
+        sit: Sit,
+        amet: Amet,
+        consectetur: onsectetur,
+        adipiscing: Adipiscing,
+        elit: Elit,
+    ) {
         // body
     }
 }
@@ -442,7 +581,7 @@ trait Lorem {
 
 Layout of function arguments and tuple structs
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -487,7 +626,7 @@ fn lorem(ipsum: usize,
 
 If function argument parenthesis goes on a newline
 
-- **Default value**: `true`
+- **Default value**: `false`
 - **Possible values**: `true`, `false`
 
 #### `false`:
@@ -497,8 +636,8 @@ fn lorem(
     ipsum: Ipsum,
     dolor: Dolor,
     sit: Sit,
-    amet: Amet)
-    -> DolorSitAmetConsecteturAdipiscingElitLoremIpsumDolorSitAmetConsecteturAdipiscingElit {
+    amet: Amet,
+) -> DolorSitAmetConsecteturAdipiscingElitLoremIpsumDolorSitAmetConsecteturAdipiscingElit {
     // body
 }
 ```
@@ -507,11 +646,12 @@ fn lorem(
 
 ```rust
 fn lorem
-    (ipsum: Ipsum,
-     dolor: Dolor,
-     sit: Sit,
-     amet: Amet)
-     -> DolorSitAmetConsecteturAdipiscingElitLoremIpsumDolorSitAmetConsecteturAdipiscingElit {
+    (
+    ipsum: Ipsum,
+    dolor: Dolor,
+    sit: Sit,
+    amet: Amet,
+) -> DolorSitAmetConsecteturAdipiscingElitLoremIpsumDolorSitAmetConsecteturAdipiscingElit {
     // body
 }
 ```
@@ -537,7 +677,8 @@ fn lorem(ipsum: usize)
 }
 
 fn lorem<T>(ipsum: T)
-    where T: Add + Sub + Mul + Div
+where
+    T: Add + Sub + Mul + Div,
 {
     // body
 }
@@ -555,7 +696,8 @@ fn lorem(ipsum: usize) {
 }
 
 fn lorem<T>(ipsum: T)
-    where T: Add + Sub + Mul + Div {
+where
+    T: Add + Sub + Mul + Div, {
     // body
 }
 ```
@@ -572,7 +714,8 @@ fn lorem(ipsum: usize) {
 }
 
 fn lorem<T>(ipsum: T)
-    where T: Add + Sub + Mul + Div
+where
+    T: Add + Sub + Mul + Div,
 {
     // body
 }
@@ -582,7 +725,7 @@ fn lorem<T>(ipsum: T)
 
 Indentation for function calls, etc.
 
-- **Default value**: `"Visual"`
+- **Default value**: `"Block"`
 - **Possible values**: `"Block"`, `"Visual"`
 
 #### `"Block"`:
@@ -694,6 +837,8 @@ fn lorem(ipsum: Ipsum,
 
 ```
 
+**Note**: This option only takes effect when `fn_call_style` is set to `"Visual"`.
+
 ## `fn_single_line`
 
 Put single-expression functions on a single line
@@ -790,7 +935,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"`:
@@ -804,14 +949,15 @@ fn lorem<
     Adipiscing: Eq = usize,
     Consectetur: Eq = usize,
     Elit: Eq = usize
->(ipsum: Ipsum,
+>(
+    ipsum: Ipsum,
     dolor: Dolor,
     sit: Sit,
     amet: Amet,
     adipiscing: Adipiscing,
     consectetur: Consectetur,
-    elit: Elit)
-    -> T {
+    elit: Elit,
+) -> T {
     // body
 }
 ```
@@ -916,6 +1062,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
@@ -996,6 +1223,39 @@ match lorem {
 
 See also: [`indent_match_arms`](#indent_match_arms), [`trailing_comma`](#trailing_comma), [`wrap_match_arms`](#wrap_match_arms).
 
+## `match_pattern_separator_break_point`
+
+Put a match sub-patterns' separator (`|`) in front or back.
+
+- **Default value**: `"Back"`
+- **Possible values**: `"Back"`, `"Front"`
+
+#### `"Back"`:
+
+```rust
+match m {
+    Variant::Tag |
+    Variant::Tag2 |
+    Variant::Tag3 |
+    Variant::Tag4 |
+    Variant::Tag5 |
+    Variant::Tag6 => {}
+}
+```
+
+#### `Front`:
+
+```rust
+match m {
+    Variant::Tag
+    | Variant::Tag2
+    | Variant::Tag3
+    | Variant::Tag4
+    | Variant::Tag5
+    | Variant::Tag6 => {}
+}
+```
+
 ## `max_width`
 
 Maximum width of each line
@@ -1005,6 +1265,88 @@ Maximum width of each line
 
 See also [`error_on_line_overflow`](#error_on_line_overflow).
 
+## `merge_derives`
+
+Merge multiple derives into a single one.
+
+- **Default value**: `true`
+- **Possible values**: `true`, `false`
+
+#### `true`:
+
+```rust
+#[derive(Eq, PartialEq, Debug, Copy, Clone)]
+pub enum Foo {}
+```
+
+#### `false`:
+
+```rust
+#[derive(Eq, PartialEq)]
+#[derive(Debug)]
+#[derive(Copy, Clone)]
+pub enum Foo {}
+```
+
+## `multiline_closure_forces_block`
+
+Force multiline closure bodies to be wrapped in a block
+
+- **Default value**: `false`
+- **Possible values**: `false`, `true`
+
+#### `true`:
+
+```rust
+
+result.and_then(|maybe_value| {
+    match maybe_value {
+        None => ...,
+        Some(value) => ...,
+    }
+})
+```
+
+#### `false`:
+
+```rust
+result.and_then(|maybe_value| match maybe_value {
+    None => ...,
+    Some(value) => ...,
+})
+```
+
+## `multiline_match_arm_forces_block`
+
+Force multiline match arm bodies to be wrapped in a block
+
+- **Default value**: `false`
+- **Possible values**: `false`, `true`
+
+#### `false`:
+
+```rust
+match lorem {
+    None => if ipsum {
+        println!("Hello World");
+    },
+    Some(dolor) => ...,
+}
+```
+
+#### `true`:
+
+```rust
+match lorem {
+    None => {
+        if ipsum {
+            println!("Hello World");
+        }
+    }
+    Some(dolor) => ...,
+}
+```
+
 ## `newline_style`
 
 Unix or Windows line endings
@@ -1179,6 +1521,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
@@ -1260,7 +1629,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`:
@@ -1442,7 +1811,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).
@@ -1608,6 +1977,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
@@ -1652,7 +2042,7 @@ let lorem = ipsum.map(|dolor| dolor.sit())?;
 
 ## `where_density`
 
-Density of a where clause
+Density of a where clause
 
 - **Default value**: `"CompressedIfEmpty"`
 - **Possible values**: `"Compressed"`, `"CompressedIfEmpty"`, `"Tall"`, `"Vertical"`
@@ -1661,9 +2051,11 @@ Density of a where clause
 
 ```rust
 trait Lorem {
-    fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
+    fn ipsum<Dolor>(dolor: Dolor) -> Sit
+    where Dolor: Eq;
 
-    fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq {
+    fn ipsum<Dolor>(dolor: Dolor) -> Sit
+    where Dolor: Eq {
         // body
     }
 }
@@ -1673,10 +2065,12 @@ trait Lorem {
 
 ```rust
 trait Lorem {
-    fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
+    fn ipsum<Dolor>(dolor: Dolor) -> Sit
+    where Dolor: Eq;
 
     fn ipsum<Dolor>(dolor: Dolor) -> Sit
-        where Dolor: Eq
+    where
+        Dolor: Eq,
     {
         // body
     }
@@ -1688,10 +2082,12 @@ trait Lorem {
 ```rust
 trait Lorem {
     fn ipsum<Dolor>(dolor: Dolor) -> Sit
-        where Dolor: Eq;
+    where
+        Dolor: Eq;
 
     fn ipsum<Dolor>(dolor: Dolor) -> Sit
-        where Dolor: Eq
+    where
+        Dolor: Eq,
     {
         // body
     }
@@ -1798,6 +2194,8 @@ fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Am
 }
 ```
 
+**Note**: This option only takes effect when `where_style` is set to `"Legacy"`.
+
 See also: [`where_density`](#where_density), [`where_pred_indent`](#where_pred_indent), [`where_style`](#where_style).
 
 ## `where_pred_indent`
@@ -1833,37 +2231,39 @@ fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
 }
 ```
 
+**Note**: This option only takes effect when `where_style` is set to `"Legacy"`.
+
 See also: [`where_density`](#where_density), [`where_layout`](#where_layout), [`where_style`](#where_style).
 
 ## `where_style`
 
 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
 }
@@ -1896,7 +2296,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`
@@ -1905,13 +2305,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),
 }
 ```
 
@@ -1920,8 +2316,7 @@ match lorem {
 ```rust
 match lorem {
     true => {
-        let ipsum = dolor;
-        println!("{}", ipsum);
+        foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
     }
     false => println!("{}", sit),
 }
@@ -1933,5 +2328,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"`