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