Skip to content

Commit 0269eb1

Browse files
docs: update configuration info
1 parent 26fb3fa commit 0269eb1

File tree

1 file changed

+133
-1
lines changed

1 file changed

+133
-1
lines changed

Diff for: Configurations.md

+133-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or
1717

1818
Below you find a detailed visual guide on all the supported configuration options of rustfmt:
1919

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)
2043

2144
## `binop_separator`
2245

@@ -272,6 +295,17 @@ where
272295
}
273296
```
274297

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)
275309

276310
## `color`
277311

@@ -717,6 +751,17 @@ trait Lorem {
717751
}
718752
```
719753

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)
720765

721766
## `fn_single_line`
722767

@@ -2079,6 +2124,18 @@ Don't reformat out of line modules
20792124
- **Possible values**: `true`, `false`
20802125
- **Stable**: No (tracking issue: #3389)
20812126

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+
20822139
## `space_after_colon`
20832140

20842141
Leave a space after the colon.
@@ -2256,6 +2313,29 @@ fn main() {
22562313

22572314
See also: [`indent_style`](#indent_style).
22582315

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)
22592339

22602340
## `tab_spaces`
22612341

@@ -2448,13 +2528,43 @@ fn main() {
24482528

24492529
## `use_small_heuristics`
24502530

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`.
24522534

24532535
- **Default value**: `"Default"`
24542536
- **Possible values**: `"Default"`, `"Off"`, `"Max"`
24552537
- **Stable**: Yes
24562538

24572539
#### `Default` (default):
2540+
When `use_small_heuristics` is set to `Default`, the values for the granular width settings are calculated as a ratio of the value for `max_width`.
2541+
2542+
The ratios are:
2543+
* [`fn_call_width`](#fn_call_width) - `60%`
2544+
* [`attr_fn_like_width`](#attr_fn_like_width) - `70%`
2545+
* [`struct_lit_width`](#struct_lit_width) - `18%`
2546+
* [`struct_variant_width`](#struct_variant_width) - `35%`
2547+
* [`array_width`](#array_width) - `60%`
2548+
* [`chain_width`](#chain_width) - `60%`
2549+
* [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%`
2550+
2551+
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`
24582568

24592569
```rust
24602570
enum Lorem {
@@ -2485,6 +2595,7 @@ fn main() {
24852595
```
24862596

24872597
#### `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.
24882599

24892600
```rust
24902601
enum Lorem {
@@ -2513,6 +2624,16 @@ fn main() {
25132624
```
25142625

25152626
#### `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`.
2630+
* `fn_call_width=200`
2631+
* `attr_fn_like_width=200`
2632+
* `struct_lit_width=200`
2633+
* `struct_variant_width=200`
2634+
* `array_width=200`
2635+
* `chain_width=200`
2636+
* `single_line_if_else_max_width=200`
25162637

25172638
```rust
25182639
enum Lorem {
@@ -2530,6 +2651,17 @@ fn main() {
25302651
}
25312652
```
25322653

2654+
2655+
See also:
2656+
* [`max_width`](#max_width)
2657+
* [`fn_call_width`](#fn_call_width)
2658+
* [`attr_fn_like_width`](#attr_fn_like_width)
2659+
* [`struct_lit_width`](#struct_lit_width)
2660+
* [`struct_variant_width`](#struct_variant_width)
2661+
* [`array_width`](#array_width)
2662+
* [`chain_width`](#chain_width)
2663+
* [`single_line_if_else_max_width`](#single_line_if_else_max_width)
2664+
25332665
## `use_try_shorthand`
25342666

25352667
Replace uses of the try! macro by the ? shorthand

0 commit comments

Comments
 (0)