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