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