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