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