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