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