]> git.lizzy.rs Git - rust.git/blob - Configurations.md
Use correct budget
[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_type_annotation_colon`
1127
1128 Leave a space after the colon in a type annotation
1129
1130 - **Default value**: `true`
1131 - **Possible values**: `true`, `false`
1132
1133 #### `false`:
1134
1135 ```rust
1136 fn lorem<T: Eq>(t:T) {
1137     let ipsum:Dolor = sit;
1138 }
1139 ```
1140
1141 #### `true`:
1142
1143 ```rust
1144 fn lorem<T: Eq>(t: T) {
1145     let ipsum: Dolor = sit;
1146 }
1147 ```
1148
1149 See also: [`space_before_type_annotation`](#space_before_type_annotation).
1150
1151 ## `space_before_bound`
1152
1153 Leave a space before the colon in a trait or lifetime bound
1154
1155 - **Default value**: `false`
1156 - **Possible values**: `true`, `false`
1157
1158 #### `false`:
1159
1160 ```rust
1161 fn lorem<T: Eq>(t: T) {
1162     let ipsum: Dolor = sit;
1163 }
1164 ```
1165
1166 #### `true`:
1167
1168 ```rust
1169 fn lorem<T : Eq>(t: T) {
1170     let ipsum: Dolor = sit;
1171 }
1172 ```
1173
1174 See also: [`space_after_bound_colon`](#space_after_bound_colon).
1175
1176 ## `space_before_type_annotation`
1177
1178 Leave a space before the colon in a type annotation
1179
1180 - **Default value**: `false`
1181 - **Possible values**: `true`, `false`
1182
1183 #### `false`:
1184
1185 ```rust
1186 fn lorem<T: Eq>(t: T) {
1187     let ipsum: Dolor = sit;
1188 }
1189 ```
1190
1191 #### `true`:
1192
1193 ```rust
1194 fn lorem<T: Eq>(t : T) {
1195     let ipsum : Dolor = sit;
1196 }
1197 ```
1198
1199 See also: [`space_after_type_annotation_colon`](#space_after_type_annotation_colon).
1200
1201 ## `spaces_around_ranges`
1202
1203 Put spaces around the .. and ... range operators
1204
1205 - **Default value**: `false`
1206 - **Possible values**: `true`, `false`
1207
1208 #### `false`:
1209
1210 ```rust
1211 let lorem = 0..10;
1212 ```
1213
1214 #### `true`:
1215
1216 ```rust
1217 let lorem = 0 .. 10;
1218 ```
1219
1220 ## `spaces_within_angle_brackets`
1221
1222 Put spaces within non-empty generic arguments
1223
1224 - **Default value**: `false`
1225 - **Possible values**: `true`, `false`
1226
1227 #### `false`:
1228
1229 ```rust
1230 fn lorem<T: Eq>(t: T) {
1231     // body
1232 }
1233 ```
1234
1235 #### `true`:
1236
1237 ```rust
1238 fn lorem< T: Eq >(t: T) {
1239     // body
1240 }
1241 ```
1242
1243 See also: [`spaces_within_parens`](#spaces_within_parens), [`spaces_within_square_brackets`](#spaces_within_square_brackets).
1244
1245 ## `spaces_within_parens`
1246
1247 Put spaces within non-empty parentheses
1248
1249 - **Default value**: `false`
1250 - **Possible values**: `true`, `false`
1251
1252 #### `false`:
1253
1254 ```rust
1255 fn lorem<T: Eq>(t: T) {
1256     let lorem = (ipsum, dolor);
1257 }
1258 ```
1259
1260 #### `true`:
1261
1262 ```rust
1263 fn lorem<T: Eq>( t: T ) {
1264     let lorem = ( ipsum, dolor );
1265 }
1266 ```
1267
1268 See also: [`spaces_within_angle_brackets`](#spaces_within_angle_brackets), [`spaces_within_square_brackets`](#spaces_within_square_brackets).
1269
1270 ## `spaces_within_square_brackets`
1271
1272 Put spaces within non-empty square brackets
1273
1274 - **Default value**: `false`
1275 - **Possible values**: `true`, `false`
1276
1277 #### `false`:
1278
1279 ```rust
1280 let lorem: [usize; 2] = [ipsum, dolor];
1281 ```
1282
1283 #### `true`:
1284
1285 ```rust
1286 let lorem: [ usize; 2 ] = [ ipsum, dolor ];
1287 ```
1288
1289 See also: [`spaces_within_parens`](#spaces_within_parens), [`spaces_within_angle_brackets`](#spaces_within_angle_brackets).
1290
1291 ## `struct_lit_multiline_style`
1292
1293 Multiline style on literal structs
1294
1295 - **Default value**: `"PreferSingle"`
1296 - **Possible values**: `"ForceMulti"`, `"PreferSingle"`
1297
1298 #### `"ForceMulti"`:
1299
1300 ```rust
1301 let lorem = Lorem {
1302     ipsum: dolor,
1303     sit: amet,
1304 };
1305 ```
1306
1307 #### `"PreferSingle"`:
1308
1309 ```rust
1310 let lorem = Lorem { ipsum: dolor, sit: amet };
1311 ```
1312
1313 See also: [`struct_lit_style`](#struct_lit_style), [`struct_lit_width`](#struct_lit_width).
1314
1315 ## `struct_lit_style`
1316
1317 Style of struct definition
1318
1319 - **Default value**: `"Block"`
1320 - **Possible values**: `"Block"`, `"Visual"`
1321
1322 #### `"Block"`:
1323
1324 ```rust
1325 let lorem = Lorem {
1326     ipsum: dolor,
1327     sit: amet,
1328 };
1329 ```
1330
1331 #### `"Visual"`:
1332
1333 ```rust
1334 let lorem = Lorem { ipsum: dolor,
1335         sit: amet, };
1336 ```
1337
1338 See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
1339
1340 ## `struct_lit_width`
1341
1342 Maximum width in the body of a struct lit before falling back to vertical formatting
1343
1344 - **Default value**: `18`
1345 - **Possible values**: any positive integer
1346
1347 **Note:** A value of `0` results in vertical formatting being applied regardless of a line's width.
1348
1349 #### Lines shorter than `struct_lit_width`:
1350 ```rust
1351 let lorem = Lorem { ipsum: dolor, sit: amet };
1352 ```
1353
1354 #### Lines longer than `struct_lit_width`:
1355 See [`struct_lit_style`](#struct_lit_style).
1356
1357 See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
1358
1359 ## `struct_variant_width`
1360
1361 Maximum width in the body of a struct variant before falling back to vertical formatting
1362
1363 - **Default value**: `35`
1364 - **Possible values**: any positive integer
1365
1366 **Note:** A value of `0` results in vertical formatting being applied regardless of a line's width.
1367
1368 #### Struct variants shorter than `struct_variant_width`:
1369 ```rust
1370 enum Lorem {
1371     Ipsum,
1372     Dolor(bool),
1373     Sit { amet: Consectetur, adipiscing: Elit },
1374 }
1375 ```
1376
1377 #### Struct variants longer than `struct_variant_width`:
1378 ```rust
1379 enum Lorem {
1380     Ipsum,
1381     Dolor(bool),
1382     Sit {
1383         amet: Consectetur,
1384         adipiscing: Elit,
1385     },
1386 }
1387 ```
1388
1389 ## `tab_spaces`
1390
1391 Number of spaces per tab
1392
1393 - **Default value**: `4`
1394 - **Possible values**: any positive integer
1395
1396 #### `2`:
1397
1398 ```rust
1399 fn lorem() {
1400   let ipsum = dolor();
1401   let sit = vec![
1402     "amet consectetur adipiscing elit."
1403   ];
1404 }
1405 ```
1406
1407 #### `4`:
1408
1409 ```rust
1410 fn lorem() {
1411     let ipsum = dolor();
1412     let sit = vec![
1413         "amet consectetur adipiscing elit."
1414     ];
1415 }
1416 ```
1417
1418 See also: [`hard_tabs`](#hard_tabs).
1419
1420 ## `take_source_hints`
1421
1422 Retain some formatting characteristics from the source code
1423
1424 - **Default value**: `false`
1425 - **Possible values**: `true`, `false`
1426
1427 #### `false`:
1428
1429 ```rust
1430 lorem
1431     .ipsum()
1432     .dolor(|| { sit.amet().consectetur().adipiscing().elit(); });
1433 ```
1434
1435 #### `true`:
1436
1437 ```rust
1438 lorem
1439     .ipsum()
1440     .dolor(|| {
1441                sit.amet()
1442                    .consectetur()
1443                    .adipiscing()
1444                    .elit();
1445            });
1446 ```
1447
1448 Note: This only applies if the call chain within the inner closure had already been formatted on separate lines before running rustfmt.
1449
1450 ## `trailing_comma`
1451
1452 How to handle trailing commas for lists
1453
1454 - **Default value**: `"Vertical"`
1455 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
1456
1457 #### `"Always"`:
1458
1459 ```rust
1460 let Lorem { ipsum, dolor, sit, } = amet;
1461 let Lorem {
1462     ipsum,
1463     dolor,
1464     sit,
1465     amet,
1466     consectetur,
1467     adipiscing,
1468 } = elit;
1469 ```
1470
1471 #### `"Never"`:
1472
1473 ```rust
1474 let Lorem { ipsum, dolor, sit } = amet;
1475 let Lorem {
1476     ipsum,
1477     dolor,
1478     sit,
1479     amet,
1480     consectetur,
1481     adipiscing
1482 } = elit;
1483 ```
1484
1485 #### `"Vertical"`:
1486
1487 ```rust
1488 let Lorem { ipsum, dolor, sit } = amet;
1489 let Lorem {
1490     ipsum,
1491     dolor,
1492     sit,
1493     amet,
1494     consectetur,
1495     adipiscing,
1496 } = elit;
1497 ```
1498
1499 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1500
1501 ## `type_punctuation_density`
1502
1503 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
1504
1505 - **Default value**: `"Wide"`
1506 - **Possible values**: `"Compressed"`, `"Wide"`
1507
1508 #### `"Compressed"`:
1509
1510 ```rust
1511 fn lorem<Ipsum: Dolor+Sit=Amet>() {
1512         // body
1513 }
1514 ```
1515
1516 #### `"Wide"`:
1517
1518 ```rust
1519 fn lorem<Ipsum: Dolor + Sit = Amet>() {
1520         // body
1521 }
1522 ```
1523
1524 ## `use_try_shorthand`
1525
1526 Replace uses of the try! macro by the ? shorthand
1527
1528 - **Default value**: `false`
1529 - **Possible values**: `true`, `false`
1530
1531 #### `false`:
1532
1533 ```rust
1534 let lorem = try!(ipsum.map(|dolor|dolor.sit()));
1535 ```
1536
1537 #### `true`:
1538
1539 ```rust
1540 let lorem = ipsum.map(|dolor| dolor.sit())?;
1541 ```
1542
1543 ## `where_density`
1544
1545 Density of a where clause
1546
1547 - **Default value**: `"CompressedIfEmpty"`
1548 - **Possible values**: `"Compressed"`, `"CompressedIfEmpty"`, `"Tall"`, `"Vertical"`
1549
1550 #### `"Compressed"`:
1551
1552 ```rust
1553 trait Lorem {
1554     fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
1555
1556     fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq {
1557         // body
1558     }
1559 }
1560 ```
1561
1562 #### `"CompressedIfEmpty"`:
1563
1564 ```rust
1565 trait Lorem {
1566     fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
1567
1568     fn ipsum<Dolor>(dolor: Dolor) -> Sit
1569         where Dolor: Eq
1570     {
1571         // body
1572     }
1573 }
1574 ```
1575
1576 #### `"Tall"`:
1577
1578 ```rust
1579 trait Lorem {
1580     fn ipsum<Dolor>(dolor: Dolor) -> Sit
1581         where Dolor: Eq;
1582
1583     fn ipsum<Dolor>(dolor: Dolor) -> Sit
1584         where Dolor: Eq
1585     {
1586         // body
1587     }
1588 }
1589 ```
1590
1591 **Note:** `where_density = "Tall"` currently produces the same output as `where_density = "Vertical"`.
1592
1593 #### `"Vertical"`:
1594
1595 ```rust
1596 trait Lorem {
1597     fn ipsum<Dolor>(dolor: Dolor) -> Sit
1598         where Dolor: Eq;
1599
1600     fn ipsum<Dolor>(dolor: Dolor) -> Sit
1601         where Dolor: Eq
1602     {
1603         // body
1604     }
1605 }
1606 ```
1607
1608 **Note:** `where_density = "Vertical"` currently produces the same output as `where_density = "Tall"`.
1609
1610 See also: [`where_layout`](#where_layout), [`where_pred_indent`](#where_pred_indent), [`where_style`](#where_style).
1611
1612 ## `where_layout`
1613
1614 Element layout inside a where clause
1615
1616 - **Default value**: `"Vertical"`
1617 - **Possible values**: `"Horizontal"`, `"HorizontalVertical"`, `"Mixed"`, `"Vertical"`
1618
1619 #### `"Horizontal"`:
1620
1621 ```rust
1622 fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1623     where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
1624 {
1625     // body
1626 }
1627
1628 fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
1629     where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit
1630 {
1631     // body
1632 }
1633 ```
1634
1635 #### `"HorizontalVertical"`:
1636
1637 ```rust
1638 fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1639     where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
1640 {
1641     // body
1642 }
1643
1644 fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
1645     where Ipsum: IpsumDolorSitAmet,
1646           Dolor: DolorSitAmetConsectetur,
1647           Sit: SitAmetConsecteturAdipiscing,
1648           Amet: AmetConsecteturAdipiscingElit
1649 {
1650     // body
1651 }
1652 ```
1653
1654 #### `"Mixed"`:
1655
1656 ```rust
1657 fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1658     where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
1659 {
1660     // body
1661 }
1662
1663 fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
1664     where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur,
1665           Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit
1666 {
1667     // body
1668 }
1669 ```
1670
1671 #### `"Vertical"`:
1672
1673 ```rust
1674 fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1675     where Ipsum: IpsumDolorSitAmet,
1676           Dolor: DolorSitAmetConsectetur
1677 {
1678     // body
1679 }
1680
1681 fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
1682     where Ipsum: IpsumDolorSitAmet,
1683           Dolor: DolorSitAmetConsectetur,
1684           Sit: SitAmetConsecteturAdipiscing,
1685           Amet: AmetConsecteturAdipiscingElit
1686 {
1687     // body
1688 }
1689 ```
1690
1691 See also: [`where_density`](#where_density), [`where_pred_indent`](#where_pred_indent), [`where_style`](#where_style).
1692
1693 ## `where_pred_indent`
1694
1695 Indentation style of a where predicate
1696
1697 - **Default value**: `"Visual"`
1698 - **Possible values**: `"Block"`, `"Visual"`
1699
1700 #### `"Block"`:
1701
1702 ```rust
1703 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1704     where Ipsum: Eq,
1705         Dolor: Eq,
1706         Sit: Eq,
1707         Amet: Eq
1708 {
1709     // body
1710 }
1711 ```
1712
1713 #### `"Visual"`:
1714
1715 ```rust
1716 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1717     where Ipsum: Eq,
1718           Dolor: Eq,
1719           Sit: Eq,
1720           Amet: Eq
1721 {
1722     // body
1723 }
1724 ```
1725
1726 See also: [`where_density`](#where_density), [`where_layout`](#where_layout), [`where_style`](#where_style).
1727
1728 ## `where_style`
1729
1730 Overall strategy for where clauses
1731
1732 - **Default value**: `"Default"`
1733 - **Possible values**: `"Default"`, `"Rfc"`
1734
1735 #### `"Default"`:
1736
1737 ```rust
1738 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1739     where Ipsum: Eq,
1740           Dolor: Eq,
1741           Sit: Eq,
1742           Amet: Eq
1743 {
1744     // body
1745 }
1746 ```
1747
1748 #### `"Rfc"`:
1749
1750 ```rust
1751 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1752 where
1753     Ipsum: Eq,
1754     Dolor: Eq,
1755     Sit: Eq,
1756     Amet: Eq,
1757 {
1758     // body
1759 }
1760 ```
1761
1762 See also: [`where_density`](#where_density), [`where_layout`](#where_layout), [`where_pred_indent`](#where_pred_indent).
1763
1764 ## `wrap_comments`
1765
1766 Break comments to fit on the line
1767
1768 - **Default value**: `false`
1769 - **Possible values**: `true`, `false`
1770
1771 #### `false`:
1772
1773 ```rust
1774 // 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.
1775 ```
1776
1777 #### `true`:
1778
1779 ```rust
1780 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
1781 // sed do eiusmod tempor incididunt ut labore et dolore
1782 // magna aliqua. Ut enim ad minim veniam, quis nostrud
1783 // exercitation ullamco laboris nisi ut aliquip ex ea
1784 // commodo consequat.
1785 ```
1786
1787 ## `wrap_match_arms`
1788
1789 Wrap multiline match arms in blocks
1790
1791 - **Default value**: `true`
1792 - **Possible values**: `true`, `false`
1793
1794 #### `false`:
1795
1796 ```rust
1797 match lorem {
1798     true => {
1799         let ipsum = dolor;
1800         println!("{}", ipsum);
1801     }
1802     false => {
1803         println!("{}", sit)
1804     }
1805 }
1806 ```
1807
1808 #### `true`:
1809
1810 ```rust
1811 match lorem {
1812     true => {
1813         let ipsum = dolor;
1814         println!("{}", ipsum);
1815     }
1816     false => println!("{}", sit),
1817 }
1818 ```
1819
1820 See also: [`indent_match_arms`](#indent_match_arms), [`match_block_trailing_comma`](#match_block_trailing_comma).
1821
1822 ## `write_mode`
1823
1824 What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage
1825
1826 - **Default value**: `"Replace"`
1827 - **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"`