You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Configurations.md
+137-5Lines changed: 137 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,29 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or
17
17
18
18
Below you find a detailed visual guide on all the supported configuration options of rustfmt:
19
19
20
+
## `array_width`
21
+
22
+
Maximum width of an array literal before falling back to vertical formatting.
23
+
24
+
-**Default value**: `60`
25
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
26
+
-**Stable**: Yes
27
+
28
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `array_width` will take precedence.
29
+
30
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
31
+
32
+
## `attr_fn_like_width`
33
+
34
+
Maximum width of the args of a function-like attributes before falling back to vertical formatting.
35
+
36
+
-**Default value**: `70`
37
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
38
+
-**Stable**: Yes
39
+
40
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `attr_fn_like_width` will take precedence.
41
+
42
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
20
43
21
44
## `binop_separator`
22
45
@@ -272,6 +295,17 @@ where
272
295
}
273
296
```
274
297
298
+
## `chain_width`
299
+
300
+
Maximum width of a chain to fit on one line.
301
+
302
+
-**Default value**: `60`
303
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
304
+
-**Stable**: Yes
305
+
306
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `chain_width` will take precedence.
307
+
308
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
275
309
276
310
## `color`
277
311
@@ -717,6 +751,17 @@ trait Lorem {
717
751
}
718
752
```
719
753
754
+
## `fn_call_width`
755
+
756
+
Maximum width of the args of a function call before falling back to vertical formatting.
757
+
758
+
-**Default value**: `60`
759
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
760
+
-**Stable**: Yes
761
+
762
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `fn_call_width` will take precedence.
763
+
764
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
720
765
721
766
## `fn_single_line`
722
767
@@ -1881,6 +1926,18 @@ specific version of rustfmt is used in your CI, use this option.
1881
1926
-**Possible values**: any published version (e.g. `"0.3.8"`)
1882
1927
-**Stable**: No (tracking issue: #3386)
1883
1928
1929
+
## `single_line_if_else_max_width`
1930
+
1931
+
Maximum line length for single line if-else expressions. A value of `0` (zero) results in if-else expressions always being broken into multiple lines. Note this occurs when `width_heuristics` is set to `Off`.
1932
+
1933
+
-**Default value**: `50`
1934
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
1935
+
-**Stable**: Yes
1936
+
1937
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence.
1938
+
1939
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
1940
+
1884
1941
## `space_after_colon`
1885
1942
1886
1943
Leave a space after the colon.
@@ -2058,6 +2115,29 @@ fn main() {
2058
2115
2059
2116
See also: [`indent_style`](#indent_style).
2060
2117
2118
+
## `struct_lit_width`
2119
+
2120
+
Maximum width in the body of a struct literal before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `width_heuristics` is set to `Off`.
2121
+
2122
+
-**Default value**: `18`
2123
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2124
+
-**Stable**: Yes
2125
+
2126
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `struct_lit_width` will take precedence.
2127
+
2128
+
See also [`max_width`](#max_width), [`width_heuristics`](#width_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2129
+
2130
+
## `struct_variant_width`
2131
+
2132
+
Maximum width in the body of a struct variant before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `width_heuristics` is set to `Off`.
2133
+
2134
+
-**Default value**: `35`
2135
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2136
+
-**Stable**: Yes
2137
+
2138
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `struct_variant_width` will take precedence.
2139
+
2140
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
2061
2141
2062
2142
## `tab_spaces`
2063
2143
@@ -2248,15 +2328,45 @@ fn main() {
2248
2328
}
2249
2329
```
2250
2330
2251
-
## `use_small_heuristics`
2331
+
## `width_heuristics`
2332
+
2333
+
This option can be used to simplify the management and bulk updates of the granular width configuration settings ([`fn_call_width`](#fn_call_width), [`attr_fn_like_width`](#attr_fn_like_width), [`struct_lit_width`](#struct_lit_width), [`struct_variant_width`](#struct_variant_width), [`array_width`](#array_width), [`chain_width`](#chain_width), [`single_line_if_else_max_width`](#single_line_if_else_max_width)), that respectively control when formatted constructs are multi-lined/vertical based on width.
2252
2334
2253
-
Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2335
+
Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `width_heuristics`.
For example when `max_width` is set to `100`, the width settings are:
2354
+
*`fn_call_width=60`
2355
+
*`attr_fn_like_width=70`
2356
+
*`struct_lit_width=18`
2357
+
*`struct_variant_width=35`
2358
+
*`array_width=60`
2359
+
*`chain_width=60`
2360
+
*`single_line_if_else_max_width=50`
2361
+
2362
+
and when `max_width` is set to `200`:
2363
+
*`fn_call_width=120`
2364
+
*`attr_fn_like_width=140`
2365
+
*`struct_lit_width=36`
2366
+
*`struct_variant_width=70`
2367
+
*`array_width=120`
2368
+
*`chain_width=120`
2369
+
*`single_line_if_else_max_width=100`
2260
2370
2261
2371
```rust
2262
2372
enumLorem {
@@ -2287,6 +2397,7 @@ fn main() {
2287
2397
```
2288
2398
2289
2399
#### `Off`:
2400
+
When `width_heuristics` is set to `Off`, the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics.
2290
2401
2291
2402
```rust
2292
2403
enumLorem {
@@ -2315,6 +2426,16 @@ fn main() {
2315
2426
```
2316
2427
2317
2428
#### `Max`:
2429
+
When `width_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2430
+
2431
+
So if `max_width` is set to `200`, then all the width settings are also set to `200`.
0 commit comments