]> git.proxmox.com Git - rustc.git/blame - src/tools/rustfmt/Configurations.md
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / rustfmt / Configurations.md
CommitLineData
f20569fa
XL
1# Configuring Rustfmt
2
3Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/1.0.4/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
4
5A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
6
7```toml
8indent_style = "Block"
9reorder_imports = false
10```
11
12Each configuration option is either stable or unstable.
923072b8 13Stable options can always be used, while unstable options are only available on a nightly toolchain and must be opted into.
f20569fa
XL
14To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or pass `--unstable-features` to rustfmt.
15
16# Configuration Options
17
18Below you find a detailed visual guide on all the supported configuration options of rustfmt:
19
136023e0 20## `array_width`
cdc7bbd5
XL
21
22Maximum 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
136023e0 28By 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.
cdc7bbd5
XL
29
30See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
31
136023e0 32## `attr_fn_like_width`
cdc7bbd5
XL
33
34Maximum 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
136023e0 40By 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.
cdc7bbd5
XL
41
42See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
f20569fa
XL
43
44## `binop_separator`
45
46Where to put a binary operator when a binary expression goes multiline.
47
48- **Default value**: `"Front"`
49- **Possible values**: `"Front"`, `"Back"`
a2a8927a 50- **Stable**: No (tracking issue: [#3368](https://github.com/rust-lang/rustfmt/issues/3368))
f20569fa
XL
51
52#### `"Front"` (default):
53
54```rust
55fn main() {
56 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
57 || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
58
59 let sum = 123456789012345678901234567890
60 + 123456789012345678901234567890
61 + 123456789012345678901234567890;
62
63 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
64 ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
65}
66```
67
68#### `"Back"`:
69
70```rust
71fn main() {
72 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
73 barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
74
75 let sum = 123456789012345678901234567890 +
76 123456789012345678901234567890 +
77 123456789012345678901234567890;
78
79 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
80 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
81}
82```
83
84## `blank_lines_lower_bound`
85
86Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
87them, additional blank lines are inserted.
88
89- **Default value**: `0`
90- **Possible values**: *unsigned integer*
a2a8927a 91- **Stable**: No (tracking issue: [#3382](https://github.com/rust-lang/rustfmt/issues/3382))
f20569fa
XL
92
93### Example
94Original Code (rustfmt will not change it with the default value of `0`):
95
96```rust
97#![rustfmt::skip]
98
99fn foo() {
100 println!("a");
101}
102fn bar() {
103 println!("b");
104 println!("c");
105}
106```
107
108#### `1`
109```rust
110fn foo() {
111
112 println!("a");
113}
114
115fn bar() {
116
117 println!("b");
118
119 println!("c");
120}
121```
122
123
124## `blank_lines_upper_bound`
125
126Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
127lines are found, they are trimmed down to match this integer.
128
129- **Default value**: `1`
130- **Possible values**: any non-negative integer
a2a8927a 131- **Stable**: No (tracking issue: [#3381](https://github.com/rust-lang/rustfmt/issues/3381))
f20569fa
XL
132
133### Example
134Original Code:
135
136```rust
137#![rustfmt::skip]
138
139fn foo() {
140 println!("a");
141}
142
143
144
145fn bar() {
146 println!("b");
147
148
149 println!("c");
150}
151```
152
153#### `1` (default):
154```rust
155fn foo() {
156 println!("a");
157}
158
159fn bar() {
160 println!("b");
161
162 println!("c");
163}
164```
165
166#### `2`:
167```rust
168fn foo() {
169 println!("a");
170}
171
172
173fn bar() {
174 println!("b");
175
176
177 println!("c");
178}
179```
180
181See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
182
183## `brace_style`
184
185Brace style for items
186
187- **Default value**: `"SameLineWhere"`
188- **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
a2a8927a 189- **Stable**: No (tracking issue: [#3376](https://github.com/rust-lang/rustfmt/issues/3376))
f20569fa
XL
190
191### Functions
192
193#### `"SameLineWhere"` (default):
194
195```rust
196fn lorem() {
197 // body
198}
199
200fn lorem(ipsum: usize) {
201 // body
202}
203
204fn lorem<T>(ipsum: T)
205where
206 T: Add + Sub + Mul + Div,
207{
208 // body
209}
210```
211
212#### `"AlwaysNextLine"`:
213
214```rust
215fn lorem()
216{
217 // body
218}
219
220fn lorem(ipsum: usize)
221{
222 // body
223}
224
225fn lorem<T>(ipsum: T)
226where
227 T: Add + Sub + Mul + Div,
228{
229 // body
230}
231```
232
233#### `"PreferSameLine"`:
234
235```rust
236fn lorem() {
237 // body
238}
239
240fn lorem(ipsum: usize) {
241 // body
242}
243
244fn lorem<T>(ipsum: T)
245where
246 T: Add + Sub + Mul + Div, {
247 // body
248}
249```
250
251### Structs and enums
252
253#### `"SameLineWhere"` (default):
254
255```rust
256struct Lorem {
257 ipsum: bool,
258}
259
260struct Dolor<T>
261where
262 T: Eq,
263{
264 sit: T,
265}
266```
267
268#### `"AlwaysNextLine"`:
269
270```rust
271struct Lorem
272{
273 ipsum: bool,
274}
275
276struct Dolor<T>
277where
278 T: Eq,
279{
280 sit: T,
281}
282```
283
284#### `"PreferSameLine"`:
285
286```rust
287struct Lorem {
288 ipsum: bool,
289}
290
291struct Dolor<T>
292where
293 T: Eq, {
294 sit: T,
295}
296```
297
136023e0 298## `chain_width`
cdc7bbd5
XL
299
300Maximum 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
136023e0 306By 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.
cdc7bbd5
XL
307
308See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
f20569fa
XL
309
310## `color`
311
312Whether to use colored output or not.
313
314- **Default value**: `"Auto"`
315- **Possible values**: "Auto", "Always", "Never"
a2a8927a 316- **Stable**: No (tracking issue: [#3385](https://github.com/rust-lang/rustfmt/issues/3385))
f20569fa
XL
317
318## `combine_control_expr`
319
320Combine control expressions with function calls.
321
322- **Default value**: `true`
323- **Possible values**: `true`, `false`
a2a8927a 324- **Stable**: No (tracking issue: [#3369](https://github.com/rust-lang/rustfmt/issues/3369))
f20569fa
XL
325
326#### `true` (default):
327
328```rust
329fn example() {
330 // If
331 foo!(if x {
332 foo();
333 } else {
334 bar();
335 });
336
337 // IfLet
338 foo!(if let Some(..) = x {
339 foo();
340 } else {
341 bar();
342 });
343
344 // While
345 foo!(while x {
346 foo();
347 bar();
348 });
349
350 // WhileLet
351 foo!(while let Some(..) = x {
352 foo();
353 bar();
354 });
355
356 // ForLoop
357 foo!(for x in y {
358 foo();
359 bar();
360 });
361
362 // Loop
363 foo!(loop {
364 foo();
365 bar();
366 });
367}
368```
369
370#### `false`:
371
372```rust
373fn example() {
374 // If
375 foo!(
376 if x {
377 foo();
378 } else {
379 bar();
380 }
381 );
382
383 // IfLet
384 foo!(
385 if let Some(..) = x {
386 foo();
387 } else {
388 bar();
389 }
390 );
391
392 // While
393 foo!(
394 while x {
395 foo();
396 bar();
397 }
398 );
399
400 // WhileLet
401 foo!(
402 while let Some(..) = x {
403 foo();
404 bar();
405 }
406 );
407
408 // ForLoop
409 foo!(
410 for x in y {
411 foo();
412 bar();
413 }
414 );
415
416 // Loop
417 foo!(
418 loop {
419 foo();
420 bar();
421 }
422 );
423}
424```
425
426## `comment_width`
427
428Maximum length of comments. No effect unless`wrap_comments = true`.
429
430- **Default value**: `80`
431- **Possible values**: any positive integer
a2a8927a 432- **Stable**: No (tracking issue: [#3349](https://github.com/rust-lang/rustfmt/issues/3349))
f20569fa
XL
433
434**Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
435
436#### `80` (default; comments shorter than `comment_width`):
437```rust
438// Lorem ipsum dolor sit amet, consectetur adipiscing elit.
439```
440
441#### `60` (comments longer than `comment_width`):
442```rust
443// Lorem ipsum dolor sit amet,
444// consectetur adipiscing elit.
445```
446
447See also [`wrap_comments`](#wrap_comments).
448
449## `condense_wildcard_suffixes`
450
451Replace strings of _ wildcards by a single .. in tuple patterns
452
453- **Default value**: `false`
454- **Possible values**: `true`, `false`
a2a8927a 455- **Stable**: No (tracking issue: [#3384](https://github.com/rust-lang/rustfmt/issues/3384))
f20569fa
XL
456
457#### `false` (default):
458
459```rust
460fn main() {
461 let (lorem, ipsum, _, _) = (1, 2, 3, 4);
462 let (lorem, ipsum, ..) = (1, 2, 3, 4);
463}
464```
465
466#### `true`:
467
468```rust
469fn main() {
470 let (lorem, ipsum, ..) = (1, 2, 3, 4);
471}
472```
473
474## `control_brace_style`
475
476Brace style for control flow constructs
477
478- **Default value**: `"AlwaysSameLine"`
479- **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
a2a8927a 480- **Stable**: No (tracking issue: [#3377](https://github.com/rust-lang/rustfmt/issues/3377))
f20569fa
XL
481
482#### `"AlwaysSameLine"` (default):
483
484```rust
485fn main() {
486 if lorem {
487 println!("ipsum!");
488 } else {
489 println!("dolor!");
490 }
491}
492```
493
494#### `"AlwaysNextLine"`:
495
496```rust
497fn main() {
498 if lorem
499 {
500 println!("ipsum!");
501 }
502 else
503 {
504 println!("dolor!");
505 }
506}
507```
508
509#### `"ClosingNextLine"`:
510
511```rust
512fn main() {
513 if lorem {
514 println!("ipsum!");
515 }
516 else {
517 println!("dolor!");
518 }
519}
520```
521
522## `disable_all_formatting`
523
3c0e092e
XL
524Don't reformat anything.
525
526Note that this option may be soft-deprecated in the future once the [ignore](#ignore) option is stabilized. Nightly toolchain users are encouraged to use [ignore](#ignore) instead when possible.
f20569fa
XL
527
528- **Default value**: `false`
529- **Possible values**: `true`, `false`
3c0e092e 530- **Stable**: Yes
f20569fa
XL
531
532## `edition`
533
534Specifies which edition is used by the parser.
535
536- **Default value**: `"2015"`
537- **Possible values**: `"2015"`, `"2018"`, `"2021"`
538- **Stable**: Yes
539
540Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
541through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
542in your config file:
543
544```toml
545edition = "2018"
546```
547
548## `empty_item_single_line`
549
550Put empty-body functions and impls on a single line
551
552- **Default value**: `true`
553- **Possible values**: `true`, `false`
a2a8927a 554- **Stable**: No (tracking issue: [#3356](https://github.com/rust-lang/rustfmt/issues/3356))
f20569fa
XL
555
556#### `true` (default):
557
558```rust
559fn lorem() {}
560
561impl Lorem {}
562```
563
564#### `false`:
565
566```rust
567fn lorem() {
568}
569
570impl Lorem {
571}
572```
573
574See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
575
576
577## `enum_discrim_align_threshold`
578
579The maximum length of enum variant having discriminant, that gets vertically aligned with others.
580Variants without discriminants would be ignored for the purpose of alignment.
581
582Note that this is not how much whitespace is inserted, but instead the longest variant name that
583doesn't get ignored when aligning.
584
585- **Default value** : 0
586- **Possible values**: any positive integer
a2a8927a 587- **Stable**: No (tracking issue: [#3372](https://github.com/rust-lang/rustfmt/issues/3372))
f20569fa
XL
588
589#### `0` (default):
590
591```rust
592enum Bar {
593 A = 0,
594 Bb = 1,
595 RandomLongVariantGoesHere = 10,
596 Ccc = 71,
597}
598
599enum Bar {
600 VeryLongVariantNameHereA = 0,
601 VeryLongVariantNameHereBb = 1,
602 VeryLongVariantNameHereCcc = 2,
603}
604```
605
606#### `20`:
607
608```rust
609enum Foo {
610 A = 0,
611 Bb = 1,
612 RandomLongVariantGoesHere = 10,
613 Ccc = 2,
614}
615
616enum Bar {
617 VeryLongVariantNameHereA = 0,
618 VeryLongVariantNameHereBb = 1,
619 VeryLongVariantNameHereCcc = 2,
620}
621```
622
623
624## `error_on_line_overflow`
625
626Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
627literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
628refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
629using a shorter name.
630
631- **Default value**: `false`
632- **Possible values**: `true`, `false`
a2a8927a 633- **Stable**: No (tracking issue: [#3391](https://github.com/rust-lang/rustfmt/issues/3391))
f20569fa
XL
634
635See also [`max_width`](#max_width).
636
637## `error_on_unformatted`
638
639Error if unable to get comments or string literals within `max_width`, or they are left with
640trailing whitespaces.
641
642- **Default value**: `false`
643- **Possible values**: `true`, `false`
a2a8927a 644- **Stable**: No (tracking issue: [#3392](https://github.com/rust-lang/rustfmt/issues/3392))
f20569fa
XL
645
646## `fn_args_layout`
647
648Control the layout of arguments in a function
649
650- **Default value**: `"Tall"`
651- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
652- **Stable**: Yes
653
654#### `"Tall"` (default):
655
656```rust
657trait Lorem {
658 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
659
660 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
661 // body
662 }
663
664 fn lorem(
665 ipsum: Ipsum,
666 dolor: Dolor,
667 sit: Sit,
668 amet: Amet,
669 consectetur: Consectetur,
670 adipiscing: Adipiscing,
671 elit: Elit,
672 );
673
674 fn lorem(
675 ipsum: Ipsum,
676 dolor: Dolor,
677 sit: Sit,
678 amet: Amet,
679 consectetur: Consectetur,
680 adipiscing: Adipiscing,
681 elit: Elit,
682 ) {
683 // body
684 }
685}
686```
687
688#### `"Compressed"`:
689
690```rust
691trait Lorem {
692 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
693
694 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
695 // body
696 }
697
698 fn lorem(
699 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
700 adipiscing: Adipiscing, elit: Elit,
701 );
702
703 fn lorem(
704 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
705 adipiscing: Adipiscing, elit: Elit,
706 ) {
707 // body
708 }
709}
710```
711
712#### `"Vertical"`:
713
714```rust
715trait Lorem {
716 fn lorem(
717 ipsum: Ipsum,
718 dolor: Dolor,
719 sit: Sit,
720 amet: Amet,
721 );
722
723 fn lorem(
724 ipsum: Ipsum,
725 dolor: Dolor,
726 sit: Sit,
727 amet: Amet,
728 ) {
729 // body
730 }
731
732 fn lorem(
733 ipsum: Ipsum,
734 dolor: Dolor,
735 sit: Sit,
736 amet: Amet,
737 consectetur: Consectetur,
738 adipiscing: Adipiscing,
739 elit: Elit,
740 );
741
742 fn lorem(
743 ipsum: Ipsum,
744 dolor: Dolor,
745 sit: Sit,
746 amet: Amet,
747 consectetur: Consectetur,
748 adipiscing: Adipiscing,
749 elit: Elit,
750 ) {
751 // body
752 }
753}
754```
755
136023e0 756## `fn_call_width`
cdc7bbd5
XL
757
758Maximum width of the args of a function call before falling back to vertical formatting.
759
760- **Default value**: `60`
761- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
762- **Stable**: Yes
763
136023e0 764By 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.
cdc7bbd5
XL
765
766See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
f20569fa
XL
767
768## `fn_single_line`
769
770Put single-expression functions on a single line
771
772- **Default value**: `false`
773- **Possible values**: `true`, `false`
a2a8927a 774- **Stable**: No (tracking issue: [#3358](https://github.com/rust-lang/rustfmt/issues/3358))
f20569fa
XL
775
776#### `false` (default):
777
778```rust
779fn lorem() -> usize {
780 42
781}
782
783fn lorem() -> usize {
784 let ipsum = 42;
785 ipsum
786}
787```
788
789#### `true`:
790
791```rust
792fn lorem() -> usize { 42 }
793
794fn lorem() -> usize {
795 let ipsum = 42;
796 ipsum
797}
798```
799
800See also [`control_brace_style`](#control_brace_style).
801
802
803## `force_explicit_abi`
804
805Always print the abi for extern items
806
807- **Default value**: `true`
808- **Possible values**: `true`, `false`
809- **Stable**: Yes
810
811**Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
812
813#### `true` (default):
814
815```rust
816extern "C" {
817 pub static lorem: c_int;
818}
819```
820
821#### `false`:
822
823```rust
824extern {
825 pub static lorem: c_int;
826}
827```
828
829## `force_multiline_blocks`
830
831Force multiline closure and match arm bodies to be wrapped in a block
832
833- **Default value**: `false`
834- **Possible values**: `false`, `true`
a2a8927a 835- **Stable**: No (tracking issue: [#3374](https://github.com/rust-lang/rustfmt/issues/3374))
f20569fa
XL
836
837#### `false` (default):
838
839```rust
840fn main() {
841 result.and_then(|maybe_value| match maybe_value {
842 None => foo(),
843 Some(value) => bar(),
844 });
845
846 match lorem {
847 None => |ipsum| {
848 println!("Hello World");
849 },
850 Some(dolor) => foo(),
851 }
852}
853```
854
855#### `true`:
856
857```rust
858fn main() {
859 result.and_then(|maybe_value| {
860 match maybe_value {
861 None => foo(),
862 Some(value) => bar(),
863 }
864 });
865
866 match lorem {
867 None => {
868 |ipsum| {
869 println!("Hello World");
870 }
871 }
872 Some(dolor) => foo(),
873 }
874}
875```
876
877
878## `format_code_in_doc_comments`
879
880Format code snippet included in doc comments.
881
882- **Default value**: `false`
883- **Possible values**: `true`, `false`
a2a8927a 884- **Stable**: No (tracking issue: [#3348](https://github.com/rust-lang/rustfmt/issues/3348))
f20569fa
XL
885
886#### `false` (default):
887
888```rust
889/// Adds one to the number given.
890///
891/// # Examples
892///
893/// ```rust
894/// let five=5;
895///
896/// assert_eq!(
897/// 6,
898/// add_one(5)
899/// );
900/// # fn add_one(x: i32) -> i32 {
901/// # x + 1
902/// # }
903/// ```
904fn add_one(x: i32) -> i32 {
905 x + 1
906}
907```
908
909#### `true`
910
911```rust
912/// Adds one to the number given.
913///
914/// # Examples
915///
916/// ```rust
917/// let five = 5;
918///
919/// assert_eq!(6, add_one(5));
920/// # fn add_one(x: i32) -> i32 {
921/// # x + 1
922/// # }
923/// ```
924fn add_one(x: i32) -> i32 {
925 x + 1
926}
927```
928
923072b8
FG
929## `doc_comment_code_block_width`
930
931Max width for code snippets included in doc comments. Only used if [`format_code_in_doc_comments`](#format_code_in_doc_comments) is true.
932
933- **Default value**: `100`
934- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
935- **Stable**: No (tracking issue: [#5359](https://github.com/rust-lang/rustfmt/issues/5359))
936
3c0e092e
XL
937## `format_generated_files`
938
939Format generated files. A file is considered generated
940if any of the first five lines contain a `@generated` comment marker.
5e7ed085
FG
941By default, generated files are reformatted, i. e. `@generated` marker is ignored.
942This option is currently ignored for stdin (`@generated` in stdin is ignored.)
3c0e092e
XL
943
944- **Default value**: `true`
945- **Possible values**: `true`, `false`
a2a8927a 946- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))
3c0e092e 947
f20569fa
XL
948## `format_macro_matchers`
949
950Format the metavariable matching patterns in macros.
951
952- **Default value**: `false`
953- **Possible values**: `true`, `false`
a2a8927a 954- **Stable**: No (tracking issue: [#3354](https://github.com/rust-lang/rustfmt/issues/3354))
f20569fa
XL
955
956#### `false` (default):
957
958```rust
959macro_rules! foo {
960 ($a: ident : $b: ty) => {
961 $a(42): $b;
962 };
963 ($a: ident $b: ident $c: ident) => {
964 $a = $b + $c;
965 };
966}
967```
968
969#### `true`:
970
971```rust
972macro_rules! foo {
973 ($a:ident : $b:ty) => {
974 $a(42): $b;
975 };
976 ($a:ident $b:ident $c:ident) => {
977 $a = $b + $c;
978 };
979}
980```
981
982See also [`format_macro_bodies`](#format_macro_bodies).
983
984
985## `format_macro_bodies`
986
987Format the bodies of macros.
988
989- **Default value**: `true`
990- **Possible values**: `true`, `false`
a2a8927a 991- **Stable**: No (tracking issue: [#3355](https://github.com/rust-lang/rustfmt/issues/3355))
f20569fa
XL
992
993#### `true` (default):
994
995```rust
996macro_rules! foo {
997 ($a: ident : $b: ty) => {
998 $a(42): $b;
999 };
1000 ($a: ident $b: ident $c: ident) => {
1001 $a = $b + $c;
1002 };
1003}
1004```
1005
1006#### `false`:
1007
1008```rust
1009macro_rules! foo {
1010 ($a: ident : $b: ty) => { $a(42): $b; };
1011 ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
1012}
1013```
1014
1015See also [`format_macro_matchers`](#format_macro_matchers).
1016
1017
1018## `format_strings`
1019
1020Format string literals where necessary
1021
1022- **Default value**: `false`
1023- **Possible values**: `true`, `false`
a2a8927a 1024- **Stable**: No (tracking issue: [#3353](https://github.com/rust-lang/rustfmt/issues/3353))
f20569fa
XL
1025
1026#### `false` (default):
1027
1028```rust
1029fn main() {
1030 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
1031}
1032```
1033
1034#### `true`:
1035
1036```rust
1037fn main() {
1038 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
1039 consectetur adipiscing";
1040}
1041```
1042
1043See also [`max_width`](#max_width).
1044
1045## `hard_tabs`
1046
1047Use tab characters for indentation, spaces for alignment
1048
1049- **Default value**: `false`
1050- **Possible values**: `true`, `false`
1051- **Stable**: Yes
1052
1053#### `false` (default):
1054
1055```rust
1056fn lorem() -> usize {
1057 42 // spaces before 42
1058}
1059```
1060
1061#### `true`:
1062
1063```rust
1064fn lorem() -> usize {
1065 42 // tabs before 42
1066}
1067```
1068
1069See also: [`tab_spaces`](#tab_spaces).
1070
3c0e092e
XL
1071## `hex_literal_case`
1072
1073Control the case of the letters in hexadecimal literal values
1074
1075- **Default value**: `Preserve`
923072b8 1076- **Possible values**: `Preserve`, `Upper`, `Lower`
a2a8927a 1077- **Stable**: No (tracking issue: [#5081](https://github.com/rust-lang/rustfmt/issues/5081))
f20569fa
XL
1078
1079## `hide_parse_errors`
1080
1081Do not show parse errors if the parser failed to parse files.
1082
1083- **Default value**: `false`
1084- **Possible values**: `true`, `false`
a2a8927a 1085- **Stable**: No (tracking issue: [#3390](https://github.com/rust-lang/rustfmt/issues/3390))
f20569fa
XL
1086
1087## `ignore`
1088
1089Skip formatting files and directories that match the specified pattern.
1090The pattern format is the same as [.gitignore](https://git-scm.com/docs/gitignore#_pattern_format). Be sure to use Unix/forwardslash `/` style paths. This path style will work on all platforms. Windows style paths with backslashes `\` are not supported.
1091
1092- **Default value**: format every file
1093- **Possible values**: See an example below
a2a8927a 1094- **Stable**: No (tracking issue: [#3395](https://github.com/rust-lang/rustfmt/issues/3395))
f20569fa
XL
1095
1096### Example
1097
1098If you want to ignore specific files, put the following to your config file:
1099
1100```toml
1101ignore = [
1102 "src/types.rs",
1103 "src/foo/bar.rs",
1104]
1105```
1106
1107If you want to ignore every file under `examples/`, put the following to your config file:
1108
1109```toml
1110ignore = [
1111 "examples",
1112]
1113```
1114
1115If you want to ignore every file under the directory where you put your rustfmt.toml:
1116
1117```toml
1118ignore = ["/"]
1119```
1120
1121## `imports_indent`
1122
1123Indent style of imports
1124
1125- **Default Value**: `"Block"`
1126- **Possible values**: `"Block"`, `"Visual"`
a2a8927a 1127- **Stable**: No (tracking issue: [#3360](https://github.com/rust-lang/rustfmt/issues/3360))
f20569fa
XL
1128
1129#### `"Block"` (default):
1130
1131```rust
1132use foo::{
1133 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1134 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1135};
1136```
1137
1138#### `"Visual"`:
1139
1140```rust
1141use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1142 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1143```
1144
1145See also: [`imports_layout`](#imports_layout).
1146
1147## `imports_layout`
1148
1149Item layout inside a imports block
1150
1151- **Default value**: "Mixed"
1152- **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
a2a8927a 1153- **Stable**: No (tracking issue: [#3361](https://github.com/rust-lang/rustfmt/issues/3361))
f20569fa
XL
1154
1155#### `"Mixed"` (default):
1156
1157```rust
1158use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1159
1160use foo::{
1161 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1162 eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1163};
1164```
1165
1166#### `"Horizontal"`:
1167
1168**Note**: This option forces all imports onto one line and may exceed `max_width`.
1169
1170```rust
1171use foo::{xxx, yyy, zzz};
1172
1173use foo::{aaa, bbb, ccc, ddd, eee, fff};
1174```
1175
1176#### `"HorizontalVertical"`:
1177
1178```rust
1179use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1180
1181use foo::{
1182 aaaaaaaaaaaaaaaaaa,
1183 bbbbbbbbbbbbbbbbbb,
1184 cccccccccccccccccc,
1185 dddddddddddddddddd,
1186 eeeeeeeeeeeeeeeeee,
1187 ffffffffffffffffff,
1188};
1189```
1190
1191#### `"Vertical"`:
1192
1193```rust
1194use foo::{
1195 xxx,
1196 yyy,
1197 zzz,
1198};
1199
1200use foo::{
1201 aaa,
1202 bbb,
1203 ccc,
1204 ddd,
1205 eee,
1206 fff,
1207};
1208```
1209
1210## `indent_style`
1211
1212Indent on expressions or items.
1213
1214- **Default value**: `"Block"`
1215- **Possible values**: `"Block"`, `"Visual"`
a2a8927a 1216- **Stable**: No (tracking issue: [#3346](https://github.com/rust-lang/rustfmt/issues/3346))
f20569fa
XL
1217
1218### Array
1219
1220#### `"Block"` (default):
1221
1222```rust
1223fn main() {
1224 let lorem = vec![
1225 "ipsum",
1226 "dolor",
1227 "sit",
1228 "amet",
1229 "consectetur",
1230 "adipiscing",
1231 "elit",
1232 ];
1233}
1234```
1235
1236#### `"Visual"`:
1237
1238```rust
1239fn main() {
1240 let lorem = vec!["ipsum",
1241 "dolor",
1242 "sit",
1243 "amet",
1244 "consectetur",
1245 "adipiscing",
1246 "elit"];
1247}
1248```
1249
1250### Control flow
1251
1252#### `"Block"` (default):
1253
1254```rust
1255fn main() {
1256 if lorem_ipsum
1257 && dolor_sit
1258 && amet_consectetur
1259 && lorem_sit
1260 && dolor_consectetur
1261 && amet_ipsum
1262 && lorem_consectetur
1263 {
1264 // ...
1265 }
1266}
1267```
1268
1269#### `"Visual"`:
1270
1271```rust
1272fn main() {
1273 if lorem_ipsum
1274 && dolor_sit
1275 && amet_consectetur
1276 && lorem_sit
1277 && dolor_consectetur
1278 && amet_ipsum
1279 && lorem_consectetur
1280 {
1281 // ...
1282 }
1283}
1284```
1285
1286See also: [`control_brace_style`](#control_brace_style).
1287
1288### Function arguments
1289
1290#### `"Block"` (default):
1291
1292```rust
1293fn lorem() {}
1294
1295fn lorem(ipsum: usize) {}
1296
1297fn lorem(
1298 ipsum: usize,
1299 dolor: usize,
1300 sit: usize,
1301 amet: usize,
1302 consectetur: usize,
1303 adipiscing: usize,
1304 elit: usize,
1305) {
1306 // body
1307}
1308```
1309
1310#### `"Visual"`:
1311
1312```rust
1313fn lorem() {}
1314
1315fn lorem(ipsum: usize) {}
1316
1317fn lorem(ipsum: usize,
1318 dolor: usize,
1319 sit: usize,
1320 amet: usize,
1321 consectetur: usize,
1322 adipiscing: usize,
1323 elit: usize) {
1324 // body
1325}
1326```
1327
1328### Function calls
1329
1330#### `"Block"` (default):
1331
1332```rust
1333fn main() {
1334 lorem(
1335 "lorem",
1336 "ipsum",
1337 "dolor",
1338 "sit",
1339 "amet",
1340 "consectetur",
1341 "adipiscing",
1342 "elit",
1343 );
1344}
1345```
1346
1347#### `"Visual"`:
1348
1349```rust
1350fn main() {
1351 lorem("lorem",
1352 "ipsum",
1353 "dolor",
1354 "sit",
1355 "amet",
1356 "consectetur",
1357 "adipiscing",
1358 "elit");
1359}
1360```
1361
1362### Generics
1363
1364#### `"Block"` (default):
1365
1366```rust
1367fn lorem<
1368 Ipsum: Eq = usize,
1369 Dolor: Eq = usize,
1370 Sit: Eq = usize,
1371 Amet: Eq = usize,
1372 Adipiscing: Eq = usize,
1373 Consectetur: Eq = usize,
1374 Elit: Eq = usize,
1375>(
1376 ipsum: Ipsum,
1377 dolor: Dolor,
1378 sit: Sit,
1379 amet: Amet,
1380 adipiscing: Adipiscing,
1381 consectetur: Consectetur,
1382 elit: Elit,
1383) -> T {
1384 // body
1385}
1386```
1387
1388#### `"Visual"`:
1389
1390```rust
1391fn lorem<Ipsum: Eq = usize,
1392 Dolor: Eq = usize,
1393 Sit: Eq = usize,
1394 Amet: Eq = usize,
1395 Adipiscing: Eq = usize,
1396 Consectetur: Eq = usize,
1397 Elit: Eq = usize>(
1398 ipsum: Ipsum,
1399 dolor: Dolor,
1400 sit: Sit,
1401 amet: Amet,
1402 adipiscing: Adipiscing,
1403 consectetur: Consectetur,
1404 elit: Elit)
1405 -> T {
1406 // body
1407}
1408```
1409
1410#### Struct
1411
1412#### `"Block"` (default):
1413
1414```rust
1415fn main() {
1416 let lorem = Lorem {
1417 ipsum: dolor,
1418 sit: amet,
1419 };
1420}
1421```
1422
1423#### `"Visual"`:
1424
1425```rust
1426fn main() {
1427 let lorem = Lorem { ipsum: dolor,
1428 sit: amet };
1429}
1430```
1431
1432See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
1433
1434### Where predicates
1435
1436#### `"Block"` (default):
1437
1438```rust
1439fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1440where
1441 Ipsum: Eq,
1442 Dolor: Eq,
1443 Sit: Eq,
1444 Amet: Eq,
1445{
1446 // body
1447}
1448```
1449
1450#### `"Visual"`:
1451
1452```rust
1453fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1454 where Ipsum: Eq,
1455 Dolor: Eq,
1456 Sit: Eq,
1457 Amet: Eq
1458{
1459 // body
1460}
1461```
1462
1463## `inline_attribute_width`
1464
1465Write an item and its attribute on the same line if their combined width is below a threshold
1466
1467- **Default value**: 0
1468- **Possible values**: any positive integer
a2a8927a 1469- **Stable**: No (tracking issue: [#3343](https://github.com/rust-lang/rustfmt/issues/3343))
f20569fa
XL
1470
1471### Example
1472
1473#### `0` (default):
1474```rust
1475#[cfg(feature = "alloc")]
1476use core::slice;
1477```
1478
1479#### `50`:
1480```rust
1481#[cfg(feature = "alloc")] use core::slice;
1482```
1483
f20569fa
XL
1484## `match_arm_blocks`
1485
94222f64
XL
1486Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.
1487
1488The Style Guide requires that bodies are block wrapped by default if a line break is required after the `=>`, but this option can be used to disable that behavior to prevent wrapping arm bodies in that event, so long as the body does not contain multiple statements nor line comments.
f20569fa
XL
1489
1490- **Default value**: `true`
1491- **Possible values**: `true`, `false`
a2a8927a 1492- **Stable**: No (tracking issue: [#3373](https://github.com/rust-lang/rustfmt/issues/3373))
f20569fa
XL
1493
1494#### `true` (default):
1495
1496```rust
1497fn main() {
1498 match lorem {
94222f64 1499 ipsum => {
f20569fa
XL
1500 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1501 }
94222f64
XL
1502 dolor => println!("{}", sit),
1503 sit => foo(
1504 "foooooooooooooooooooooooo",
1505 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1506 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1507 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1508 ),
f20569fa
XL
1509 }
1510}
1511```
1512
1513#### `false`:
1514
1515```rust
1516fn main() {
1517 match lorem {
94222f64 1518 lorem =>
f20569fa 1519 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
94222f64
XL
1520 ipsum => println!("{}", sit),
1521 sit => foo(
1522 "foooooooooooooooooooooooo",
1523 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1524 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1525 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1526 ),
f20569fa
XL
1527 }
1528}
1529```
1530
1531See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1532
1533## `match_arm_leading_pipes`
1534
1535Controls whether to include a leading pipe on match arms
1536
1537- **Default value**: `Never`
1538- **Possible values**: `Always`, `Never`, `Preserve`
1539- **Stable**: Yes
1540
1541#### `Never` (default):
1542```rust
1543// Leading pipes are removed from this:
1544// fn foo() {
1545// match foo {
1546// | "foo" | "bar" => {}
1547// | "baz"
1548// | "something relatively long"
1549// | "something really really really realllllllllllllly long" => println!("x"),
1550// | "qux" => println!("y"),
1551// _ => {}
1552// }
1553// }
1554
1555// Becomes
1556fn foo() {
1557 match foo {
1558 "foo" | "bar" => {}
1559 "baz"
1560 | "something relatively long"
1561 | "something really really really realllllllllllllly long" => println!("x"),
1562 "qux" => println!("y"),
1563 _ => {}
1564 }
1565}
1566```
1567
1568#### `Always`:
1569```rust
1570// Leading pipes are emitted on all arms of this:
1571// fn foo() {
1572// match foo {
1573// "foo" | "bar" => {}
1574// "baz"
1575// | "something relatively long"
1576// | "something really really really realllllllllllllly long" => println!("x"),
1577// "qux" => println!("y"),
1578// _ => {}
1579// }
1580// }
1581
1582// Becomes:
1583fn foo() {
1584 match foo {
1585 | "foo" | "bar" => {}
1586 | "baz"
1587 | "something relatively long"
1588 | "something really really really realllllllllllllly long" => println!("x"),
1589 | "qux" => println!("y"),
1590 | _ => {}
1591 }
1592}
1593```
1594
1595#### `Preserve`:
1596```rust
1597fn foo() {
1598 match foo {
1599 | "foo" | "bar" => {}
1600 | "baz"
1601 | "something relatively long"
1602 | "something really really really realllllllllllllly long" => println!("x"),
1603 | "qux" => println!("y"),
1604 _ => {}
1605 }
1606
1607 match baz {
1608 "qux" => {}
1609 "foo" | "bar" => {}
1610 _ => {}
1611 }
1612}
1613```
1614
1615## `match_block_trailing_comma`
1616
1617Put a trailing comma after a block based match arm (non-block arms are not affected)
1618
1619- **Default value**: `false`
1620- **Possible values**: `true`, `false`
3c0e092e 1621- **Stable**: Yes
f20569fa
XL
1622
1623#### `false` (default):
1624
1625```rust
1626fn main() {
1627 match lorem {
1628 Lorem::Ipsum => {
1629 println!("ipsum");
1630 }
1631 Lorem::Dolor => println!("dolor"),
1632 }
1633}
1634```
1635
1636#### `true`:
1637
1638```rust
1639fn main() {
1640 match lorem {
1641 Lorem::Ipsum => {
1642 println!("ipsum");
1643 },
1644 Lorem::Dolor => println!("dolor"),
1645 }
1646}
1647```
1648
1649See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1650
1651## `max_width`
1652
1653Maximum width of each line
1654
1655- **Default value**: `100`
1656- **Possible values**: any positive integer
1657- **Stable**: Yes
1658
1659See also [`error_on_line_overflow`](#error_on_line_overflow).
1660
1661## `merge_derives`
1662
1663Merge multiple derives into a single one.
1664
1665- **Default value**: `true`
1666- **Possible values**: `true`, `false`
1667- **Stable**: Yes
1668
1669#### `true` (default):
1670
1671```rust
1672#[derive(Eq, PartialEq, Debug, Copy, Clone)]
1673pub enum Foo {}
1674```
1675
1676#### `false`:
1677
1678```rust
3c0e092e
XL
1679#[derive(Eq, PartialEq, Debug, Copy, Clone)]
1680pub enum Bar {}
1681
f20569fa
XL
1682#[derive(Eq, PartialEq)]
1683#[derive(Debug)]
1684#[derive(Copy, Clone)]
1685pub enum Foo {}
1686```
1687
1688## `imports_granularity`
1689
1690How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
1691
1692- **Default value**: `Preserve`
3c0e092e 1693- **Possible values**: `Preserve`, `Crate`, `Module`, `Item`, `One`
a2a8927a 1694- **Stable**: No (tracking issue: [#4991](https://github.com/rust-lang/rustfmt/issues/4991))
f20569fa 1695
923072b8
FG
1696Note that rustfmt will not modify the granularity of imports containing comments if doing so could potentially lose or misplace said comments.
1697
f20569fa
XL
1698#### `Preserve` (default):
1699
1700Do not change the granularity of any imports and preserve the original structure written by the developer.
1701
1702```rust
1703use foo::b;
1704use foo::b::{f, g};
1705use foo::{a, c, d::e};
1706use qux::{h, i};
1707```
1708
1709#### `Crate`:
1710
1711Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements.
1712
1713```rust
1714use foo::{
1715 a, b,
1716 b::{f, g},
1717 c,
1718 d::e,
1719};
1720use qux::{h, i};
1721```
1722
1723#### `Module`:
1724
1725Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements.
1726
1727```rust
1728use foo::b::{f, g};
1729use foo::d::e;
1730use foo::{a, b, c};
1731use qux::{h, i};
1732```
1733
1734#### `Item`:
1735
1736Flatten imports so that each has its own `use` statement.
1737
1738```rust
1739use foo::a;
1740use foo::b;
1741use foo::b::f;
1742use foo::b::g;
1743use foo::c;
1744use foo::d::e;
1745use qux::h;
1746use qux::i;
1747```
1748
3c0e092e
XL
1749#### `One`:
1750
1751Merge all imports into a single `use` statement as long as they have the same visibility.
1752
1753```rust
1754pub use foo::{x, y};
1755use {
1756 bar::{
1757 a,
1758 b::{self, f, g},
1759 c,
1760 d::e,
1761 },
1762 qux::{h, i},
1763};
1764```
1765
f20569fa
XL
1766## `merge_imports`
1767
1768This option is deprecated. Use `imports_granularity = "Crate"` instead.
1769
1770- **Default value**: `false`
1771- **Possible values**: `true`, `false`
1772
1773#### `false` (default):
1774
1775```rust
1776use foo::{a, c, d};
1777use foo::{b, g};
1778use foo::{e, f};
1779```
1780
1781#### `true`:
1782
1783```rust
1784use foo::{a, b, c, d, e, f, g};
1785```
1786
1787
1788## `newline_style`
1789
1790Unix or Windows line endings
1791
1792- **Default value**: `"Auto"`
1793- **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1794- **Stable**: Yes
1795
1796#### `Auto` (default):
1797
1798The newline style is detected automatically on a per-file basis. Files
1799with mixed line endings will be converted to the first detected line
1800ending style.
1801
1802#### `Native`
1803
1804Line endings will be converted to `\r\n` on Windows and `\n` on all
1805other platforms.
1806
1807#### `Unix`
1808
1809Line endings will be converted to `\n`.
1810
1811#### `Windows`
1812
1813Line endings will be converted to `\r\n`.
1814
1815## `normalize_comments`
1816
1817Convert /* */ comments to // comments where possible
1818
1819- **Default value**: `false`
1820- **Possible values**: `true`, `false`
a2a8927a 1821- **Stable**: No (tracking issue: [#3350](https://github.com/rust-lang/rustfmt/issues/3350))
f20569fa
XL
1822
1823#### `false` (default):
1824
1825```rust
1826// Lorem ipsum:
1827fn dolor() -> usize {}
1828
1829/* sit amet: */
1830fn adipiscing() -> usize {}
1831```
1832
1833#### `true`:
1834
1835```rust
1836// Lorem ipsum:
1837fn dolor() -> usize {}
1838
1839// sit amet:
1840fn adipiscing() -> usize {}
1841```
1842
1843## `normalize_doc_attributes`
1844
1845Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1846
1847- **Default value**: `false`
1848- **Possible values**: `true`, `false`
a2a8927a 1849- **Stable**: No (tracking issue: [#3351](https://github.com/rust-lang/rustfmt/issues/3351))
f20569fa
XL
1850
1851#### `false` (default):
1852
1853```rust
1854#![doc = "Example documentation"]
1855
1856#[doc = "Example item documentation"]
3c0e092e
XL
1857pub enum Bar {}
1858
1859/// Example item documentation
f20569fa
XL
1860pub enum Foo {}
1861```
1862
1863#### `true`:
1864
1865```rust
1866//! Example documentation
1867
1868/// Example item documentation
1869pub enum Foo {}
1870```
1871
1872## `overflow_delimited_expr`
1873
1874When structs, slices, arrays, and block/array-like macros are used as the last
1875argument in an expression list, allow them to overflow (like blocks/closures)
1876instead of being indented on a new line.
1877
1878- **Default value**: `false`
1879- **Possible values**: `true`, `false`
a2a8927a 1880- **Stable**: No (tracking issue: [#3370](https://github.com/rust-lang/rustfmt/issues/3370))
f20569fa
XL
1881
1882#### `false` (default):
1883
1884```rust
1885fn example() {
1886 foo(ctx, |param| {
1887 action();
1888 foo(param)
1889 });
1890
1891 foo(
1892 ctx,
1893 Bar {
1894 x: value,
1895 y: value2,
1896 },
1897 );
1898
1899 foo(
1900 ctx,
1901 &[
1902 MAROON_TOMATOES,
1903 PURPLE_POTATOES,
1904 ORGANE_ORANGES,
1905 GREEN_PEARS,
1906 RED_APPLES,
1907 ],
1908 );
1909
1910 foo(
1911 ctx,
1912 vec![
1913 MAROON_TOMATOES,
1914 PURPLE_POTATOES,
1915 ORGANE_ORANGES,
1916 GREEN_PEARS,
1917 RED_APPLES,
1918 ],
1919 );
1920}
1921```
1922
1923#### `true`:
1924
1925```rust
1926fn example() {
1927 foo(ctx, |param| {
1928 action();
1929 foo(param)
1930 });
1931
1932 foo(ctx, Bar {
1933 x: value,
1934 y: value2,
1935 });
1936
1937 foo(ctx, &[
1938 MAROON_TOMATOES,
1939 PURPLE_POTATOES,
1940 ORGANE_ORANGES,
1941 GREEN_PEARS,
1942 RED_APPLES,
1943 ]);
1944
1945 foo(ctx, vec![
1946 MAROON_TOMATOES,
1947 PURPLE_POTATOES,
1948 ORGANE_ORANGES,
1949 GREEN_PEARS,
1950 RED_APPLES,
1951 ]);
1952}
1953```
1954
1955## `remove_nested_parens`
1956
1957Remove nested parens.
1958
1959- **Default value**: `true`,
1960- **Possible values**: `true`, `false`
1961- **Stable**: Yes
1962
1963
1964#### `true` (default):
1965```rust
1966fn main() {
1967 (foo());
1968}
1969```
1970
1971#### `false`:
1972```rust
1973fn main() {
3c0e092e
XL
1974 (foo());
1975
f20569fa
XL
1976 ((((foo()))));
1977}
1978```
1979
1980
1981## `reorder_impl_items`
1982
1983Reorder impl items. `type` and `const` are put first, then macros and methods.
1984
1985- **Default value**: `false`
1986- **Possible values**: `true`, `false`
a2a8927a 1987- **Stable**: No (tracking issue: [#3363](https://github.com/rust-lang/rustfmt/issues/3363))
f20569fa
XL
1988
1989#### `false` (default)
1990
1991```rust
1992struct Dummy;
1993
1994impl Iterator for Dummy {
1995 fn next(&mut self) -> Option<Self::Item> {
1996 None
1997 }
1998
1999 type Item = i32;
2000}
3c0e092e
XL
2001
2002impl Iterator for Dummy {
2003 type Item = i32;
2004
2005 fn next(&mut self) -> Option<Self::Item> {
2006 None
2007 }
2008}
f20569fa
XL
2009```
2010
2011#### `true`
2012
2013```rust
2014struct Dummy;
2015
2016impl Iterator for Dummy {
2017 type Item = i32;
2018
2019 fn next(&mut self) -> Option<Self::Item> {
2020 None
2021 }
2022}
2023```
2024
2025## `reorder_imports`
2026
2027Reorder import and extern crate statements alphabetically in groups (a group is
2028separated by a newline).
2029
2030- **Default value**: `true`
2031- **Possible values**: `true`, `false`
2032- **Stable**: Yes
2033
2034#### `true` (default):
2035
2036```rust
2037use dolor;
2038use ipsum;
2039use lorem;
2040use sit;
2041```
2042
2043#### `false`:
2044
2045```rust
2046use lorem;
2047use ipsum;
2048use dolor;
2049use sit;
2050```
2051
2052## `group_imports`
2053
923072b8
FG
2054Controls the strategy for how consecutive imports are grouped together.
2055
2056Controls the strategy for grouping sets of consecutive imports. Imports may contain newlines between imports and still be grouped together as a single set, but other statements between imports will result in different grouping sets.
f20569fa
XL
2057
2058- **Default value**: `Preserve`
3c0e092e 2059- **Possible values**: `Preserve`, `StdExternalCrate`, `One`
a2a8927a 2060- **Stable**: No (tracking issue: [#5083](https://github.com/rust-lang/rustfmt/issues/5083))
f20569fa 2061
923072b8
FG
2062Each set of imports (one or more `use` statements, optionally separated by newlines) will be formatted independently. Other statements such as `mod ...` or `extern crate ...` will cause imports to not be grouped together.
2063
f20569fa
XL
2064#### `Preserve` (default):
2065
2066Preserve the source file's import groups.
2067
2068```rust
2069use super::update::convert_publish_payload;
2070use chrono::Utc;
2071
2072use alloc::alloc::Layout;
2073use juniper::{FieldError, FieldResult};
2074use uuid::Uuid;
2075
2076use std::sync::Arc;
2077
2078use broker::database::PooledConnection;
2079
2080use super::schema::{Context, Payload};
2081use crate::models::Event;
2082use core::f32;
2083```
2084
2085#### `StdExternalCrate`:
2086
2087Discard existing import groups, and create three groups for:
20881. `std`, `core` and `alloc`,
20892. external crates,
20903. `self`, `super` and `crate` imports.
2091
2092```rust
2093use alloc::alloc::Layout;
2094use core::f32;
2095use std::sync::Arc;
2096
2097use broker::database::PooledConnection;
2098use chrono::Utc;
2099use juniper::{FieldError, FieldResult};
2100use uuid::Uuid;
2101
2102use super::schema::{Context, Payload};
2103use super::update::convert_publish_payload;
2104use crate::models::Event;
2105```
2106
3c0e092e
XL
2107#### `One`:
2108
2109Discard existing import groups, and create a single group for everything
2110
2111```rust
2112use super::schema::{Context, Payload};
2113use super::update::convert_publish_payload;
2114use crate::models::Event;
2115use alloc::alloc::Layout;
2116use broker::database::PooledConnection;
2117use chrono::Utc;
2118use core::f32;
2119use juniper::{FieldError, FieldResult};
2120use std::sync::Arc;
2121use uuid::Uuid;
2122```
2123
f20569fa
XL
2124## `reorder_modules`
2125
2126Reorder `mod` declarations alphabetically in group.
2127
2128- **Default value**: `true`
2129- **Possible values**: `true`, `false`
2130- **Stable**: Yes
2131
2132#### `true` (default)
2133
2134```rust
2135mod a;
2136mod b;
2137
2138mod dolor;
2139mod ipsum;
2140mod lorem;
2141mod sit;
2142```
2143
2144#### `false`
2145
2146```rust
2147mod b;
2148mod a;
2149
2150mod lorem;
2151mod ipsum;
2152mod dolor;
2153mod sit;
2154```
2155
2156**Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
2157of the original source code.
2158
f20569fa
XL
2159## `required_version`
2160
2161Require a specific version of rustfmt. If you want to make sure that the
2162specific version of rustfmt is used in your CI, use this option.
2163
2164- **Default value**: `CARGO_PKG_VERSION`
2165- **Possible values**: any published version (e.g. `"0.3.8"`)
a2a8927a 2166- **Stable**: No (tracking issue: [#3386](https://github.com/rust-lang/rustfmt/issues/3386))
f20569fa 2167
5e7ed085
FG
2168## `short_array_element_width_threshold`
2169
2170The width threshold for an array element to be considered "short".
2171
2172The layout of an array is dependent on the length of each of its elements.
2173If the length of every element in an array is below this threshold (all elements are "short") then the array can be formatted in the mixed/compressed style, but if any one element has a length that exceeds this threshold then the array elements will have to be formatted vertically.
2174
2175- **Default value**: `10`
2176- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2177- **Stable**: Yes
2178
2179#### `10` (default):
2180```rust
2181fn main() {
2182 pub const FORMAT_TEST: [u64; 5] = [
2183 0x0000000000000000,
2184 0xaaaaaaaaaaaaaaaa,
2185 0xbbbbbbbbbbbbbbbb,
2186 0xcccccccccccccccc,
2187 0xdddddddddddddddd,
2188 ];
2189}
2190```
2191#### `20`:
2192```rust
2193fn main() {
2194 pub const FORMAT_TEST: [u64; 5] = [
2195 0x0000000000000000, 0xaaaaaaaaaaaaaaaa, 0xbbbbbbbbbbbbbbbb, 0xcccccccccccccccc,
2196 0xdddddddddddddddd,
2197 ];
2198}
2199```
2200See also [`max_width`](#max_width).
2201
f20569fa
XL
2202## `skip_children`
2203
2204Don't reformat out of line modules
2205
2206- **Default value**: `false`
2207- **Possible values**: `true`, `false`
5e7ed085 2208- **Stable**: No (tracking issue: [#3389](https://github.com/rust-lang/rustfmt/issues/3389))
f20569fa 2209
136023e0 2210## `single_line_if_else_max_width`
cdc7bbd5
XL
2211
2212Maximum 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`.
2213
2214- **Default value**: `50`
2215- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2216- **Stable**: Yes
2217
136023e0 2218By 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.
cdc7bbd5
XL
2219
2220See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2221
f20569fa
XL
2222## `space_after_colon`
2223
2224Leave a space after the colon.
2225
2226- **Default value**: `true`
2227- **Possible values**: `true`, `false`
a2a8927a 2228- **Stable**: No (tracking issue: [#3366](https://github.com/rust-lang/rustfmt/issues/3366))
f20569fa
XL
2229
2230#### `true` (default):
2231
2232```rust
2233fn lorem<T: Eq>(t: T) {
2234 let lorem: Dolor = Lorem {
2235 ipsum: dolor,
2236 sit: amet,
2237 };
2238}
2239```
2240
2241#### `false`:
2242
2243```rust
2244fn lorem<T:Eq>(t:T) {
2245 let lorem:Dolor = Lorem {
2246 ipsum:dolor,
2247 sit:amet,
2248 };
2249}
2250```
2251
2252See also: [`space_before_colon`](#space_before_colon).
2253
2254## `space_before_colon`
2255
2256Leave a space before the colon.
2257
2258- **Default value**: `false`
2259- **Possible values**: `true`, `false`
a2a8927a 2260- **Stable**: No (tracking issue: [#3365](https://github.com/rust-lang/rustfmt/issues/3365))
f20569fa
XL
2261
2262#### `false` (default):
2263
2264```rust
2265fn lorem<T: Eq>(t: T) {
2266 let lorem: Dolor = Lorem {
2267 ipsum: dolor,
2268 sit: amet,
2269 };
2270}
2271```
2272
2273#### `true`:
2274
2275```rust
2276fn lorem<T : Eq>(t : T) {
2277 let lorem : Dolor = Lorem {
2278 ipsum : dolor,
2279 sit : amet,
2280 };
2281}
2282```
2283
2284See also: [`space_after_colon`](#space_after_colon).
2285
2286## `spaces_around_ranges`
2287
2288Put spaces around the .., ..=, and ... range operators
2289
2290- **Default value**: `false`
2291- **Possible values**: `true`, `false`
a2a8927a 2292- **Stable**: No (tracking issue: [#3367](https://github.com/rust-lang/rustfmt/issues/3367))
f20569fa
XL
2293
2294#### `false` (default):
2295
2296```rust
2297fn main() {
2298 let lorem = 0..10;
2299 let ipsum = 0..=10;
2300
2301 match lorem {
2302 1..5 => foo(),
2303 _ => bar,
2304 }
2305
2306 match lorem {
2307 1..=5 => foo(),
2308 _ => bar,
2309 }
2310
2311 match lorem {
2312 1...5 => foo(),
2313 _ => bar,
2314 }
2315}
2316```
2317
2318#### `true`:
2319
2320```rust
2321fn main() {
2322 let lorem = 0 .. 10;
2323 let ipsum = 0 ..= 10;
2324
2325 match lorem {
2326 1 .. 5 => foo(),
2327 _ => bar,
2328 }
2329
2330 match lorem {
2331 1 ..= 5 => foo(),
2332 _ => bar,
2333 }
2334
2335 match lorem {
2336 1 ... 5 => foo(),
2337 _ => bar,
2338 }
2339}
2340```
2341
2342## `struct_field_align_threshold`
2343
2344The maximum diff of width between struct fields to be aligned with each other.
2345
2346- **Default value** : 0
2347- **Possible values**: any non-negative integer
a2a8927a 2348- **Stable**: No (tracking issue: [#3371](https://github.com/rust-lang/rustfmt/issues/3371))
f20569fa
XL
2349
2350#### `0` (default):
2351
2352```rust
2353struct Foo {
2354 x: u32,
2355 yy: u32,
2356 zzz: u32,
2357}
2358```
2359
2360#### `20`:
2361
2362```rust
2363struct Foo {
2364 x: u32,
2365 yy: u32,
2366 zzz: u32,
2367}
2368```
2369
2370## `struct_lit_single_line`
2371
2372Put small struct literals on a single line
2373
2374- **Default value**: `true`
2375- **Possible values**: `true`, `false`
a2a8927a 2376- **Stable**: No (tracking issue: [#3357](https://github.com/rust-lang/rustfmt/issues/3357))
f20569fa
XL
2377
2378#### `true` (default):
2379
2380```rust
2381fn main() {
2382 let lorem = Lorem { foo: bar, baz: ofo };
2383}
2384```
2385
2386#### `false`:
2387
2388```rust
2389fn main() {
2390 let lorem = Lorem {
2391 foo: bar,
2392 baz: ofo,
2393 };
2394}
2395```
2396
2397See also: [`indent_style`](#indent_style).
2398
136023e0 2399## `struct_lit_width`
cdc7bbd5
XL
2400
2401Maximum 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`.
2402
2403- **Default value**: `18`
2404- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2405- **Stable**: Yes
2406
136023e0 2407By 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.
cdc7bbd5
XL
2408
2409See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2410
136023e0 2411## `struct_variant_width`
cdc7bbd5
XL
2412
2413Maximum 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`.
2414
2415- **Default value**: `35`
2416- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2417- **Stable**: Yes
2418
136023e0 2419By 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.
cdc7bbd5
XL
2420
2421See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
f20569fa
XL
2422
2423## `tab_spaces`
2424
2425Number of spaces per tab
2426
2427- **Default value**: `4`
2428- **Possible values**: any positive integer
2429- **Stable**: Yes
2430
2431#### `4` (default):
2432
2433```rust
2434fn lorem() {
2435 let ipsum = dolor();
2436 let sit = vec![
2437 "amet consectetur adipiscing elit amet",
2438 "consectetur adipiscing elit amet consectetur.",
2439 ];
2440}
2441```
2442
2443#### `2`:
2444
2445```rust
2446fn lorem() {
2447 let ipsum = dolor();
2448 let sit = vec![
2449 "amet consectetur adipiscing elit amet",
2450 "consectetur adipiscing elit amet consectetur.",
2451 ];
2452}
2453```
2454
2455See also: [`hard_tabs`](#hard_tabs).
2456
2457
2458## `trailing_comma`
2459
2460How to handle trailing commas for lists
2461
2462- **Default value**: `"Vertical"`
2463- **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
a2a8927a 2464- **Stable**: No (tracking issue: [#3379](https://github.com/rust-lang/rustfmt/issues/3379))
f20569fa
XL
2465
2466#### `"Vertical"` (default):
2467
2468```rust
2469fn main() {
2470 let Lorem { ipsum, dolor, sit } = amet;
2471 let Lorem {
2472 ipsum,
2473 dolor,
2474 sit,
2475 amet,
2476 consectetur,
2477 adipiscing,
2478 } = elit;
2479}
2480```
2481
2482#### `"Always"`:
2483
2484```rust
2485fn main() {
2486 let Lorem { ipsum, dolor, sit, } = amet;
2487 let Lorem {
2488 ipsum,
2489 dolor,
2490 sit,
2491 amet,
2492 consectetur,
2493 adipiscing,
2494 } = elit;
2495}
2496```
2497
2498#### `"Never"`:
2499
2500```rust
2501fn main() {
2502 let Lorem { ipsum, dolor, sit } = amet;
2503 let Lorem {
2504 ipsum,
2505 dolor,
2506 sit,
2507 amet,
2508 consectetur,
2509 adipiscing
2510 } = elit;
2511}
2512```
2513
2514See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2515
2516## `trailing_semicolon`
2517
2518Add trailing semicolon after break, continue and return
2519
2520- **Default value**: `true`
2521- **Possible values**: `true`, `false`
a2a8927a 2522- **Stable**: No (tracking issue: [#3378](https://github.com/rust-lang/rustfmt/issues/3378))
f20569fa
XL
2523
2524#### `true` (default):
2525```rust
2526fn foo() -> usize {
2527 return 0;
2528}
2529```
2530
2531#### `false`:
2532```rust
2533fn foo() -> usize {
2534 return 0
2535}
2536```
2537
2538## `type_punctuation_density`
2539
2540Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2541
2542- **Default value**: `"Wide"`
2543- **Possible values**: `"Compressed"`, `"Wide"`
a2a8927a 2544- **Stable**: No (tracking issue: [#3364](https://github.com/rust-lang/rustfmt/issues/3364))
f20569fa
XL
2545
2546#### `"Wide"` (default):
2547
2548```rust
2549fn lorem<Ipsum: Dolor + Sit = Amet>() {
2550 // body
2551}
2552```
2553
2554#### `"Compressed"`:
2555
2556```rust
2557fn lorem<Ipsum: Dolor+Sit=Amet>() {
2558 // body
2559}
2560```
2561
2562## `unstable_features`
2563
2564Enable unstable features on the unstable channel.
2565
2566- **Default value**: `false`
2567- **Possible values**: `true`, `false`
a2a8927a 2568- **Stable**: No (tracking issue: [#3387](https://github.com/rust-lang/rustfmt/issues/3387))
f20569fa
XL
2569
2570## `use_field_init_shorthand`
2571
2572Use field initialize shorthand if possible.
2573
2574- **Default value**: `false`
2575- **Possible values**: `true`, `false`
2576- **Stable**: Yes
2577
2578#### `false` (default):
2579
2580```rust
2581struct Foo {
2582 x: u32,
2583 y: u32,
2584 z: u32,
2585}
2586
2587fn main() {
2588 let x = 1;
2589 let y = 2;
2590 let z = 3;
3c0e092e
XL
2591 let a = Foo { x, y, z };
2592 let b = Foo { x: x, y: y, z: z };
f20569fa
XL
2593}
2594```
2595
2596#### `true`:
2597
2598```rust
2599struct Foo {
2600 x: u32,
2601 y: u32,
2602 z: u32,
2603}
2604
2605fn main() {
2606 let x = 1;
2607 let y = 2;
2608 let z = 3;
2609 let a = Foo { x, y, z };
2610}
2611```
2612
2613## `use_small_heuristics`
2614
cdc7bbd5
XL
2615This 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.
2616
136023e0 2617Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
f20569fa
XL
2618
2619- **Default value**: `"Default"`
2620- **Possible values**: `"Default"`, `"Off"`, `"Max"`
2621- **Stable**: Yes
2622
2623#### `Default` (default):
cdc7bbd5
XL
2624When `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`.
2625
2626The ratios are:
2627* [`fn_call_width`](#fn_call_width) - `60%`
2628* [`attr_fn_like_width`](#attr_fn_like_width) - `70%`
2629* [`struct_lit_width`](#struct_lit_width) - `18%`
2630* [`struct_variant_width`](#struct_variant_width) - `35%`
2631* [`array_width`](#array_width) - `60%`
2632* [`chain_width`](#chain_width) - `60%`
2633* [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%`
2634
2635For example when `max_width` is set to `100`, the width settings are:
2636* `fn_call_width=60`
2637* `attr_fn_like_width=70`
2638* `struct_lit_width=18`
2639* `struct_variant_width=35`
2640* `array_width=60`
2641* `chain_width=60`
2642* `single_line_if_else_max_width=50`
2643
2644and when `max_width` is set to `200`:
2645* `fn_call_width=120`
2646* `attr_fn_like_width=140`
2647* `struct_lit_width=36`
2648* `struct_variant_width=70`
2649* `array_width=120`
2650* `chain_width=120`
2651* `single_line_if_else_max_width=100`
f20569fa
XL
2652
2653```rust
2654enum Lorem {
2655 Ipsum,
2656 Dolor(bool),
2657 Sit { amet: Consectetur, adipiscing: Elit },
2658}
2659
2660fn main() {
2661 lorem(
2662 "lorem",
2663 "ipsum",
2664 "dolor",
2665 "sit",
2666 "amet",
2667 "consectetur",
2668 "adipiscing",
2669 );
2670
2671 let lorem = Lorem {
2672 ipsum: dolor,
2673 sit: amet,
2674 };
2675 let lorem = Lorem { ipsum: dolor };
2676
2677 let lorem = if ipsum { dolor } else { sit };
2678}
2679```
2680
2681#### `Off`:
136023e0 2682When `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.
f20569fa
XL
2683
2684```rust
2685enum Lorem {
2686 Ipsum,
2687 Dolor(bool),
2688 Sit {
2689 amet: Consectetur,
2690 adipiscing: Elit,
2691 },
2692}
2693
2694fn main() {
2695 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2696
2697 let lorem = Lorem {
2698 ipsum: dolor,
2699 sit: amet,
2700 };
2701
2702 let lorem = if ipsum {
2703 dolor
2704 } else {
2705 sit
2706 };
2707}
2708```
2709
2710#### `Max`:
cdc7bbd5
XL
2711When `use_small_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2712
2713So if `max_width` is set to `200`, then all the width settings are also set to `200`.
2714* `fn_call_width=200`
2715* `attr_fn_like_width=200`
2716* `struct_lit_width=200`
2717* `struct_variant_width=200`
2718* `array_width=200`
2719* `chain_width=200`
2720* `single_line_if_else_max_width=200`
f20569fa
XL
2721
2722```rust
2723enum Lorem {
2724 Ipsum,
2725 Dolor(bool),
2726 Sit { amet: Consectetur, adipiscing: Elit },
2727}
2728
2729fn main() {
2730 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2731
2732 let lorem = Lorem { ipsum: dolor, sit: amet };
2733
2734 let lorem = if ipsum { dolor } else { sit };
2735}
2736```
2737
cdc7bbd5
XL
2738
2739See also:
2740* [`max_width`](#max_width)
2741* [`fn_call_width`](#fn_call_width)
2742* [`attr_fn_like_width`](#attr_fn_like_width)
2743* [`struct_lit_width`](#struct_lit_width)
2744* [`struct_variant_width`](#struct_variant_width)
2745* [`array_width`](#array_width)
2746* [`chain_width`](#chain_width)
2747* [`single_line_if_else_max_width`](#single_line_if_else_max_width)
2748
f20569fa
XL
2749## `use_try_shorthand`
2750
2751Replace uses of the try! macro by the ? shorthand
2752
2753- **Default value**: `false`
2754- **Possible values**: `true`, `false`
2755- **Stable**: Yes
2756
2757#### `false` (default):
2758
2759```rust
2760fn main() {
3c0e092e
XL
2761 let lorem = ipsum.map(|dolor| dolor.sit())?;
2762
f20569fa
XL
2763 let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2764}
2765```
2766
2767#### `true`:
2768
2769```rust
2770fn main() {
2771 let lorem = ipsum.map(|dolor| dolor.sit())?;
2772}
2773```
2774
2775## `version`
2776
2777Which version of the formatting rules to use. `Version::One` is backwards-compatible
2778with Rustfmt 1.0. Other versions are only backwards compatible within a major
2779version number.
2780
2781- **Default value**: `One`
2782- **Possible values**: `One`, `Two`
a2a8927a 2783- **Stable**: No (tracking issue: [#3383](https://github.com/rust-lang/rustfmt/issues/3383))
f20569fa
XL
2784
2785### Example
2786
2787```toml
2788version = "Two"
2789```
2790
2791## `where_single_line`
2792
2793Forces the `where` clause to be laid out on a single line.
2794
2795- **Default value**: `false`
2796- **Possible values**: `true`, `false`
a2a8927a 2797- **Stable**: No (tracking issue: [#3359](https://github.com/rust-lang/rustfmt/issues/3359))
f20569fa
XL
2798
2799#### `false` (default):
2800
2801```rust
2802impl<T> Lorem for T
2803where
2804 Option<T>: Ipsum,
2805{
2806 // body
2807}
2808```
2809
2810#### `true`:
2811
2812```rust
2813impl<T> Lorem for T
2814where Option<T>: Ipsum
2815{
2816 // body
2817}
2818```
2819
2820See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2821
2822
2823## `wrap_comments`
2824
2825Break comments to fit on the line
2826
2827- **Default value**: `false`
2828- **Possible values**: `true`, `false`
a2a8927a 2829- **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347))
f20569fa
XL
2830
2831#### `false` (default):
2832
2833```rust
3c0e092e
XL
2834// Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2835// sed do eiusmod tempor incididunt ut labore et dolore
2836// magna aliqua. Ut enim ad minim veniam, quis nostrud
2837// exercitation ullamco laboris nisi ut aliquip ex ea
2838// commodo consequat.
2839
f20569fa
XL
2840// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
2841```
2842
2843#### `true`:
2844
2845```rust
2846// Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2847// sed do eiusmod tempor incididunt ut labore et dolore
2848// magna aliqua. Ut enim ad minim veniam, quis nostrud
2849// exercitation ullamco laboris nisi ut aliquip ex ea
2850// commodo consequat.
2851```
2852
2853# Internal Options
2854
2855## `emit_mode`
2856
2857Internal option
2858
2859## `make_backup`
2860
2861Internal option, use `--backup`
2862
2863## `print_misformatted_file_names`
2864
2865Internal option, use `-l` or `--files-with-diff`