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