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