]> git.lizzy.rs Git - rust.git/blob - Configurations.md
Wrapping `condense_wildcard_suffixes=false` 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 let (lorem, ipsum, ..) = (1, 2, 3, 4);
517 ```
518
519 ## `control_brace_style`
520
521 Brace style for control flow constructs
522
523 - **Default value**: `"AlwaysSameLine"`
524 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
525 - **Stable**: No
526
527 #### `"AlwaysSameLine"` (default):
528
529 ```rust
530 if lorem {
531     println!("ipsum!");
532 } else {
533     println!("dolor!");
534 }
535 ```
536
537 #### `"AlwaysNextLine"`:
538
539 ```rust
540 if lorem
541 {
542     println!("ipsum!");
543 }
544 else
545 {
546     println!("dolor!");
547 }
548 ```
549
550 #### `"ClosingNextLine"`:
551
552 ```rust
553 if lorem {
554     println!("ipsum!");
555 }
556 else {
557     println!("dolor!");
558 }
559 ```
560
561 ## `disable_all_formatting`
562
563 Don't reformat anything
564
565 - **Default value**: `false`
566 - **Possible values**: `true`, `false`
567 - **Stable**: No
568
569 ## `error_on_line_overflow`
570
571 Error if unable to get all lines within `max_width`
572
573 - **Default value**: `true`
574 - **Possible values**: `true`, `false`
575 - **Stable**: No
576
577 See also [`max_width`](#max_width).
578
579 ## `error_on_line_overflow_comments`
580
581 Error if unable to get all comment lines within `comment_width`.
582
583 - **Default value**: `true`
584 - **Possible values**: `true`, `false`
585 - **Stable**: No
586
587 See also [`comment_width`](#comment_width).
588
589 ## `fn_args_density`
590
591 Argument density in functions
592
593 - **Default value**: `"Tall"`
594 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
595 - **Stable**: No
596
597 #### `"Tall"` (default):
598
599 ```rust
600 trait Lorem {
601     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
602
603     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
604         // body
605     }
606
607     fn lorem(
608         ipsum: Ipsum,
609         dolor: Dolor,
610         sit: Sit,
611         amet: Amet,
612         consectetur: Consectetur,
613         adipiscing: Adipiscing,
614         elit: Elit,
615     );
616
617     fn lorem(
618         ipsum: Ipsum,
619         dolor: Dolor,
620         sit: Sit,
621         amet: Amet,
622         consectetur: Consectetur,
623         adipiscing: Adipiscing,
624         elit: Elit,
625     ) {
626         // body
627     }
628 }
629 ```
630
631 #### `"Compressed"`:
632
633 ```rust
634 trait Lorem {
635     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
636
637     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
638         // body
639     }
640
641     fn lorem(
642         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
643         adipiscing: Adipiscing, elit: Elit,
644     );
645
646     fn lorem(
647         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
648         adipiscing: Adipiscing, elit: Elit,
649     ) {
650         // body
651     }
652 }
653 ```
654
655 #### `"Vertical"`:
656
657 ```rust
658 trait Lorem {
659     fn lorem(ipsum: Ipsum,
660              dolor: Dolor,
661              sit: Sit,
662              amet: Amet);
663
664     fn lorem(ipsum: Ipsum,
665              dolor: Dolor,
666              sit: Sit,
667              amet: Amet) {
668         // body
669     }
670
671     fn lorem(ipsum: Ipsum,
672              dolor: Dolor,
673              sit: Sit,
674              amet: Amet,
675              consectetur: Consectetur,
676              adipiscing: Adipiscing,
677              elit: Elit);
678
679     fn lorem(ipsum: Ipsum,
680              dolor: Dolor,
681              sit: Sit,
682              amet: Amet,
683              consectetur: Consectetur,
684              adipiscing: Adipiscing,
685              elit: Elit) {
686         // body
687     }
688 }
689 ```
690
691
692 ## `brace_style`
693
694 Brace style for items
695
696 - **Default value**: `"SameLineWhere"`
697 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
698 - **Stable**: No
699
700 ### Functions
701
702 #### `"SameLineWhere"` (default):
703
704 ```rust
705 fn lorem() {
706     // body
707 }
708
709 fn lorem(ipsum: usize) {
710     // body
711 }
712
713 fn lorem<T>(ipsum: T)
714 where
715     T: Add + Sub + Mul + Div,
716 {
717     // body
718 }
719 ```
720
721 #### `"AlwaysNextLine"`:
722
723 ```rust
724 fn lorem()
725 {
726     // body
727 }
728
729 fn lorem(ipsum: usize)
730 {
731     // body
732 }
733
734 fn lorem<T>(ipsum: T)
735 where
736     T: Add + Sub + Mul + Div,
737 {
738     // body
739 }
740 ```
741
742 #### `"PreferSameLine"`:
743
744 ```rust
745 fn lorem() {
746     // body
747 }
748
749 fn lorem(ipsum: usize) {
750     // body
751 }
752
753 fn lorem<T>(ipsum: T)
754 where
755     T: Add + Sub + Mul + Div, {
756     // body
757 }
758 ```
759
760 ### Structs and enums
761
762 #### `"SameLineWhere"` (default):
763
764 ```rust
765 struct Lorem {
766     ipsum: bool,
767 }
768
769 struct Dolor<T>
770     where T: Eq
771 {
772     sit: T,
773 }
774 ```
775
776 #### `"AlwaysNextLine"`:
777
778 ```rust
779 struct Lorem
780 {
781     ipsum: bool,
782 }
783
784 struct Dolor<T>
785     where T: Eq
786 {
787     sit: T,
788 }
789 ```
790
791 #### `"PreferSameLine"`:
792
793 ```rust
794 struct Lorem {
795     ipsum: bool,
796 }
797
798 struct Dolor<T>
799     where T: Eq {
800     sit: T,
801 }
802 ```
803
804
805 ## `empty_item_single_line`
806
807 Put empty-body functions and impls on a single line
808
809 - **Default value**: `true`
810 - **Possible values**: `true`, `false`
811 - **Stable**: No
812
813 #### `true` (default):
814
815 ```rust
816 fn lorem() {}
817
818 impl Lorem {}
819 ```
820
821 #### `false`:
822
823 ```rust
824 fn lorem() {
825 }
826
827 impl Lorem {
828 }
829 ```
830
831 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
832
833
834 ## `fn_single_line`
835
836 Put single-expression functions on a single line
837
838 - **Default value**: `false`
839 - **Possible values**: `true`, `false`
840 - **Stable**: No
841
842 #### `false` (default):
843
844 ```rust
845 fn lorem() -> usize {
846     42
847 }
848
849 fn lorem() -> usize {
850     let ipsum = 42;
851     ipsum
852 }
853 ```
854
855 #### `true`:
856
857 ```rust
858 fn lorem() -> usize { 42 }
859
860 fn lorem() -> usize {
861     let ipsum = 42;
862     ipsum
863 }
864 ```
865
866 See also [`control_brace_style`](#control_brace_style).
867
868
869 ## `where_single_line`
870
871 To force single line where layout
872
873 - **Default value**: `false`
874 - **Possible values**: `true`, `false`
875 - **Stable**: No
876
877 #### `false` (default):
878
879 ```rust
880 impl<T> Lorem for T
881 where
882     Option<T>: Ipsum,
883 {
884     ...
885 }
886 ```
887
888 #### `true`:
889
890 ```rust
891 impl<T> Lorem for T
892 where Option<T>: Ipsum {
893     ...
894 }
895 ```
896
897 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
898
899
900 ## `force_explicit_abi`
901
902 Always print the abi for extern items
903
904 - **Default value**: `true`
905 - **Possible values**: `true`, `false`
906 - **Stable**: Yes
907
908 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
909
910 #### `true` (default):
911
912 ```rust
913 extern "C" {
914     pub static lorem: c_int;
915 }
916 ```
917
918 #### `false`:
919
920 ```rust
921 extern {
922     pub static lorem: c_int;
923 }
924 ```
925
926 ## `format_strings`
927
928 Format string literals where necessary
929
930 - **Default value**: `false`
931 - **Possible values**: `true`, `false`
932 - **Stable**: No
933
934 #### `false` (default):
935
936 ```rust
937 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit";
938 ```
939
940 #### `true`:
941
942 ```rust
943 let lorem =
944     "ipsum dolor sit amet consectetur \
945      adipiscing elit lorem ipsum dolor sit";
946 ```
947
948 See also [`max_width`](#max_width).
949
950 ## `hard_tabs`
951
952 Use tab characters for indentation, spaces for alignment
953
954 - **Default value**: `false`
955 - **Possible values**: `true`, `false`
956 - **Stable**: Yes
957
958 #### `false` (default):
959
960 ```rust
961 fn lorem() -> usize {
962     42 // spaces before 42
963 }
964 ```
965
966 #### `true`:
967
968 ```rust
969 fn lorem() -> usize {
970         42 // tabs before 42
971 }
972 ```
973
974 See also: [`tab_spaces`](#tab_spaces).
975
976
977 ## `imports_indent`
978
979 Indent style of imports
980
981 - **Default Value**: `"Visual"`
982 - **Possible values**: `"Block"`, `"Visual"`
983 - **Stable**: No
984
985 #### `"Visual"` (default):
986
987 ```rust
988 use foo::{xxx,
989           yyy,
990           zzz};
991 ```
992
993 #### `"Block"`:
994
995 ```rust
996 use foo::{
997     xxx,
998     yyy,
999     zzz,
1000 };
1001 ```
1002
1003 See also: [`imports_layout`](#imports_layout).
1004
1005 ## `imports_layout`
1006
1007 Item layout inside a imports block
1008
1009 - **Default value**: "Mixed"
1010 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1011 - **Stable**: No
1012
1013 #### `"Mixed"` (default):
1014
1015 ```rust
1016 use foo::{xxx, yyy, zzz};
1017
1018 use foo::{aaa, bbb, ccc,
1019           ddd, eee, fff};
1020 ```
1021
1022 #### `"Horizontal"`:
1023
1024 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1025
1026 ```rust
1027 use foo::{xxx, yyy, zzz};
1028
1029 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1030 ```
1031
1032 #### `"HorizontalVertical"`:
1033
1034 ```rust
1035 use foo::{xxx, yyy, zzz};
1036
1037 use foo::{aaa,
1038           bbb,
1039           ccc,
1040           ddd,
1041           eee,
1042           fff};
1043 ```
1044
1045 #### `"Vertical"`:
1046
1047 ```rust
1048 use foo::{xxx,
1049           yyy,
1050           zzz};
1051
1052 use foo::{aaa,
1053           bbb,
1054           ccc,
1055           ddd,
1056           eee,
1057           fff};
1058 ```
1059
1060
1061 ## `match_block_trailing_comma`
1062
1063 Put a trailing comma after a block based match arm (non-block arms are not affected)
1064
1065 - **Default value**: `false`
1066 - **Possible values**: `true`, `false`
1067 - **Stable**: No
1068
1069 #### `false` (default):
1070
1071 ```rust
1072 match lorem {
1073     Lorem::Ipsum => {
1074         println!("ipsum");
1075     }
1076     Lorem::Dolor => println!("dolor"),
1077 }
1078 ```
1079
1080 #### `true`:
1081
1082 ```rust
1083 match lorem {
1084     Lorem::Ipsum => {
1085         println!("ipsum");
1086     },
1087     Lorem::Dolor => println!("dolor"),
1088 }
1089 ```
1090
1091 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1092
1093 ## `max_width`
1094
1095 Maximum width of each line
1096
1097 - **Default value**: `100`
1098 - **Possible values**: any positive integer
1099 - **Stable**: Yes
1100
1101 See also [`error_on_line_overflow`](#error_on_line_overflow).
1102
1103 ## `merge_derives`
1104
1105 Merge multiple derives into a single one.
1106
1107 - **Default value**: `true`
1108 - **Possible values**: `true`, `false`
1109 - **Stable**: Yes
1110
1111 #### `true` (default):
1112
1113 ```rust
1114 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1115 pub enum Foo {}
1116 ```
1117
1118 #### `false`:
1119
1120 ```rust
1121 #[derive(Eq, PartialEq)]
1122 #[derive(Debug)]
1123 #[derive(Copy, Clone)]
1124 pub enum Foo {}
1125 ```
1126
1127 ## `force_multiline_blocks`
1128
1129 Force multiline closure and match arm bodies to be wrapped in a block
1130
1131 - **Default value**: `false`
1132 - **Possible values**: `false`, `true`
1133 - **Stable**: No
1134
1135 #### `false` (default):
1136
1137 ```rust
1138 result.and_then(|maybe_value| match maybe_value {
1139     None => ...,
1140     Some(value) => ...,
1141 })
1142
1143 match lorem {
1144     None => if ipsum {
1145         println!("Hello World");
1146     },
1147     Some(dolor) => ...,
1148 }
1149 ```
1150
1151 #### `true`:
1152
1153 ```rust
1154
1155 result.and_then(|maybe_value| {
1156     match maybe_value {
1157         None => ...,
1158         Some(value) => ...,
1159     }
1160 })
1161
1162 match lorem {
1163     None => {
1164         if ipsum {
1165             println!("Hello World");
1166         }
1167     }
1168     Some(dolor) => ...,
1169 }
1170 ```
1171
1172
1173 ## `newline_style`
1174
1175 Unix or Windows line endings
1176
1177 - **Default value**: `"Unix"`
1178 - **Possible values**: `"Native"`, `"Unix"`, `"Windows"`
1179 - **Stable**: Yes
1180
1181 ## `normalize_comments`
1182
1183 Convert /* */ comments to // comments where possible
1184
1185 - **Default value**: `false`
1186 - **Possible values**: `true`, `false`
1187 - **Stable**: Yes
1188
1189 #### `false` (default):
1190
1191 ```rust
1192 // Lorem ipsum:
1193 fn dolor() -> usize {}
1194
1195 /* sit amet: */
1196 fn adipiscing() -> usize {}
1197 ```
1198
1199 #### `true`:
1200
1201 ```rust
1202 // Lorem ipsum:
1203 fn dolor() -> usize {}
1204
1205 // sit amet:
1206 fn adipiscing() -> usize {}
1207 ```
1208
1209 ## `reorder_imported_names`
1210
1211 Reorder lists of names in import statements alphabetically
1212
1213 - **Default value**: `false`
1214 - **Possible values**: `true`, `false`
1215 - **Stable**: No
1216
1217 #### `false` (default):
1218
1219 ```rust
1220 use super::{lorem, ipsum, dolor, sit};
1221 ```
1222
1223 #### `true`:
1224
1225 ```rust
1226 use super::{dolor, ipsum, lorem, sit};
1227 ```
1228
1229 See also [`reorder_imports`](#reorder_imports).
1230
1231 ## `reorder_imports`
1232
1233 Reorder import statements alphabetically
1234
1235 - **Default value**: `false`
1236 - **Possible values**: `true`, `false`
1237 - **Stable**: No
1238
1239 #### `false` (default):
1240
1241 ```rust
1242 use lorem;
1243 use ipsum;
1244 use dolor;
1245 use sit;
1246 ```
1247
1248 #### `true`:
1249
1250 ```rust
1251 use dolor;
1252 use ipsum;
1253 use lorem;
1254 use sit;
1255 ```
1256
1257 See also [`reorder_imported_names`](#reorder_imported_names), [`reorder_imports_in_group`](#reorder_imports_in_group).
1258
1259 ## `reorder_imports_in_group`
1260
1261 Reorder import statements in group
1262
1263 - **Default value**: `false`
1264 - **Possible values**: `true`, `false`
1265 - **Stable**: No
1266
1267 **Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`.
1268
1269 #### `false` (default):
1270
1271 ```rust
1272 use std::mem;
1273 use std::io;
1274
1275 use lorem;
1276 use ipsum;
1277 use dolor;
1278 use sit;
1279 ```
1280
1281 #### `true`:
1282
1283 ```rust
1284 use std::io;
1285 use std::mem;
1286
1287 use dolor;
1288 use ipsum;
1289 use lorem;
1290 use sit;
1291 ```
1292
1293 See also [`reorder_imports`](#reorder_imports).
1294
1295 ## `reorder_extern_crates`
1296
1297 Reorder `extern crate` statements alphabetically
1298
1299 - **Default value**: `true`
1300 - **Possible values**: `true`, `false`
1301 - **Stable**: No
1302
1303 #### `true` (default):
1304
1305 ```rust
1306 extern crate dolor;
1307 extern crate ipsum;
1308 extern crate lorem;
1309 extern crate sit;
1310 ```
1311
1312 #### `false`:
1313
1314 ```rust
1315 extern crate lorem;
1316 extern crate ipsum;
1317 extern crate dolor;
1318 extern crate sit;
1319 ```
1320
1321 See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group).
1322
1323 ## `reorder_extern_crates_in_group`
1324
1325 Reorder `extern crate` statements in group
1326
1327 - **Default value**: `true`
1328 - **Possible values**: `true`, `false`
1329 - **Stable**: No
1330
1331 **Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`.
1332
1333 #### `true` (default):
1334
1335 ```rust
1336 extern crate a;
1337 extern crate b;
1338
1339 extern crate dolor;
1340 extern crate ipsum;
1341 extern crate lorem;
1342 extern crate sit;
1343 ```
1344
1345 #### `false`:
1346
1347 ```rust
1348 extern crate b;
1349 extern crate a;
1350
1351 extern crate lorem;
1352 extern crate ipsum;
1353 extern crate dolor;
1354 extern crate sit;
1355 ```
1356
1357 See also [`reorder_extern_crates`](#reorder_extern_crates).
1358
1359 ## `report_todo`
1360
1361 Report `TODO` items in comments.
1362
1363 - **Default value**: `"Never"`
1364 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1365 - **Stable**: No
1366
1367 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1368 it contains a `#X` (with `X` being a number) in parentheses following the
1369 `TODO`, `"Unnumbered"` will ignore it.
1370
1371 See also [`report_fixme`](#report_fixme).
1372
1373 ## `report_fixme`
1374
1375 Report `FIXME` items in comments.
1376
1377 - **Default value**: `"Never"`
1378 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1379 - **Stable**: No
1380
1381 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1382 it contains a `#X` (with `X` being a number) in parentheses following the
1383 `FIXME`, `"Unnumbered"` will ignore it.
1384
1385 See also [`report_todo`](#report_todo).
1386
1387
1388 ## `skip_children`
1389
1390 Don't reformat out of line modules
1391
1392 - **Default value**: `false`
1393 - **Possible values**: `true`, `false`
1394 - **Stable**: No
1395
1396 ## `space_after_colon`
1397
1398 Leave a space after the colon.
1399
1400 - **Default value**: `true`
1401 - **Possible values**: `true`, `false`
1402 - **Stable**: No
1403
1404 #### `true` (default):
1405
1406 ```rust
1407 fn lorem<T: Eq>(t: T) {
1408     let lorem: Dolor = Lorem {
1409         ipsum: dolor,
1410         sit: amet,
1411     };
1412 }
1413 ```
1414
1415 #### `false`:
1416
1417 ```rust
1418 fn lorem<T:Eq>(t:T) {
1419     let lorem:Dolor = Lorem {
1420         ipsum:dolor,
1421         sit:amet,
1422     };
1423 }
1424 ```
1425
1426 See also: [`space_before_colon`](#space_before_colon).
1427
1428 ## `space_before_colon`
1429
1430 Leave a space before the colon.
1431
1432 - **Default value**: `false`
1433 - **Possible values**: `true`, `false`
1434 - **Stable**: No
1435
1436 #### `false` (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 #### `true`:
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_after_colon`](#space_after_colon).
1459
1460 ## `struct_field_align_threshold`
1461
1462 The maximum diff of width between struct fields to be aligned with each other.
1463
1464 - **Default value** : 0
1465 - **Possible values**: any positive integer
1466 - **Stable**: No
1467
1468 #### `0` (default):
1469
1470 ```rust
1471 struct Foo {
1472     x: u32,
1473     yy: u32,
1474     zzz: u32,
1475 }
1476 ```
1477
1478 #### `20`:
1479
1480 ```rust
1481 struct Foo {
1482     x:   u32,
1483     yy:  u32,
1484     zzz: u32,
1485 }
1486 ```
1487
1488 ## `spaces_around_ranges`
1489
1490 Put spaces around the .. and ... range operators
1491
1492 - **Default value**: `false`
1493 - **Possible values**: `true`, `false`
1494 - **Stable**: No
1495
1496 #### `false` (default):
1497
1498 ```rust
1499 let lorem = 0..10;
1500 ```
1501
1502 #### `true`:
1503
1504 ```rust
1505 let lorem = 0 .. 10;
1506 ```
1507
1508 ## `spaces_within_parens_and_brackets`
1509
1510 Put spaces within non-empty generic arguments, parentheses, and square brackets
1511
1512 - **Default value**: `false`
1513 - **Possible values**: `true`, `false`
1514 - **Stable**: No
1515
1516 #### `false` (default):
1517
1518 ```rust
1519 // generic arguments
1520 fn lorem<T: Eq>(t: T) {
1521     // body
1522 }
1523
1524 // non-empty parentheses
1525 fn lorem<T: Eq>(t: T) {
1526     let lorem = (ipsum, dolor);
1527 }
1528
1529 // non-empty square brackets
1530 let lorem: [usize; 2] = [ipsum, dolor];
1531 ```
1532
1533 #### `true`:
1534
1535 ```rust
1536 // generic arguments
1537 fn lorem< T: Eq >(t: T) {
1538     // body
1539 }
1540
1541 // non-empty parentheses
1542 fn lorem<T: Eq>( t: T ) {
1543     let lorem = ( ipsum, dolor );
1544 }
1545
1546 // non-empty square brackets
1547 let lorem: [ usize; 2 ] = [ ipsum, dolor ];
1548 ```
1549
1550 ## `struct_lit_single_line`
1551
1552 Put small struct literals on a single line
1553
1554 - **Default value**: `true`
1555 - **Possible values**: `true`, `false`
1556 - **Stable**: No
1557
1558 #### `true` (default):
1559
1560 ```rust
1561 let lorem = Lorem { ipsum: dolor, sit: amet };
1562 ```
1563
1564 #### `false`:
1565
1566 ```rust
1567 let lorem = Lorem {
1568     ipsum: dolor,
1569     sit: amet,
1570 };
1571 ```
1572
1573 See also: [`indent_style`](#indent_style).
1574
1575
1576 ## `tab_spaces`
1577
1578 Number of spaces per tab
1579
1580 - **Default value**: `4`
1581 - **Possible values**: any positive integer
1582 - **Stable**: Yes
1583
1584 #### `4` (default):
1585
1586 ```rust
1587 fn lorem() {
1588     let ipsum = dolor();
1589     let sit = vec![
1590         "amet consectetur adipiscing elit."
1591     ];
1592 }
1593 ```
1594
1595 #### `2`:
1596
1597 ```rust
1598 fn lorem() {
1599   let ipsum = dolor();
1600   let sit = vec![
1601     "amet consectetur adipiscing elit."
1602   ];
1603 }
1604 ```
1605
1606 See also: [`hard_tabs`](#hard_tabs).
1607
1608
1609 ## `trailing_comma`
1610
1611 How to handle trailing commas for lists
1612
1613 - **Default value**: `"Vertical"`
1614 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
1615 - **Stable**: No
1616
1617 #### `"Vertical"` (default):
1618
1619 ```rust
1620 let Lorem { ipsum, dolor, sit } = amet;
1621 let Lorem {
1622     ipsum,
1623     dolor,
1624     sit,
1625     amet,
1626     consectetur,
1627     adipiscing,
1628 } = elit;
1629 ```
1630
1631 #### `"Always"`:
1632
1633 ```rust
1634 let Lorem { ipsum, dolor, sit, } = amet;
1635 let Lorem {
1636     ipsum,
1637     dolor,
1638     sit,
1639     amet,
1640     consectetur,
1641     adipiscing,
1642 } = elit;
1643 ```
1644
1645 #### `"Never"`:
1646
1647 ```rust
1648 let Lorem { ipsum, dolor, sit } = amet;
1649 let Lorem {
1650     ipsum,
1651     dolor,
1652     sit,
1653     amet,
1654     consectetur,
1655     adipiscing
1656 } = elit;
1657 ```
1658
1659 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1660
1661 ## `trailing_semicolon`
1662
1663 Add trailing semicolon after break, continue and return
1664
1665 - **Default value**: `true`
1666 - **Possible values**: `true`, `false`
1667 - **Stable**: No
1668
1669 #### `true` (default):
1670 ```rust
1671 fn foo() -> usize {
1672     return 0;
1673 }
1674 ```
1675
1676 #### `false`:
1677 ```rust
1678 fn foo() -> usize {
1679     return 0
1680 }
1681 ```
1682
1683 ## `type_punctuation_density`
1684
1685 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
1686
1687 - **Default value**: `"Wide"`
1688 - **Possible values**: `"Compressed"`, `"Wide"`
1689 - **Stable**: No
1690
1691 #### `"Wide"` (default):
1692
1693 ```rust
1694 fn lorem<Ipsum: Dolor + Sit = Amet>() {
1695         // body
1696 }
1697 ```
1698
1699 #### `"Compressed"`:
1700
1701 ```rust
1702 fn lorem<Ipsum: Dolor+Sit=Amet>() {
1703         // body
1704 }
1705 ```
1706
1707 ## `use_try_shorthand`
1708
1709 Replace uses of the try! macro by the ? shorthand
1710
1711 - **Default value**: `false`
1712 - **Possible values**: `true`, `false`
1713 - **Stable**: No
1714
1715 #### `false` (default):
1716
1717 ```rust
1718 let lorem = try!(ipsum.map(|dolor|dolor.sit()));
1719 ```
1720
1721 #### `true`:
1722
1723 ```rust
1724 let lorem = ipsum.map(|dolor| dolor.sit())?;
1725 ```
1726
1727
1728 ## `wrap_comments`
1729
1730 Break comments to fit on the line
1731
1732 - **Default value**: `false`
1733 - **Possible values**: `true`, `false`
1734 - **Stable**: Yes
1735
1736 #### `false` (default):
1737
1738 ```rust
1739 // 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.
1740 ```
1741
1742 #### `true`:
1743
1744 ```rust
1745 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
1746 // sed do eiusmod tempor incididunt ut labore et dolore
1747 // magna aliqua. Ut enim ad minim veniam, quis nostrud
1748 // exercitation ullamco laboris nisi ut aliquip ex ea
1749 // commodo consequat.
1750 ```
1751
1752 ## `match_arm_blocks`
1753
1754 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1755
1756 - **Default value**: `true`
1757 - **Possible values**: `true`, `false`
1758 - **Stable**: No
1759
1760 #### `true` (default):
1761
1762 ```rust
1763 match lorem {
1764     true => {
1765         foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1766     }
1767     false => println!("{}", sit),
1768 }
1769 ```
1770
1771 #### `false`:
1772
1773 ```rust
1774 match lorem {
1775     true =>
1776         foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1777     false => println!("{}", sit),
1778 }
1779 ```
1780
1781 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1782
1783 ## `write_mode`
1784
1785 What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage
1786
1787 - **Default value**: `"Overwrite"`
1788 - **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"`
1789 - **Stable**: No
1790
1791 ## `blank_lines_upper_bound`
1792
1793 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
1794 lines are found, they are trimmed down to match this integer.
1795
1796 - **Default value**: `1`
1797 - **Possible values**: *unsigned integer*
1798 - **Stable**: No
1799
1800 ### Example
1801 Original Code:
1802
1803 ```rust
1804 fn foo() {
1805     println!("a");
1806 }
1807
1808
1809
1810 fn bar() {
1811     println!("b");
1812
1813
1814     println!("c");
1815 }
1816 ```
1817
1818 #### `1` (default):
1819 ```rust
1820 fn foo() {
1821     println!("a");
1822 }
1823
1824 fn bar() {
1825     println!("b");
1826
1827     println!("c");
1828 }
1829 ```
1830
1831 #### `2` (default):
1832 ```rust
1833 fn foo() {
1834     println!("a");
1835 }
1836
1837
1838 fn bar() {
1839     println!("b");
1840
1841
1842     println!("c");
1843 }
1844 ```
1845
1846 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
1847
1848 ## `blank_lines_lower_bound`
1849
1850 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
1851 them, additional blank lines are inserted.
1852
1853 - **Default value**: `0`
1854 - **Possible values**: *unsigned integer*
1855 - **Stable**: No
1856
1857 ### Example
1858 Original Code (rustfmt will not change it with the default value of `0`):
1859
1860 ```rust
1861 fn foo() {
1862     println!("a");
1863 }
1864 fn bar() {
1865     println!("b");
1866     println!("c");
1867 }
1868 ```
1869
1870 #### `1`
1871 ```rust
1872 fn foo() {
1873
1874     println!("a");
1875 }
1876
1877 fn bar() {
1878
1879     println!("b");
1880
1881     println!("c");
1882 }
1883 ```