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