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