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-5
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](https://github.com/rust-lang/rustfmt/issues/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.
@@ -2080,6 +2137,29 @@ fn main() {
2080
2137
2081
2138
See also: [`indent_style`](#indent_style).
2082
2139
2140
+
## `struct_lit_width`
2141
+
2142
+
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`.
2143
+
2144
+
-**Default value**: `18`
2145
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2146
+
-**Stable**: Yes
2147
+
2148
+
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.
2149
+
2150
+
See also [`max_width`](#max_width), [`width_heuristics`](#width_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2151
+
2152
+
## `struct_variant_width`
2153
+
2154
+
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`.
2155
+
2156
+
-**Default value**: `35`
2157
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2158
+
-**Stable**: Yes
2159
+
2160
+
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.
2161
+
2162
+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
2083
2163
2084
2164
## `tab_spaces`
2085
2165
@@ -2270,15 +2350,45 @@ fn main() {
2270
2350
}
2271
2351
```
2272
2352
2273
-
## `use_small_heuristics`
2353
+
## `width_heuristics`
2354
+
2355
+
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.
2274
2356
2275
-
Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2357
+
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:
2376
+
*`fn_call_width=60`
2377
+
*`attr_fn_like_width=70`
2378
+
*`struct_lit_width=18`
2379
+
*`struct_variant_width=35`
2380
+
*`array_width=60`
2381
+
*`chain_width=60`
2382
+
*`single_line_if_else_max_width=50`
2383
+
2384
+
and when `max_width` is set to `200`:
2385
+
*`fn_call_width=120`
2386
+
*`attr_fn_like_width=140`
2387
+
*`struct_lit_width=36`
2388
+
*`struct_variant_width=70`
2389
+
*`array_width=120`
2390
+
*`chain_width=120`
2391
+
*`single_line_if_else_max_width=100`
2282
2392
2283
2393
```rust
2284
2394
enumLorem {
@@ -2309,6 +2419,7 @@ fn main() {
2309
2419
```
2310
2420
2311
2421
#### `Off`:
2422
+
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.
2312
2423
2313
2424
```rust
2314
2425
enumLorem {
@@ -2337,6 +2448,16 @@ fn main() {
2337
2448
```
2338
2449
2339
2450
#### `Max`:
2451
+
When `width_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2452
+
2453
+
So if `max_width` is set to `200`, then all the width settings are also set to `200`.
0 commit comments