]> git.lizzy.rs Git - rust.git/blob - Configurations.md
Merge pull request #2795 from jechase/issue-2794
[rust.git] / 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.
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
21 ## `indent_style`
22
23 Indent on expressions or items.
24
25 - **Default value**: `"Block"`
26 - **Possible values**: `"Block"`, `"Visual"`
27 - **Stable**: No
28
29 ### Array
30
31 #### `"Block"` (default):
32
33 ```rust
34 fn main() {
35     let lorem = vec![
36         "ipsum",
37         "dolor",
38         "sit",
39         "amet",
40         "consectetur",
41         "adipiscing",
42         "elit",
43     ];
44 }
45 ```
46
47 #### `"Visual"`:
48
49 ```rust
50 fn main() {
51     let lorem = vec!["ipsum",
52                      "dolor",
53                      "sit",
54                      "amet",
55                      "consectetur",
56                      "adipiscing",
57                      "elit"];
58 }
59 ```
60
61 ### Control flow
62
63 #### `"Block"` (default):
64
65 ```rust
66 fn main() {
67     if lorem_ipsum
68         && dolor_sit
69         && amet_consectetur
70         && lorem_sit
71         && dolor_consectetur
72         && amet_ipsum
73         && lorem_consectetur
74     {
75         // ...
76     }
77 }
78 ```
79
80 #### `"Visual"`:
81
82 ```rust
83 fn main() {
84     if lorem_ipsum
85        && dolor_sit
86        && amet_consectetur
87        && lorem_sit
88        && dolor_consectetur
89        && amet_ipsum
90        && lorem_consectetur
91     {
92         // ...
93     }
94 }
95 ```
96
97 See also: [`control_brace_style`](#control_brace_style).
98
99 ### Function arguments
100
101 #### `"Block"` (default):
102
103 ```rust
104 fn lorem() {}
105
106 fn lorem(ipsum: usize) {}
107
108 fn lorem(
109     ipsum: usize,
110     dolor: usize,
111     sit: usize,
112     amet: usize,
113     consectetur: usize,
114     adipiscing: usize,
115     elit: usize,
116 ) {
117     // body
118 }
119 ```
120
121 #### `"Visual"`:
122
123 ```rust
124 fn lorem() {}
125
126 fn lorem(ipsum: usize) {}
127
128 fn lorem(ipsum: usize,
129          dolor: usize,
130          sit: usize,
131          amet: usize,
132          consectetur: usize,
133          adipiscing: usize,
134          elit: usize) {
135     // body
136 }
137 ```
138
139 ### Function calls
140
141 #### `"Block"` (default):
142
143 ```rust
144 fn main() {
145     lorem(
146         "lorem",
147         "ipsum",
148         "dolor",
149         "sit",
150         "amet",
151         "consectetur",
152         "adipiscing",
153         "elit",
154     );
155 }
156 ```
157
158 #### `"Visual"`:
159
160 ```rust
161 fn main() {
162     lorem("lorem",
163           "ipsum",
164           "dolor",
165           "sit",
166           "amet",
167           "consectetur",
168           "adipiscing",
169           "elit");
170 }
171 ```
172
173 ### Generics
174
175 #### `"Block"` (default):
176
177 ```rust
178 fn lorem<
179     Ipsum: Eq = usize,
180     Dolor: Eq = usize,
181     Sit: Eq = usize,
182     Amet: Eq = usize,
183     Adipiscing: Eq = usize,
184     Consectetur: Eq = usize,
185     Elit: Eq = usize,
186 >(
187     ipsum: Ipsum,
188     dolor: Dolor,
189     sit: Sit,
190     amet: Amet,
191     adipiscing: Adipiscing,
192     consectetur: Consectetur,
193     elit: Elit,
194 ) -> T {
195     // body
196 }
197 ```
198
199 #### `"Visual"`:
200
201 ```rust
202 fn lorem<Ipsum: Eq = usize,
203          Dolor: Eq = usize,
204          Sit: Eq = usize,
205          Amet: Eq = usize,
206          Adipiscing: Eq = usize,
207          Consectetur: Eq = usize,
208          Elit: Eq = usize>(
209     ipsum: Ipsum,
210     dolor: Dolor,
211     sit: Sit,
212     amet: Amet,
213     adipiscing: Adipiscing,
214     consectetur: Consectetur,
215     elit: Elit)
216     -> T {
217     // body
218 }
219 ```
220
221 #### Struct
222
223 #### `"Block"` (default):
224
225 ```rust
226 fn main() {
227     let lorem = Lorem {
228         ipsum: dolor,
229         sit: amet,
230     };
231 }
232 ```
233
234 #### `"Visual"`:
235
236 ```rust
237 fn main() {
238     let lorem = Lorem { ipsum: dolor,
239                         sit: amet, };
240 }
241 ```
242
243 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
244
245 ### Where predicates
246
247 #### `"Block"` (default):
248
249 ```rust
250 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
251 where
252     Ipsum: Eq,
253     Dolor: Eq,
254     Sit: Eq,
255     Amet: Eq,
256 {
257     // body
258 }
259 ```
260
261 #### `"Visual"`:
262
263 ```rust
264 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
265     where Ipsum: Eq,
266           Dolor: Eq,
267           Sit: Eq,
268           Amet: Eq
269 {
270     // body
271 }
272 ```
273
274 ## `use_small_heuristics`
275
276 Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
277
278 - **Default value**: `Default`
279 - **Possible values**: `Default`, `Off`
280 - **Stable**: Yess
281
282 #### `Default` (default):
283
284 ```rust
285 enum Lorem {
286     Ipsum,
287     Dolor(bool),
288     Sit { amet: Consectetur, adipiscing: Elit },
289 }
290
291 fn main() {
292     lorem(
293         "lorem",
294         "ipsum",
295         "dolor",
296         "sit",
297         "amet",
298         "consectetur",
299         "adipiscing",
300     );
301
302     let lorem = Lorem {
303         ipsum: dolor,
304         sit: amet,
305     };
306     let lorem = Lorem { ipsum: dolor };
307
308     let lorem = if ipsum { dolor } else { sit };
309 }
310 ```
311
312 #### `Off`:
313
314 ```rust
315 enum Lorem {
316     Ipsum,
317     Dolor(bool),
318     Sit {
319         amet: Consectetur,
320         adipiscing: Elit,
321     },
322 }
323
324 fn main() {
325     lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
326
327     let lorem = Lorem {
328         ipsum: dolor,
329         sit: amet,
330     };
331
332     let lorem = if ipsum {
333         dolor
334     } else {
335         sit
336     };
337 }
338 ```
339
340 ## `binop_separator`
341
342 Where to put a binary operator when a binary expression goes multiline.
343
344 - **Default value**: `"Front"`
345 - **Possible values**: `"Front"`, `"Back"`
346 - **Stable**: No
347
348 #### `"Front"` (default):
349
350 ```rust
351 fn main() {
352     let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
353         || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
354
355     let sum = 123456789012345678901234567890
356         + 123456789012345678901234567890
357         + 123456789012345678901234567890;
358
359     let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
360         ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
361 }
362 ```
363
364 #### `"Back"`:
365
366 ```rust
367 fn main() {
368     let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
369         barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
370
371     let sum = 123456789012345678901234567890 +
372         123456789012345678901234567890 +
373         123456789012345678901234567890;
374
375     let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
376         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
377 }
378 ```
379
380 ## `combine_control_expr`
381
382 Combine control expressions with function calls.
383
384 - **Default value**: `true`
385 - **Possible values**: `true`, `false`
386 - **Stable**: No
387
388 #### `true` (default):
389
390 ```rust
391 fn example() {
392     // If
393     foo!(if x {
394         foo();
395     } else {
396         bar();
397     });
398
399     // IfLet
400     foo!(if let Some(..) = x {
401         foo();
402     } else {
403         bar();
404     });
405
406     // While
407     foo!(while x {
408         foo();
409         bar();
410     });
411
412     // WhileLet
413     foo!(while let Some(..) = x {
414         foo();
415         bar();
416     });
417
418     // ForLoop
419     foo!(for x in y {
420         foo();
421         bar();
422     });
423
424     // Loop
425     foo!(loop {
426         foo();
427         bar();
428     });
429 }
430 ```
431
432 #### `false`:
433
434 ```rust
435 fn example() {
436     // If
437     foo!(
438         if x {
439             foo();
440         } else {
441             bar();
442         }
443     );
444
445     // IfLet
446     foo!(
447         if let Some(..) = x {
448             foo();
449         } else {
450             bar();
451         }
452     );
453
454     // While
455     foo!(
456         while x {
457             foo();
458             bar();
459         }
460     );
461
462     // WhileLet
463     foo!(
464         while let Some(..) = x {
465             foo();
466             bar();
467         }
468     );
469
470     // ForLoop
471     foo!(
472         for x in y {
473             foo();
474             bar();
475         }
476     );
477
478     // Loop
479     foo!(
480         loop {
481             foo();
482             bar();
483         }
484     );
485 }
486 ```
487
488 ## `comment_width`
489
490 Maximum length of comments. No effect unless`wrap_comments = true`.
491
492 - **Default value**: `80`
493 - **Possible values**: any positive integer
494 - **Stable**: No
495
496 **Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
497
498 #### `80` (default; comments shorter than `comment_width`):
499 ```rust
500 // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
501 ```
502
503 #### `60` (comments longer than `comment_width`):
504 ```rust
505 // Lorem ipsum dolor sit amet,
506 // consectetur adipiscing elit.
507 ```
508
509 See also [`wrap_comments`](#wrap_comments).
510
511 ## `condense_wildcard_suffixes`
512
513 Replace strings of _ wildcards by a single .. in tuple patterns
514
515 - **Default value**: `false`
516 - **Possible values**: `true`, `false`
517 - **Stable**: No
518
519 #### `false` (default):
520
521 ```rust
522 fn main() {
523     let (lorem, ipsum, _, _) = (1, 2, 3, 4);
524     let (lorem, ipsum, ..) = (1, 2, 3, 4);
525 }
526 ```
527
528 #### `true`:
529
530 ```rust
531 fn main() {
532     let (lorem, ipsum, ..) = (1, 2, 3, 4);
533 }
534 ```
535
536 ## `control_brace_style`
537
538 Brace style for control flow constructs
539
540 - **Default value**: `"AlwaysSameLine"`
541 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
542 - **Stable**: No
543
544 #### `"AlwaysSameLine"` (default):
545
546 ```rust
547 fn main() {
548     if lorem {
549         println!("ipsum!");
550     } else {
551         println!("dolor!");
552     }
553 }
554 ```
555
556 #### `"AlwaysNextLine"`:
557
558 ```rust
559 fn main() {
560     if lorem
561     {
562         println!("ipsum!");
563     }
564     else
565     {
566         println!("dolor!");
567     }
568 }
569 ```
570
571 #### `"ClosingNextLine"`:
572
573 ```rust
574 fn main() {
575     if lorem {
576         println!("ipsum!");
577     }
578     else {
579         println!("dolor!");
580     }
581 }
582 ```
583
584 ## `disable_all_formatting`
585
586 Don't reformat anything
587
588 - **Default value**: `false`
589 - **Possible values**: `true`, `false`
590 - **Stable**: No
591
592 ## `error_on_line_overflow`
593
594 Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
595 literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
596 refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
597 using a shorter name.
598
599 - **Default value**: `false`
600 - **Possible values**: `true`, `false`
601 - **Stable**: No
602
603 See also [`max_width`](#max_width).
604
605 ## `error_on_unformatted`
606
607 Error if unable to get comments or string literals within `max_width`, or they are left with
608 trailing whitespaces.
609
610 - **Default value**: `false`
611 - **Possible values**: `true`, `false`
612 - **Stable**: No
613
614 ## `fn_args_density`
615
616 Argument density in functions
617
618 - **Default value**: `"Tall"`
619 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
620 - **Stable**: No
621
622 #### `"Tall"` (default):
623
624 ```rust
625 trait Lorem {
626     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
627
628     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
629         // body
630     }
631
632     fn lorem(
633         ipsum: Ipsum,
634         dolor: Dolor,
635         sit: Sit,
636         amet: Amet,
637         consectetur: Consectetur,
638         adipiscing: Adipiscing,
639         elit: Elit,
640     );
641
642     fn lorem(
643         ipsum: Ipsum,
644         dolor: Dolor,
645         sit: Sit,
646         amet: Amet,
647         consectetur: Consectetur,
648         adipiscing: Adipiscing,
649         elit: Elit,
650     ) {
651         // body
652     }
653 }
654 ```
655
656 #### `"Compressed"`:
657
658 ```rust
659 trait Lorem {
660     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
661
662     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
663         // body
664     }
665
666     fn lorem(
667         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
668         adipiscing: Adipiscing, elit: Elit,
669     );
670
671     fn lorem(
672         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
673         adipiscing: Adipiscing, elit: Elit,
674     ) {
675         // body
676     }
677 }
678 ```
679
680 #### `"Vertical"`:
681
682 ```rust
683 trait Lorem {
684     fn lorem(
685         ipsum: Ipsum,
686         dolor: Dolor,
687         sit: Sit,
688         amet: Amet,
689     );
690
691     fn lorem(
692         ipsum: Ipsum,
693         dolor: Dolor,
694         sit: Sit,
695         amet: Amet,
696     ) {
697         // body
698     }
699
700     fn lorem(
701         ipsum: Ipsum,
702         dolor: Dolor,
703         sit: Sit,
704         amet: Amet,
705         consectetur: Consectetur,
706         adipiscing: Adipiscing,
707         elit: Elit,
708     );
709
710     fn lorem(
711         ipsum: Ipsum,
712         dolor: Dolor,
713         sit: Sit,
714         amet: Amet,
715         consectetur: Consectetur,
716         adipiscing: Adipiscing,
717         elit: Elit,
718     ) {
719         // body
720     }
721 }
722 ```
723
724
725 ## `brace_style`
726
727 Brace style for items
728
729 - **Default value**: `"SameLineWhere"`
730 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
731 - **Stable**: No
732
733 ### Functions
734
735 #### `"SameLineWhere"` (default):
736
737 ```rust
738 fn lorem() {
739     // body
740 }
741
742 fn lorem(ipsum: usize) {
743     // body
744 }
745
746 fn lorem<T>(ipsum: T)
747 where
748     T: Add + Sub + Mul + Div,
749 {
750     // body
751 }
752 ```
753
754 #### `"AlwaysNextLine"`:
755
756 ```rust
757 fn lorem()
758 {
759     // body
760 }
761
762 fn lorem(ipsum: usize)
763 {
764     // body
765 }
766
767 fn lorem<T>(ipsum: T)
768 where
769     T: Add + Sub + Mul + Div,
770 {
771     // body
772 }
773 ```
774
775 #### `"PreferSameLine"`:
776
777 ```rust
778 fn lorem() {
779     // body
780 }
781
782 fn lorem(ipsum: usize) {
783     // body
784 }
785
786 fn lorem<T>(ipsum: T)
787 where
788     T: Add + Sub + Mul + Div, {
789     // body
790 }
791 ```
792
793 ### Structs and enums
794
795 #### `"SameLineWhere"` (default):
796
797 ```rust
798 struct Lorem {
799     ipsum: bool,
800 }
801
802 struct Dolor<T>
803 where
804     T: Eq,
805 {
806     sit: T,
807 }
808 ```
809
810 #### `"AlwaysNextLine"`:
811
812 ```rust
813 struct Lorem
814 {
815     ipsum: bool,
816 }
817
818 struct Dolor<T>
819 where
820     T: Eq,
821 {
822     sit: T,
823 }
824 ```
825
826 #### `"PreferSameLine"`:
827
828 ```rust
829 struct Lorem {
830     ipsum: bool,
831 }
832
833 struct Dolor<T>
834 where
835     T: Eq, {
836     sit: T,
837 }
838 ```
839
840
841 ## `empty_item_single_line`
842
843 Put empty-body functions and impls on a single line
844
845 - **Default value**: `true`
846 - **Possible values**: `true`, `false`
847 - **Stable**: No
848
849 #### `true` (default):
850
851 ```rust
852 fn lorem() {}
853
854 impl Lorem {}
855 ```
856
857 #### `false`:
858
859 ```rust
860 fn lorem() {
861 }
862
863 impl Lorem {
864 }
865 ```
866
867 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
868
869
870 ## `fn_single_line`
871
872 Put single-expression functions on a single line
873
874 - **Default value**: `false`
875 - **Possible values**: `true`, `false`
876 - **Stable**: No
877
878 #### `false` (default):
879
880 ```rust
881 fn lorem() -> usize {
882     42
883 }
884
885 fn lorem() -> usize {
886     let ipsum = 42;
887     ipsum
888 }
889 ```
890
891 #### `true`:
892
893 ```rust
894 fn lorem() -> usize { 42 }
895
896 fn lorem() -> usize {
897     let ipsum = 42;
898     ipsum
899 }
900 ```
901
902 See also [`control_brace_style`](#control_brace_style).
903
904
905 ## `where_single_line`
906
907 Forces the `where` clause to be laid out on a single line.
908
909 - **Default value**: `false`
910 - **Possible values**: `true`, `false`
911 - **Stable**: No
912
913 #### `false` (default):
914
915 ```rust
916 impl<T> Lorem for T
917 where
918     Option<T>: Ipsum,
919 {
920     // body
921 }
922 ```
923
924 #### `true`:
925
926 ```rust
927 impl<T> Lorem for T
928 where Option<T>: Ipsum
929 {
930     // body
931 }
932 ```
933
934 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
935
936
937 ## `force_explicit_abi`
938
939 Always print the abi for extern items
940
941 - **Default value**: `true`
942 - **Possible values**: `true`, `false`
943 - **Stable**: Yes
944
945 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
946
947 #### `true` (default):
948
949 ```rust
950 extern "C" {
951     pub static lorem: c_int;
952 }
953 ```
954
955 #### `false`:
956
957 ```rust
958 extern {
959     pub static lorem: c_int;
960 }
961 ```
962
963 ## `format_strings`
964
965 Format string literals where necessary
966
967 - **Default value**: `false`
968 - **Possible values**: `true`, `false`
969 - **Stable**: No
970
971 #### `false` (default):
972
973 ```rust
974 fn main() {
975     let lorem =
976         "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
977 }
978 ```
979
980 #### `true`:
981
982 ```rust
983 fn main() {
984     let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
985                  consectetur adipiscing";
986 }
987 ```
988
989 See also [`max_width`](#max_width).
990
991 ## `hard_tabs`
992
993 Use tab characters for indentation, spaces for alignment
994
995 - **Default value**: `false`
996 - **Possible values**: `true`, `false`
997 - **Stable**: Yes
998
999 #### `false` (default):
1000
1001 ```rust
1002 fn lorem() -> usize {
1003     42 // spaces before 42
1004 }
1005 ```
1006
1007 #### `true`:
1008
1009 ```rust
1010 fn lorem() -> usize {
1011         42 // tabs before 42
1012 }
1013 ```
1014
1015 See also: [`tab_spaces`](#tab_spaces).
1016
1017
1018 ## `imports_indent`
1019
1020 Indent style of imports
1021
1022 - **Default Value**: `"Visual"`
1023 - **Possible values**: `"Block"`, `"Visual"`
1024 - **Stable**: No
1025
1026 #### `"Visual"` (default):
1027
1028 ```rust
1029 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1030           zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1031 ```
1032
1033 #### `"Block"`:
1034
1035 ```rust
1036 use foo::{
1037     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1038     zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1039 };
1040 ```
1041
1042 See also: [`imports_layout`](#imports_layout).
1043
1044 ## `imports_layout`
1045
1046 Item layout inside a imports block
1047
1048 - **Default value**: "Mixed"
1049 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1050 - **Stable**: No
1051
1052 #### `"Mixed"` (default):
1053
1054 ```rust
1055 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1056
1057 use foo::{
1058     aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1059     eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1060 };
1061 ```
1062
1063 #### `"Horizontal"`:
1064
1065 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1066
1067 ```rust
1068 use foo::{xxx, yyy, zzz};
1069
1070 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1071 ```
1072
1073 #### `"HorizontalVertical"`:
1074
1075 ```rust
1076 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1077
1078 use foo::{
1079     aaaaaaaaaaaaaaaaaa,
1080     bbbbbbbbbbbbbbbbbb,
1081     cccccccccccccccccc,
1082     dddddddddddddddddd,
1083     eeeeeeeeeeeeeeeeee,
1084     ffffffffffffffffff,
1085 };
1086 ```
1087
1088 #### `"Vertical"`:
1089
1090 ```rust
1091 use foo::{
1092     xxx,
1093     yyy,
1094     zzz,
1095 };
1096
1097 use foo::{
1098     aaa,
1099     bbb,
1100     ccc,
1101     ddd,
1102     eee,
1103     fff,
1104 };
1105 ```
1106
1107 ## `merge_imports`
1108
1109 Merge multiple imports into a single nested import.
1110
1111 - **Default value**: `false`
1112 - **Possible values**: `true`, `false`
1113 - **Stable**: No
1114
1115 #### `false` (default):
1116
1117 ```rust
1118 use foo::{a, c, d};
1119 use foo::{b, g};
1120 use foo::{e, f};
1121 ```
1122
1123 #### `true`:
1124
1125 ```rust
1126 use foo::{a, b, c, d, e, f, g};
1127 ```
1128
1129
1130 ## `match_block_trailing_comma`
1131
1132 Put a trailing comma after a block based match arm (non-block arms are not affected)
1133
1134 - **Default value**: `false`
1135 - **Possible values**: `true`, `false`
1136 - **Stable**: No
1137
1138 #### `false` (default):
1139
1140 ```rust
1141 fn main() {
1142     match lorem {
1143         Lorem::Ipsum => {
1144             println!("ipsum");
1145         }
1146         Lorem::Dolor => println!("dolor"),
1147     }
1148 }
1149 ```
1150
1151 #### `true`:
1152
1153 ```rust
1154 fn main() {
1155     match lorem {
1156         Lorem::Ipsum => {
1157             println!("ipsum");
1158         },
1159         Lorem::Dolor => println!("dolor"),
1160     }
1161 }
1162 ```
1163
1164 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1165
1166 ## `max_width`
1167
1168 Maximum width of each line
1169
1170 - **Default value**: `100`
1171 - **Possible values**: any positive integer
1172 - **Stable**: Yes
1173
1174 See also [`error_on_line_overflow`](#error_on_line_overflow).
1175
1176 ## `merge_derives`
1177
1178 Merge multiple derives into a single one.
1179
1180 - **Default value**: `true`
1181 - **Possible values**: `true`, `false`
1182 - **Stable**: Yes
1183
1184 #### `true` (default):
1185
1186 ```rust
1187 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1188 pub enum Foo {}
1189 ```
1190
1191 #### `false`:
1192
1193 ```rust
1194 #[derive(Eq, PartialEq)]
1195 #[derive(Debug)]
1196 #[derive(Copy, Clone)]
1197 pub enum Foo {}
1198 ```
1199
1200 ## `force_multiline_blocks`
1201
1202 Force multiline closure and match arm bodies to be wrapped in a block
1203
1204 - **Default value**: `false`
1205 - **Possible values**: `false`, `true`
1206 - **Stable**: No
1207
1208 #### `false` (default):
1209
1210 ```rust
1211 fn main() {
1212     result.and_then(|maybe_value| match maybe_value {
1213         None => foo(),
1214         Some(value) => bar(),
1215     });
1216
1217     match lorem {
1218         None => if ipsum {
1219             println!("Hello World");
1220         },
1221         Some(dolor) => foo(),
1222     }
1223 }
1224 ```
1225
1226 #### `true`:
1227
1228 ```rust
1229 fn main() {
1230     result.and_then(|maybe_value| {
1231         match maybe_value {
1232             None => foo(),
1233             Some(value) => bar(),
1234         }
1235     });
1236
1237     match lorem {
1238         None => {
1239             if ipsum {
1240                 println!("Hello World");
1241             }
1242         }
1243         Some(dolor) => foo(),
1244     }
1245 }
1246 ```
1247
1248
1249 ## `newline_style`
1250
1251 Unix or Windows line endings
1252
1253 - **Default value**: `"Unix"`
1254 - **Possible values**: `"Native"`, `"Unix"`, `"Windows"`
1255 - **Stable**: Yes
1256
1257 ## `normalize_comments`
1258
1259 Convert /* */ comments to // comments where possible
1260
1261 - **Default value**: `false`
1262 - **Possible values**: `true`, `false`
1263 - **Stable**: No
1264
1265 #### `false` (default):
1266
1267 ```rust
1268 // Lorem ipsum:
1269 fn dolor() -> usize {}
1270
1271 /* sit amet: */
1272 fn adipiscing() -> usize {}
1273 ```
1274
1275 #### `true`:
1276
1277 ```rust
1278 // Lorem ipsum:
1279 fn dolor() -> usize {}
1280
1281 // sit amet:
1282 fn adipiscing() -> usize {}
1283 ```
1284
1285 ## `remove_nested_parens`
1286
1287 Remove nested parens.
1288
1289 - **Default value**: `true`,
1290 - **Possible values**: `true`, `false`
1291 - **Stable**: Yes
1292
1293
1294 #### `true` (default):
1295 ```rust
1296 fn main() {
1297     (foo());
1298 }
1299 ```
1300
1301 #### `false`:
1302 ```rust
1303 fn main() {
1304     ((((foo()))));
1305 }
1306 ```
1307
1308
1309 ## `reorder_imports`
1310
1311 Reorder import and extern crate statements alphabetically in groups (a group is
1312 separated by a newline).
1313
1314 - **Default value**: `true`
1315 - **Possible values**: `true`, `false`
1316 - **Stable**: Yes
1317
1318 #### `true` (default):
1319
1320 ```rust
1321 use dolor;
1322 use ipsum;
1323 use lorem;
1324 use sit;
1325 ```
1326
1327 #### `false`:
1328
1329 ```rust
1330 use lorem;
1331 use ipsum;
1332 use dolor;
1333 use sit;
1334 ```
1335
1336
1337 ## `reorder_modules`
1338
1339 Reorder `mod` declarations alphabetically in group.
1340
1341 - **Default value**: `true`
1342 - **Possible values**: `true`, `false`
1343 - **Stable**: Yes
1344
1345 #### `true` (default)
1346
1347 ```rust
1348 mod a;
1349 mod b;
1350
1351 mod dolor;
1352 mod ipsum;
1353 mod lorem;
1354 mod sit;
1355 ```
1356
1357 #### `false`
1358
1359 ```rust
1360 mod b;
1361 mod a;
1362
1363 mod lorem;
1364 mod ipsum;
1365 mod dolor;
1366 mod sit;
1367 ```
1368
1369 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantic
1370 of the original source code.
1371
1372 ## `reorder_impl_items`
1373
1374 Reorder impl items. `type` and `const` are put first, then macros and methods.
1375
1376 - **Default value**: `false`
1377 - **Possible values**: `true`, `false`
1378 - **Stable**: No
1379
1380 #### `false` (default)
1381
1382 ```rust
1383 struct Dummy;
1384
1385 impl Iterator for Dummy {
1386     fn next(&mut self) -> Option<Self::Item> {
1387         None
1388     }
1389
1390     type Item = i32;
1391 }
1392 ```
1393
1394 #### `true`
1395
1396 ```rust
1397 struct Dummy;
1398
1399 impl Iterator for Dummy {
1400     type Item = i32;
1401
1402     fn next(&mut self) -> Option<Self::Item> {
1403         None
1404     }
1405 }
1406 ```
1407
1408 ## `report_todo`
1409
1410 Report `TODO` items in comments.
1411
1412 - **Default value**: `"Never"`
1413 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1414 - **Stable**: No
1415
1416 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1417 it contains a `#X` (with `X` being a number) in parentheses following the
1418 `TODO`, `"Unnumbered"` will ignore it.
1419
1420 See also [`report_fixme`](#report_fixme).
1421
1422 ## `report_fixme`
1423
1424 Report `FIXME` items in comments.
1425
1426 - **Default value**: `"Never"`
1427 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1428 - **Stable**: No
1429
1430 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1431 it contains a `#X` (with `X` being a number) in parentheses following the
1432 `FIXME`, `"Unnumbered"` will ignore it.
1433
1434 See also [`report_todo`](#report_todo).
1435
1436
1437 ## `skip_children`
1438
1439 Don't reformat out of line modules
1440
1441 - **Default value**: `false`
1442 - **Possible values**: `true`, `false`
1443 - **Stable**: No
1444
1445 ## `space_after_colon`
1446
1447 Leave a space after the colon.
1448
1449 - **Default value**: `true`
1450 - **Possible values**: `true`, `false`
1451 - **Stable**: No
1452
1453 #### `true` (default):
1454
1455 ```rust
1456 fn lorem<T: Eq>(t: T) {
1457     let lorem: Dolor = Lorem {
1458         ipsum: dolor,
1459         sit: amet,
1460     };
1461 }
1462 ```
1463
1464 #### `false`:
1465
1466 ```rust
1467 fn lorem<T:Eq>(t:T) {
1468     let lorem:Dolor = Lorem {
1469         ipsum:dolor,
1470         sit:amet,
1471     };
1472 }
1473 ```
1474
1475 See also: [`space_before_colon`](#space_before_colon).
1476
1477 ## `space_before_colon`
1478
1479 Leave a space before the colon.
1480
1481 - **Default value**: `false`
1482 - **Possible values**: `true`, `false`
1483 - **Stable**: No
1484
1485 #### `false` (default):
1486
1487 ```rust
1488 fn lorem<T: Eq>(t: T) {
1489     let lorem: Dolor = Lorem {
1490         ipsum: dolor,
1491         sit: amet,
1492     };
1493 }
1494 ```
1495
1496 #### `true`:
1497
1498 ```rust
1499 fn lorem<T : Eq>(t : T) {
1500     let lorem : Dolor = Lorem {
1501         ipsum : dolor,
1502         sit : amet,
1503     };
1504 }
1505 ```
1506
1507 See also: [`space_after_colon`](#space_after_colon).
1508
1509 ## `struct_field_align_threshold`
1510
1511 The maximum diff of width between struct fields to be aligned with each other.
1512
1513 - **Default value** : 0
1514 - **Possible values**: any positive integer
1515 - **Stable**: No
1516
1517 #### `0` (default):
1518
1519 ```rust
1520 struct Foo {
1521     x: u32,
1522     yy: u32,
1523     zzz: u32,
1524 }
1525 ```
1526
1527 #### `20`:
1528
1529 ```rust
1530 struct Foo {
1531     x:   u32,
1532     yy:  u32,
1533     zzz: u32,
1534 }
1535 ```
1536
1537 ## `spaces_around_ranges`
1538
1539 Put spaces around the .., ..=, and ... range operators
1540
1541 - **Default value**: `false`
1542 - **Possible values**: `true`, `false`
1543 - **Stable**: No
1544
1545 #### `false` (default):
1546
1547 ```rust
1548 fn main() {
1549     let lorem = 0..10;
1550     let ipsum = 0..=10;
1551
1552     match lorem {
1553         1..5 => foo(),
1554         _ => bar,
1555     }
1556
1557     match lorem {
1558         1..=5 => foo(),
1559         _ => bar,
1560     }
1561
1562     match lorem {
1563         1...5 => foo(),
1564         _ => bar,
1565     }
1566 }
1567 ```
1568
1569 #### `true`:
1570
1571 ```rust
1572 fn main() {
1573     let lorem = 0 .. 10;
1574     let ipsum = 0 ..= 10;
1575
1576     match lorem {
1577         1 .. 5 => foo(),
1578         _ => bar,
1579     }
1580
1581     match lorem {
1582         1 ..= 5 => foo(),
1583         _ => bar,
1584     }
1585
1586     match lorem {
1587         1 ... 5 => foo(),
1588         _ => bar,
1589     }
1590 }
1591 ```
1592
1593 ## `struct_lit_single_line`
1594
1595 Put small struct literals on a single line
1596
1597 - **Default value**: `true`
1598 - **Possible values**: `true`, `false`
1599 - **Stable**: No
1600
1601 #### `true` (default):
1602
1603 ```rust
1604 fn main() {
1605     let lorem = Lorem { foo: bar, baz: ofo };
1606 }
1607 ```
1608
1609 #### `false`:
1610
1611 ```rust
1612 fn main() {
1613     let lorem = Lorem {
1614         foo: bar,
1615         baz: ofo,
1616     };
1617 }
1618 ```
1619
1620 See also: [`indent_style`](#indent_style).
1621
1622
1623 ## `tab_spaces`
1624
1625 Number of spaces per tab
1626
1627 - **Default value**: `4`
1628 - **Possible values**: any positive integer
1629 - **Stable**: Yes
1630
1631 #### `4` (default):
1632
1633 ```rust
1634 fn lorem() {
1635     let ipsum = dolor();
1636     let sit = vec![
1637         "amet consectetur adipiscing elit amet",
1638         "consectetur adipiscing elit amet consectetur.",
1639     ];
1640 }
1641 ```
1642
1643 #### `2`:
1644
1645 ```rust
1646 fn lorem() {
1647   let ipsum = dolor();
1648   let sit = vec![
1649     "amet consectetur adipiscing elit amet",
1650     "consectetur adipiscing elit amet consectetur.",
1651   ];
1652 }
1653 ```
1654
1655 See also: [`hard_tabs`](#hard_tabs).
1656
1657
1658 ## `trailing_comma`
1659
1660 How to handle trailing commas for lists
1661
1662 - **Default value**: `"Vertical"`
1663 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
1664 - **Stable**: No
1665
1666 #### `"Vertical"` (default):
1667
1668 ```rust
1669 fn main() {
1670     let Lorem { ipsum, dolor, sit } = amet;
1671     let Lorem {
1672         ipsum,
1673         dolor,
1674         sit,
1675         amet,
1676         consectetur,
1677         adipiscing,
1678     } = elit;
1679 }
1680 ```
1681
1682 #### `"Always"`:
1683
1684 ```rust
1685 fn main() {
1686     let Lorem { ipsum, dolor, sit, } = amet;
1687     let Lorem {
1688         ipsum,
1689         dolor,
1690         sit,
1691         amet,
1692         consectetur,
1693         adipiscing,
1694     } = elit;
1695 }
1696 ```
1697
1698 #### `"Never"`:
1699
1700 ```rust
1701 fn main() {
1702     let Lorem { ipsum, dolor, sit } = amet;
1703     let Lorem {
1704         ipsum,
1705         dolor,
1706         sit,
1707         amet,
1708         consectetur,
1709         adipiscing
1710     } = elit;
1711 }
1712 ```
1713
1714 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1715
1716 ## `trailing_semicolon`
1717
1718 Add trailing semicolon after break, continue and return
1719
1720 - **Default value**: `true`
1721 - **Possible values**: `true`, `false`
1722 - **Stable**: No
1723
1724 #### `true` (default):
1725 ```rust
1726 fn foo() -> usize {
1727     return 0;
1728 }
1729 ```
1730
1731 #### `false`:
1732 ```rust
1733 fn foo() -> usize {
1734     return 0
1735 }
1736 ```
1737
1738 ## `type_punctuation_density`
1739
1740 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
1741
1742 - **Default value**: `"Wide"`
1743 - **Possible values**: `"Compressed"`, `"Wide"`
1744 - **Stable**: No
1745
1746 #### `"Wide"` (default):
1747
1748 ```rust
1749 fn lorem<Ipsum: Dolor + Sit = Amet>() {
1750     // body
1751 }
1752 ```
1753
1754 #### `"Compressed"`:
1755
1756 ```rust
1757 fn lorem<Ipsum: Dolor+Sit=Amet>() {
1758     // body
1759 }
1760 ```
1761
1762 ## `use_field_init_shorthand`
1763
1764 Use field initialize shorthand if possible.
1765
1766 - **Default value**: `false`
1767 - **Possible values**: `true`, `false`
1768 - **Stable**: Yes
1769
1770 #### `false` (default):
1771
1772 ```rust
1773 struct Foo {
1774     x: u32,
1775     y: u32,
1776     z: u32,
1777 }
1778
1779 fn main() {
1780     let x = 1;
1781     let y = 2;
1782     let z = 3;
1783     let a = Foo { x: x, y: y, z: z };
1784 }
1785 ```
1786
1787 #### `true`:
1788
1789 ```rust
1790 struct Foo {
1791     x: u32,
1792     y: u32,
1793     z: u32,
1794 }
1795
1796 fn main() {
1797     let x = 1;
1798     let y = 2;
1799     let z = 3;
1800     let a = Foo { x, y, z };
1801 }
1802 ```
1803
1804 ## `use_try_shorthand`
1805
1806 Replace uses of the try! macro by the ? shorthand
1807
1808 - **Default value**: `false`
1809 - **Possible values**: `true`, `false`
1810 - **Stable**: Yes
1811
1812 #### `false` (default):
1813
1814 ```rust
1815 fn main() {
1816     let lorem = try!(ipsum.map(|dolor| dolor.sit()));
1817 }
1818 ```
1819
1820 #### `true`:
1821
1822 ```rust
1823 fn main() {
1824     let lorem = ipsum.map(|dolor| dolor.sit())?;
1825 }
1826 ```
1827
1828
1829 ## `wrap_comments`
1830
1831 Break comments to fit on the line
1832
1833 - **Default value**: `false`
1834 - **Possible values**: `true`, `false`
1835 - **Stable**: No
1836
1837 #### `false` (default):
1838
1839 ```rust
1840 // 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.
1841 ```
1842
1843 #### `true`:
1844
1845 ```rust
1846 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
1847 // sed do eiusmod tempor incididunt ut labore et dolore
1848 // magna aliqua. Ut enim ad minim veniam, quis nostrud
1849 // exercitation ullamco laboris nisi ut aliquip ex ea
1850 // commodo consequat.
1851 ```
1852
1853 ## `match_arm_blocks`
1854
1855 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1856
1857 - **Default value**: `true`
1858 - **Possible values**: `true`, `false`
1859 - **Stable**: No
1860
1861 #### `true` (default):
1862
1863 ```rust
1864 fn main() {
1865     match lorem {
1866         true => {
1867             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1868         }
1869         false => println!("{}", sit),
1870     }
1871 }
1872 ```
1873
1874 #### `false`:
1875
1876 ```rust
1877 fn main() {
1878     match lorem {
1879         true =>
1880             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1881         false => println!("{}", sit),
1882     }
1883 }
1884 ```
1885
1886 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1887
1888
1889 ## `blank_lines_upper_bound`
1890
1891 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
1892 lines are found, they are trimmed down to match this integer.
1893
1894 - **Default value**: `1`
1895 - **Possible values**: *unsigned integer*
1896 - **Stable**: No
1897
1898 ### Example
1899 Original Code:
1900
1901 ```rust
1902 #![rustfmt::skip]
1903
1904 fn foo() {
1905     println!("a");
1906 }
1907
1908
1909
1910 fn bar() {
1911     println!("b");
1912
1913
1914     println!("c");
1915 }
1916 ```
1917
1918 #### `1` (default):
1919 ```rust
1920 fn foo() {
1921     println!("a");
1922 }
1923
1924 fn bar() {
1925     println!("b");
1926
1927     println!("c");
1928 }
1929 ```
1930
1931 #### `2` (default):
1932 ```rust
1933 fn foo() {
1934     println!("a");
1935 }
1936
1937
1938 fn bar() {
1939     println!("b");
1940
1941
1942     println!("c");
1943 }
1944 ```
1945
1946 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
1947
1948 ## `blank_lines_lower_bound`
1949
1950 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
1951 them, additional blank lines are inserted.
1952
1953 - **Default value**: `0`
1954 - **Possible values**: *unsigned integer*
1955 - **Stable**: No
1956
1957 ### Example
1958 Original Code (rustfmt will not change it with the default value of `0`):
1959
1960 ```rust
1961 #![rustfmt::skip]
1962
1963 fn foo() {
1964     println!("a");
1965 }
1966 fn bar() {
1967     println!("b");
1968     println!("c");
1969 }
1970 ```
1971
1972 #### `1`
1973 ```rust
1974 fn foo() {
1975
1976     println!("a");
1977 }
1978
1979 fn bar() {
1980
1981     println!("b");
1982
1983     println!("c");
1984 }
1985 ```
1986
1987
1988 ## `required_version`
1989
1990 Require a specific version of rustfmt. If you want to make sure that the
1991 specific version of rustfmt is used in your CI, use this option.
1992
1993 - **Default value**: `CARGO_PKG_VERSION`
1994 - **Possible values**: any published version (e.g. `"0.3.8"`)
1995 - **Stable**: No
1996
1997 ## `hide_parse_errors`
1998
1999 Do not show parse errors if the parser failed to parse files.
2000
2001 - **Default value**: `false`
2002 - **Possible values**: `true`, `false`
2003 - **Stable**: No
2004
2005 ## `color`
2006
2007 Whether to use colored output or not.
2008
2009 - **Default value**: `"Auto"`
2010 - **Possible values**: "Auto", "Always", "Never"
2011 - **Stable**: No
2012
2013 ## `unstable_features`
2014
2015 Enable unstable features on stable channel.
2016
2017 - **Default value**: `false`
2018 - **Possible values**: `true`, `false`
2019 - **Stable**: No
2020
2021 ## `license_template_path`
2022
2023 Check whether beginnings of files match a license template.
2024
2025 - **Default value**: `""``
2026 - **Possible values**: path to a license template file
2027 - **Stable**: No
2028
2029 A license template is a plain text file which is matched literally against the
2030 beginning of each source file, except for `{}`-delimited blocks, which are
2031 matched as regular expressions. The following license template therefore
2032 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
2033 Copyright 2018 The Rust Project Developers.`, etc.:
2034
2035 ```
2036 // Copyright {\d+} The Rust Project Developers.
2037 ```
2038
2039 `\{`, `\}` and `\\` match literal braces / backslashes.
2040
2041 ## `ignore`
2042
2043 Skip formatting the specified files and directories.
2044
2045 - **Default value**: format every files
2046 - **Possible values**: See an example below
2047 - **Stable**: No
2048
2049 ### Example
2050
2051 If you want to ignore specific files, put the following to your config file:
2052
2053 ```toml
2054 ignore = [
2055     "src/types.rs",
2056     "src/foo/bar.rs",
2057 ]
2058 ```
2059
2060 If you want to ignore every file under `examples/`, put the following to your config file:
2061
2062 ```toml
2063 ignore [
2064     "examples",
2065 ]
2066 ```
2067
2068 ## `emit_mode`
2069
2070 Internal option
2071
2072 ## `make_backup`
2073
2074 Internal option, use `--backup`