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