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