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