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