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