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
+133-1
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 [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `array_width` will take precedence.
29
+
30
+
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_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 [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `attr_fn_like_width` will take precedence.
41
+
42
+
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_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 [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `chain_width` will take precedence.
307
+
308
+
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_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 [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `fn_call_width` will take precedence.
763
+
764
+
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
720
765
721
766
## `fn_single_line`
722
767
@@ -2079,6 +2124,18 @@ Don't reformat out of line modules
2079
2124
-**Possible values**: `true`, `false`
2080
2125
-**Stable**: No (tracking issue: #3389)
2081
2126
2127
+
## `single_line_if_else_max_width`
2128
+
2129
+
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 `use_small_heuristics` is set to `Off`.
2130
+
2131
+
-**Default value**: `50`
2132
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2133
+
-**Stable**: Yes
2134
+
2135
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence.
2136
+
2137
+
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2138
+
2082
2139
## `space_after_colon`
2083
2140
2084
2141
Leave a space after the colon.
@@ -2256,6 +2313,29 @@ fn main() {
2256
2313
2257
2314
See also: [`indent_style`](#indent_style).
2258
2315
2316
+
## `struct_lit_width`
2317
+
2318
+
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 `use_small_heuristics` is set to `Off`.
2319
+
2320
+
-**Default value**: `18`
2321
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2322
+
-**Stable**: Yes
2323
+
2324
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_lit_width` will take precedence.
2325
+
2326
+
See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2327
+
2328
+
## `struct_variant_width`
2329
+
2330
+
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 `use_small_heuristics` is set to `Off`.
2331
+
2332
+
-**Default value**: `35`
2333
+
-**Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2334
+
-**Stable**: Yes
2335
+
2336
+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_variant_width` will take precedence.
2337
+
2338
+
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2259
2339
2260
2340
## `tab_spaces`
2261
2341
@@ -2448,13 +2528,43 @@ fn main() {
2448
2528
2449
2529
## `use_small_heuristics`
2450
2530
2451
-
Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2531
+
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.
2532
+
2533
+
Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
For example when `max_width` is set to `100`, the width settings are:
2552
+
*`fn_call_width=60`
2553
+
*`attr_fn_like_width=70`
2554
+
*`struct_lit_width=18`
2555
+
*`struct_variant_width=35`
2556
+
*`array_width=60`
2557
+
*`chain_width=60`
2558
+
*`single_line_if_else_max_width=50`
2559
+
2560
+
and when `max_width` is set to `200`:
2561
+
*`fn_call_width=120`
2562
+
*`attr_fn_like_width=140`
2563
+
*`struct_lit_width=36`
2564
+
*`struct_variant_width=70`
2565
+
*`array_width=120`
2566
+
*`chain_width=120`
2567
+
*`single_line_if_else_max_width=100`
2458
2568
2459
2569
```rust
2460
2570
enumLorem {
@@ -2485,6 +2595,7 @@ fn main() {
2485
2595
```
2486
2596
2487
2597
#### `Off`:
2598
+
When `use_small_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.
2488
2599
2489
2600
```rust
2490
2601
enumLorem {
@@ -2513,6 +2624,16 @@ fn main() {
2513
2624
```
2514
2625
2515
2626
#### `Max`:
2627
+
When `use_small_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2628
+
2629
+
So if `max_width` is set to `200`, then all the width settings are also set to `200`.
0 commit comments