]> git.lizzy.rs Git - rust.git/blob - Configurations.md
18e57e1983a227f1672de522795a0dfed3508838
[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
1350 extern crate dolor;
1351 extern crate sit;
1352 ```
1353
1354 See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group).
1355
1356 ## `reorder_extern_crates_in_group`
1357
1358 Reorder `extern crate` statements in group
1359
1360 - **Default value**: `true`
1361 - **Possible values**: `true`, `false`
1362 - **Stable**: No
1363
1364 #### `true` (default):
1365
1366 **Note:** This only takes effect when [`reorder_extern_crates`](#reorder_extern_crates) is set to `true`.
1367
1368 ```rust
1369 extern crate a;
1370 extern crate b;
1371
1372 extern crate dolor;
1373 extern crate ipsum;
1374 extern crate lorem;
1375 extern crate sit;
1376 ```
1377
1378 #### `false`:
1379
1380 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.
1381
1382 ## `report_todo`
1383
1384 Report `TODO` items in comments.
1385
1386 - **Default value**: `"Never"`
1387 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1388 - **Stable**: No
1389
1390 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1391 it contains a `#X` (with `X` being a number) in parentheses following the
1392 `TODO`, `"Unnumbered"` will ignore it.
1393
1394 See also [`report_fixme`](#report_fixme).
1395
1396 ## `report_fixme`
1397
1398 Report `FIXME` items in comments.
1399
1400 - **Default value**: `"Never"`
1401 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1402 - **Stable**: No
1403
1404 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1405 it contains a `#X` (with `X` being a number) in parentheses following the
1406 `FIXME`, `"Unnumbered"` will ignore it.
1407
1408 See also [`report_todo`](#report_todo).
1409
1410
1411 ## `skip_children`
1412
1413 Don't reformat out of line modules
1414
1415 - **Default value**: `false`
1416 - **Possible values**: `true`, `false`
1417 - **Stable**: No
1418
1419 ## `space_after_colon`
1420
1421 Leave a space after the colon.
1422
1423 - **Default value**: `true`
1424 - **Possible values**: `true`, `false`
1425 - **Stable**: No
1426
1427 #### `true` (default):
1428
1429 ```rust
1430 fn lorem<T: Eq>(t: T) {
1431     let lorem: Dolor = Lorem {
1432         ipsum: dolor,
1433         sit: amet,
1434     };
1435 }
1436 ```
1437
1438 #### `false`:
1439
1440 ```rust
1441 fn lorem<T:Eq>(t:T) {
1442     let lorem:Dolor = Lorem {
1443         ipsum:dolor,
1444         sit:amet,
1445     };
1446 }
1447 ```
1448
1449 See also: [`space_before_colon`](#space_before_colon).
1450
1451 ## `space_before_colon`
1452
1453 Leave a space before the colon.
1454
1455 - **Default value**: `false`
1456 - **Possible values**: `true`, `false`
1457 - **Stable**: No
1458
1459 #### `false` (default):
1460
1461 ```rust
1462 fn lorem<T: Eq>(t: T) {
1463     let lorem: Dolor = Lorem {
1464         ipsum: dolor,
1465         sit: amet,
1466     };
1467 }
1468 ```
1469
1470 #### `true`:
1471
1472 ```rust
1473 fn lorem<T : Eq>(t : T) {
1474     let lorem : Dolor = Lorem {
1475         ipsum : dolor,
1476         sit : amet,
1477     };
1478 }
1479 ```
1480
1481 See also: [`space_after_colon`](#space_after_colon).
1482
1483 ## `struct_field_align_threshold`
1484
1485 The maximum diff of width between struct fields to be aligned with each other.
1486
1487 - **Default value** : 0
1488 - **Possible values**: any positive integer
1489 - **Stable**: No
1490
1491 #### `0` (default):
1492
1493 ```rust
1494 struct Foo {
1495     x: u32,
1496     yy: u32,
1497     zzz: u32,
1498 }
1499 ```
1500
1501 #### `20`:
1502
1503 ```rust
1504 struct Foo {
1505     x:   u32,
1506     yy:  u32,
1507     zzz: u32,
1508 }
1509 ```
1510
1511 ## `spaces_around_ranges`
1512
1513 Put spaces around the .., ..=, and ... range operators
1514
1515 - **Default value**: `false`
1516 - **Possible values**: `true`, `false`
1517 - **Stable**: No
1518
1519 #### `false` (default):
1520
1521 ```rust
1522 fn main() {
1523     let lorem = 0..10;
1524     let ipsum = 0..=10;
1525
1526     match lorem {
1527         1..5 => foo(),
1528         _ => bar,
1529     }
1530
1531     match lorem {
1532         1..=5 => foo(),
1533         _ => bar,
1534     }
1535
1536     match lorem {
1537         1...5 => foo(),
1538         _ => bar,
1539     }
1540 }
1541 ```
1542
1543 #### `true`:
1544
1545 ```rust
1546 fn main() {
1547     let lorem = 0 .. 10;
1548     let ipsum = 0 ..= 10;
1549
1550     match lorem {
1551         1 .. 5 => foo(),
1552         _ => bar,
1553     }
1554
1555     match lorem {
1556         1 ..= 5 => foo(),
1557         _ => bar,
1558     }
1559
1560     match lorem {
1561         1 ... 5 => foo(),
1562         _ => bar,
1563     }
1564 }
1565 ```
1566
1567 ## `spaces_within_parens_and_brackets`
1568
1569 Put spaces within non-empty generic arguments, parentheses, and square brackets
1570
1571 - **Default value**: `false`
1572 - **Possible values**: `true`, `false`
1573 - **Stable**: No
1574
1575 #### `false` (default):
1576
1577 ```rust
1578 // generic arguments
1579 fn lorem<T: Eq>(t: T) {
1580     // body
1581 }
1582
1583 // non-empty parentheses
1584 fn lorem<T: Eq>(t: T) {
1585     let lorem = (ipsum, dolor);
1586 }
1587
1588 // non-empty square brackets
1589 fn lorem<T: Eq>(t: T) {
1590     let lorem: [usize; 2] = [ipsum, dolor];
1591 }
1592 ```
1593
1594 #### `true`:
1595
1596 ```rust
1597 // generic arguments
1598 fn lorem< T: Eq >( t: T ) {
1599     // body
1600 }
1601
1602 // non-empty parentheses
1603 fn lorem< T: Eq >( t: T ) {
1604     let lorem = ( ipsum, dolor );
1605 }
1606
1607 // non-empty square brackets
1608 fn lorem< T: Eq >( t: T ) {
1609     let lorem: [ usize; 2 ] = [ ipsum, dolor ];
1610 }
1611 ```
1612
1613 ## `struct_lit_single_line`
1614
1615 Put small struct literals on a single line
1616
1617 - **Default value**: `true`
1618 - **Possible values**: `true`, `false`
1619 - **Stable**: No
1620
1621 #### `true` (default):
1622
1623 ```rust
1624 fn main() {
1625     let lorem = Lorem { foo: bar, baz: ofo };
1626 }
1627 ```
1628
1629 #### `false`:
1630
1631 ```rust
1632 fn main() {
1633     let lorem = Lorem {
1634         foo: bar,
1635         baz: ofo,
1636     };
1637 }
1638 ```
1639
1640 See also: [`indent_style`](#indent_style).
1641
1642
1643 ## `tab_spaces`
1644
1645 Number of spaces per tab
1646
1647 - **Default value**: `4`
1648 - **Possible values**: any positive integer
1649 - **Stable**: Yes
1650
1651 #### `4` (default):
1652
1653 ```rust
1654 fn lorem() {
1655     let ipsum = dolor();
1656     let sit = vec![
1657         "amet consectetur adipiscing elit amet consectetur adipiscing elit amet consectetur.",
1658     ];
1659 }
1660 ```
1661
1662 #### `2`:
1663
1664 ```rust
1665 fn lorem() {
1666   let ipsum = dolor();
1667   let sit = vec![
1668     "amet consectetur adipiscing elit amet consectetur adipiscing elit amet consectetur.",
1669   ];
1670 }
1671 ```
1672
1673 See also: [`hard_tabs`](#hard_tabs).
1674
1675
1676 ## `trailing_comma`
1677
1678 How to handle trailing commas for lists
1679
1680 - **Default value**: `"Vertical"`
1681 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
1682 - **Stable**: No
1683
1684 #### `"Vertical"` (default):
1685
1686 ```rust
1687 fn main() {
1688     let Lorem { ipsum, dolor, sit } = amet;
1689     let Lorem {
1690         ipsum,
1691         dolor,
1692         sit,
1693         amet,
1694         consectetur,
1695         adipiscing,
1696     } = elit;
1697 }
1698 ```
1699
1700 #### `"Always"`:
1701
1702 ```rust
1703 fn main() {
1704     let Lorem { ipsum, dolor, sit, } = amet;
1705     let Lorem {
1706         ipsum,
1707         dolor,
1708         sit,
1709         amet,
1710         consectetur,
1711         adipiscing,
1712     } = elit;
1713 }
1714 ```
1715
1716 #### `"Never"`:
1717
1718 ```rust
1719 fn main() {
1720     let Lorem { ipsum, dolor, sit } = amet;
1721     let Lorem {
1722         ipsum,
1723         dolor,
1724         sit,
1725         amet,
1726         consectetur,
1727         adipiscing
1728     } = elit;
1729 }
1730 ```
1731
1732 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1733
1734 ## `trailing_semicolon`
1735
1736 Add trailing semicolon after break, continue and return
1737
1738 - **Default value**: `true`
1739 - **Possible values**: `true`, `false`
1740 - **Stable**: No
1741
1742 #### `true` (default):
1743 ```rust
1744 fn foo() -> usize {
1745     return 0;
1746 }
1747 ```
1748
1749 #### `false`:
1750 ```rust
1751 fn foo() -> usize {
1752     return 0
1753 }
1754 ```
1755
1756 ## `type_punctuation_density`
1757
1758 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
1759
1760 - **Default value**: `"Wide"`
1761 - **Possible values**: `"Compressed"`, `"Wide"`
1762 - **Stable**: No
1763
1764 #### `"Wide"` (default):
1765
1766 ```rust
1767 fn lorem<Ipsum: Dolor + Sit = Amet>() {
1768     // body
1769 }
1770 ```
1771
1772 #### `"Compressed"`:
1773
1774 ```rust
1775 fn lorem<Ipsum: Dolor+Sit=Amet>() {
1776     // body
1777 }
1778 ```
1779
1780 ## `use_field_init_shorthand`
1781
1782 Use field initialize shorthand if possible.
1783
1784 - **Default value**: `false`
1785 - **Possible values**: `true`, `false`
1786 - **Stable**: No
1787
1788 #### `false` (default):
1789
1790 ```rust
1791 struct Foo {
1792     x: u32,
1793     y: u32,
1794     z: u32,
1795 }
1796
1797 fn main() {
1798     let x = 1;
1799     let y = 2;
1800     let z = 3;
1801     let a = Foo { x: x, y: y, z: z };
1802 }
1803 ```
1804
1805 #### `true`:
1806
1807 ```rust
1808 struct Foo {
1809     x: u32,
1810     y: u32,
1811     z: u32,
1812 }
1813
1814 fn main() {
1815     let x = 1;
1816     let y = 2;
1817     let z = 3;
1818     let a = Foo { x, y, z };
1819 }
1820 ```
1821
1822 ## `use_try_shorthand`
1823
1824 Replace uses of the try! macro by the ? shorthand
1825
1826 - **Default value**: `false`
1827 - **Possible values**: `true`, `false`
1828 - **Stable**: No
1829
1830 #### `false` (default):
1831
1832 ```rust
1833 fn main() {
1834     let lorem = try!(ipsum.map(|dolor| dolor.sit()));
1835 }
1836 ```
1837
1838 #### `true`:
1839
1840 ```rust
1841 fn main() {
1842     let lorem = ipsum.map(|dolor| dolor.sit())?;
1843 }
1844 ```
1845
1846
1847 ## `wrap_comments`
1848
1849 Break comments to fit on the line
1850
1851 - **Default value**: `false`
1852 - **Possible values**: `true`, `false`
1853 - **Stable**: Yes
1854
1855 #### `false` (default):
1856
1857 ```rust
1858 // 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.
1859 ```
1860
1861 #### `true`:
1862
1863 ```rust
1864 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
1865 // sed do eiusmod tempor incididunt ut labore et dolore
1866 // magna aliqua. Ut enim ad minim veniam, quis nostrud
1867 // exercitation ullamco laboris nisi ut aliquip ex ea
1868 // commodo consequat.
1869 ```
1870
1871 ## `match_arm_blocks`
1872
1873 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1874
1875 - **Default value**: `true`
1876 - **Possible values**: `true`, `false`
1877 - **Stable**: No
1878
1879 #### `true` (default):
1880
1881 ```rust
1882 fn main() {
1883     match lorem {
1884         true => {
1885             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1886         }
1887         false => println!("{}", sit),
1888     }
1889 }
1890 ```
1891
1892 #### `false`:
1893
1894 ```rust
1895 fn main() {
1896     match lorem {
1897         true =>
1898             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1899         false => println!("{}", sit),
1900     }
1901 }
1902 ```
1903
1904 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1905
1906 ## `write_mode`
1907
1908 What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage
1909
1910 - **Default value**: `"Overwrite"`
1911 - **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"`
1912 - **Stable**: No
1913
1914 ## `blank_lines_upper_bound`
1915
1916 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
1917 lines are found, they are trimmed down to match this integer.
1918
1919 - **Default value**: `1`
1920 - **Possible values**: *unsigned integer*
1921 - **Stable**: No
1922
1923 ### Example
1924 Original Code:
1925
1926 ```rust
1927 #![rustfmt_skip]
1928
1929 fn foo() {
1930     println!("a");
1931 }
1932
1933
1934
1935 fn bar() {
1936     println!("b");
1937
1938
1939     println!("c");
1940 }
1941 ```
1942
1943 #### `1` (default):
1944 ```rust
1945 fn foo() {
1946     println!("a");
1947 }
1948
1949 fn bar() {
1950     println!("b");
1951
1952     println!("c");
1953 }
1954 ```
1955
1956 #### `2` (default):
1957 ```rust
1958 fn foo() {
1959     println!("a");
1960 }
1961
1962
1963 fn bar() {
1964     println!("b");
1965
1966
1967     println!("c");
1968 }
1969 ```
1970
1971 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
1972
1973 ## `blank_lines_lower_bound`
1974
1975 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
1976 them, additional blank lines are inserted.
1977
1978 - **Default value**: `0`
1979 - **Possible values**: *unsigned integer*
1980 - **Stable**: No
1981
1982 ### Example
1983 Original Code (rustfmt will not change it with the default value of `0`):
1984
1985 ```rust
1986 #![rustfmt_skip]
1987
1988 fn foo() {
1989     println!("a");
1990 }
1991 fn bar() {
1992     println!("b");
1993     println!("c");
1994 }
1995 ```
1996
1997 #### `1`
1998 ```rust
1999 fn foo() {
2000
2001     println!("a");
2002 }
2003
2004 fn bar() {
2005
2006     println!("b");
2007
2008     println!("c");
2009 }
2010 ```