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