]> git.lizzy.rs Git - rust.git/blob - Configurations.md
/s/featuers/features
[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 indent_style = "Block"
9 reorder_imported_names = true
10 ```
11
12 Each configuration option is either stable or unstable.
13 Stable options can be used directly, while unstable options are opt-in.
14 To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or pass `--unstable-features` to rustfmt.
15
16 # Configuration Options
17
18 Below you find a detailed visual guide on all the supported configuration options of rustfmt:
19
20
21 ## `indent_style`
22
23 Indent on expressions or items.
24
25 - **Default value**: `"Block"`
26 - **Possible values**: `"Block"`, `"Visual"`
27 - **Stable**: No
28
29 ### Array
30
31 #### `"Block"` (default):
32
33 ```rust
34 fn main() {
35     let lorem = vec![
36         "ipsum",
37         "dolor",
38         "sit",
39         "amet",
40         "consectetur",
41         "adipiscing",
42         "elit",
43     ];
44 }
45 ```
46
47 #### `"Visual"`:
48
49 ```rust
50 fn main() {
51     let lorem = vec!["ipsum",
52                      "dolor",
53                      "sit",
54                      "amet",
55                      "consectetur",
56                      "adipiscing",
57                      "elit"];
58 }
59 ```
60
61 ### Control flow
62
63 #### `"Block"` (default):
64
65 ```rust
66 fn main() {
67     if lorem_ipsum && dolor_sit && amet_consectetur && lorem_sit && dolor_consectetur && amet_ipsum
68         && lorem_consectetur
69     {
70         // ...
71     }
72 }
73 ```
74
75 #### `"Visual"`:
76
77 ```rust
78 fn main() {
79     if lorem_ipsum && dolor_sit && amet_consectetur && lorem_sit && dolor_consectetur && amet_ipsum
80        && lorem_consectetur
81     {
82         // ...
83     }
84 }
85 ```
86
87 See also: [`control_brace_style`](#control_brace_style).
88
89 ### Function arguments
90
91 #### `"Block"` (default):
92
93 ```rust
94 fn lorem() {}
95
96 fn lorem(ipsum: usize) {}
97
98 fn lorem(
99     ipsum: usize,
100     dolor: usize,
101     sit: usize,
102     amet: usize,
103     consectetur: usize,
104     adipiscing: usize,
105     elit: usize,
106 ) {
107     // body
108 }
109 ```
110
111 #### `"Visual"`:
112
113 ```rust
114 fn lorem() {}
115
116 fn lorem(ipsum: usize) {}
117
118 fn lorem(ipsum: usize,
119          dolor: usize,
120          sit: usize,
121          amet: usize,
122          consectetur: usize,
123          adipiscing: usize,
124          elit: usize) {
125     // body
126 }
127 ```
128
129 ### Function calls
130
131 #### `"Block"` (default):
132
133 ```rust
134 fn main() {
135     lorem(
136         "lorem",
137         "ipsum",
138         "dolor",
139         "sit",
140         "amet",
141         "consectetur",
142         "adipiscing",
143         "elit",
144     );
145 }
146 ```
147
148 #### `"Visual"`:
149
150 ```rust
151 fn main() {
152     lorem("lorem",
153           "ipsum",
154           "dolor",
155           "sit",
156           "amet",
157           "consectetur",
158           "adipiscing",
159           "elit");
160 }
161 ```
162
163 ### Generics
164
165 #### `"Block"` (default):
166
167 ```rust
168 fn lorem<
169     Ipsum: Eq = usize,
170     Dolor: Eq = usize,
171     Sit: Eq = usize,
172     Amet: Eq = usize,
173     Adipiscing: Eq = usize,
174     Consectetur: Eq = usize,
175     Elit: Eq = usize,
176 >(
177     ipsum: Ipsum,
178     dolor: Dolor,
179     sit: Sit,
180     amet: Amet,
181     adipiscing: Adipiscing,
182     consectetur: Consectetur,
183     elit: Elit,
184 ) -> T {
185     // body
186 }
187 ```
188
189 #### `"Visual"`:
190
191 ```rust
192 fn lorem<Ipsum: Eq = usize,
193          Dolor: Eq = usize,
194          Sit: Eq = usize,
195          Amet: Eq = usize,
196          Adipiscing: Eq = usize,
197          Consectetur: Eq = usize,
198          Elit: Eq = usize>(
199     ipsum: Ipsum,
200     dolor: Dolor,
201     sit: Sit,
202     amet: Amet,
203     adipiscing: Adipiscing,
204     consectetur: Consectetur,
205     elit: Elit)
206     -> T {
207     // body
208 }
209 ```
210
211 #### Struct
212
213 #### `"Block"` (default):
214
215 ```rust
216 fn main() {
217     let lorem = Lorem {
218         ipsum: dolor,
219         sit: amet,
220     };
221 }
222 ```
223
224 #### `"Visual"`:
225
226 ```rust
227 fn main() {
228     let lorem = Lorem { ipsum: dolor,
229                         sit: amet, };
230 }
231 ```
232
233 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
234
235 ### Where predicates
236
237 #### `"Block"` (default):
238
239 ```rust
240 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
241 where
242     Ipsum: Eq,
243     Dolor: Eq,
244     Sit: Eq,
245     Amet: Eq,
246 {
247     // body
248 }
249 ```
250
251 #### `"Visual"`:
252
253 ```rust
254 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
255     where Ipsum: Eq,
256           Dolor: Eq,
257           Sit: Eq,
258           Amet: Eq
259 {
260     // body
261 }
262 ```
263
264 ## `use_small_heuristics`
265
266 Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
267
268 - **Default value**: `true`
269 - **Possible values**: `true`, `false`
270 - **Stable**: No
271
272 #### `true` (default):
273
274 ```rust
275 enum Lorem {
276     Ipsum,
277     Dolor(bool),
278     Sit { amet: Consectetur, adipiscing: Elit },
279 }
280
281 fn main() {
282     lorem(
283         "lorem",
284         "ipsum",
285         "dolor",
286         "sit",
287         "amet",
288         "consectetur",
289         "adipiscing",
290     );
291
292     let lorem = Lorem {
293         ipsum: dolor,
294         sit: amet,
295     };
296     let lorem = Lorem { ipsum: dolor };
297
298     let lorem = if ipsum { dolor } else { sit };
299 }
300 ```
301
302 #### `false`:
303
304 ```rust
305 enum Lorem {
306     Ipsum,
307     Dolor(bool),
308     Sit {
309         amet: Consectetur,
310         adipiscing: Elit,
311     },
312 }
313
314 fn main() {
315     lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
316
317     let lorem = Lorem {
318         ipsum: dolor,
319         sit: amet,
320     };
321
322     let lorem = if ipsum {
323         dolor
324     } else {
325         sit
326     };
327 }
328 ```
329
330 ## `binop_separator`
331
332 Where to put a binary operator when a binary expression goes multiline.
333
334 - **Default value**: `"Front"`
335 - **Possible values**: `"Front"`, `"Back"`
336 - **Stable**: No
337
338 #### `"Front"` (default):
339
340 ```rust
341 fn main() {
342     let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
343         || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
344
345     let sum = 123456789012345678901234567890 + 123456789012345678901234567890
346         + 123456789012345678901234567890;
347
348     let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
349         ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
350 }
351 ```
352
353 #### `"Back"`:
354
355 ```rust
356 fn main() {
357     let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
358         barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
359
360     let sum = 123456789012345678901234567890 + 123456789012345678901234567890 +
361         123456789012345678901234567890;
362
363     let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
364         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
365 }
366 ```
367
368 ## `combine_control_expr`
369
370 Combine control expressions with function calls.
371
372 - **Default value**: `true`
373 - **Possible values**: `true`, `false`
374 - **Stable**: No
375
376 #### `true` (default):
377
378 ```rust
379 fn example() {
380     // If
381     foo!(if x {
382         foo();
383     } else {
384         bar();
385     });
386
387     // IfLet
388     foo!(if let Some(..) = x {
389         foo();
390     } else {
391         bar();
392     });
393
394     // While
395     foo!(while x {
396         foo();
397         bar();
398     });
399
400     // WhileLet
401     foo!(while let Some(..) = x {
402         foo();
403         bar();
404     });
405
406     // ForLoop
407     foo!(for x in y {
408         foo();
409         bar();
410     });
411
412     // Loop
413     foo!(loop {
414         foo();
415         bar();
416     });
417 }
418 ```
419
420 #### `false`:
421
422 ```rust
423 fn example() {
424     // If
425     foo!(
426         if x {
427             foo();
428         } else {
429             bar();
430         }
431     );
432
433     // IfLet
434     foo!(
435         if let Some(..) = x {
436             foo();
437         } else {
438             bar();
439         }
440     );
441
442     // While
443     foo!(
444         while x {
445             foo();
446             bar();
447         }
448     );
449
450     // WhileLet
451     foo!(
452         while let Some(..) = x {
453             foo();
454             bar();
455         }
456     );
457
458     // ForLoop
459     foo!(
460         for x in y {
461             foo();
462             bar();
463         }
464     );
465
466     // Loop
467     foo!(
468         loop {
469             foo();
470             bar();
471         }
472     );
473 }
474 ```
475
476 ## `comment_width`
477
478 Maximum length of comments. No effect unless`wrap_comments = true`.
479
480 - **Default value**: `80`
481 - **Possible values**: any positive integer
482 - **Stable**: No
483
484 **Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
485
486 #### `80` (default; comments shorter than `comment_width`):
487 ```rust
488 // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
489 ```
490
491 #### `60` (comments longer than `comment_width`):
492 ```rust
493 // Lorem ipsum dolor sit amet,
494 // consectetur adipiscing elit.
495 ```
496
497 See also [`wrap_comments`](#wrap_comments).
498
499 ## `condense_wildcard_suffixes`
500
501 Replace strings of _ wildcards by a single .. in tuple patterns
502
503 - **Default value**: `false`
504 - **Possible values**: `true`, `false`
505 - **Stable**: No
506
507 #### `false` (default):
508
509 ```rust
510 fn main() {
511     let (lorem, ipsum, _, _) = (1, 2, 3, 4);
512     let (lorem, ipsum, ..) = (1, 2, 3, 4);
513 }
514 ```
515
516 #### `true`:
517
518 ```rust
519 fn main() {
520     let (lorem, ipsum, ..) = (1, 2, 3, 4);
521 }
522 ```
523
524 ## `control_brace_style`
525
526 Brace style for control flow constructs
527
528 - **Default value**: `"AlwaysSameLine"`
529 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
530 - **Stable**: No
531
532 #### `"AlwaysSameLine"` (default):
533
534 ```rust
535 fn main() {
536     if lorem {
537         println!("ipsum!");
538     } else {
539         println!("dolor!");
540     }
541 }
542 ```
543
544 #### `"AlwaysNextLine"`:
545
546 ```rust
547 fn main() {
548     if lorem
549     {
550         println!("ipsum!");
551     }
552     else
553     {
554         println!("dolor!");
555     }
556 }
557 ```
558
559 #### `"ClosingNextLine"`:
560
561 ```rust
562 fn main() {
563     if lorem {
564         println!("ipsum!");
565     }
566     else {
567         println!("dolor!");
568     }
569 }
570 ```
571
572 ## `disable_all_formatting`
573
574 Don't reformat anything
575
576 - **Default value**: `false`
577 - **Possible values**: `true`, `false`
578 - **Stable**: No
579
580 ## `error_on_line_overflow`
581
582 Error if unable to get all lines within `max_width`, except for comments and string literals.
583
584 - **Default value**: `true`
585 - **Possible values**: `true`, `false`
586 - **Stable**: No
587
588 See also [`max_width`](#max_width).
589
590 ## `error_on_unformatted`
591
592 Error if unable to get comments or string literals within `max_width`, or they are left with
593 trailing whitespaces.
594
595 - **Default value**: `false`
596 - **Possible values**: `true`, `false`
597 - **Stable**: No
598
599 ## `fn_args_density`
600
601 Argument density in functions
602
603 - **Default value**: `"Tall"`
604 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
605 - **Stable**: No
606
607 #### `"Tall"` (default):
608
609 ```rust
610 trait Lorem {
611     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
612
613     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
614         // body
615     }
616
617     fn lorem(
618         ipsum: Ipsum,
619         dolor: Dolor,
620         sit: Sit,
621         amet: Amet,
622         consectetur: Consectetur,
623         adipiscing: Adipiscing,
624         elit: Elit,
625     );
626
627     fn lorem(
628         ipsum: Ipsum,
629         dolor: Dolor,
630         sit: Sit,
631         amet: Amet,
632         consectetur: Consectetur,
633         adipiscing: Adipiscing,
634         elit: Elit,
635     ) {
636         // body
637     }
638 }
639 ```
640
641 #### `"Compressed"`:
642
643 ```rust
644 trait Lorem {
645     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
646
647     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
648         // body
649     }
650
651     fn lorem(
652         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
653         adipiscing: Adipiscing, elit: Elit,
654     );
655
656     fn lorem(
657         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
658         adipiscing: Adipiscing, elit: Elit,
659     ) {
660         // body
661     }
662 }
663 ```
664
665 #### `"Vertical"`:
666
667 ```rust
668 trait Lorem {
669     fn lorem(
670         ipsum: Ipsum,
671         dolor: Dolor,
672         sit: Sit,
673         amet: Amet,
674     );
675
676     fn lorem(
677         ipsum: Ipsum,
678         dolor: Dolor,
679         sit: Sit,
680         amet: Amet,
681     ) {
682         // body
683     }
684
685     fn lorem(
686         ipsum: Ipsum,
687         dolor: Dolor,
688         sit: Sit,
689         amet: Amet,
690         consectetur: Consectetur,
691         adipiscing: Adipiscing,
692         elit: Elit,
693     );
694
695     fn lorem(
696         ipsum: Ipsum,
697         dolor: Dolor,
698         sit: Sit,
699         amet: Amet,
700         consectetur: Consectetur,
701         adipiscing: Adipiscing,
702         elit: Elit,
703     ) {
704         // body
705     }
706 }
707 ```
708
709
710 ## `brace_style`
711
712 Brace style for items
713
714 - **Default value**: `"SameLineWhere"`
715 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
716 - **Stable**: No
717
718 ### Functions
719
720 #### `"SameLineWhere"` (default):
721
722 ```rust
723 fn lorem() {
724     // body
725 }
726
727 fn lorem(ipsum: usize) {
728     // body
729 }
730
731 fn lorem<T>(ipsum: T)
732 where
733     T: Add + Sub + Mul + Div,
734 {
735     // body
736 }
737 ```
738
739 #### `"AlwaysNextLine"`:
740
741 ```rust
742 fn lorem()
743 {
744     // body
745 }
746
747 fn lorem(ipsum: usize)
748 {
749     // body
750 }
751
752 fn lorem<T>(ipsum: T)
753 where
754     T: Add + Sub + Mul + Div,
755 {
756     // body
757 }
758 ```
759
760 #### `"PreferSameLine"`:
761
762 ```rust
763 fn lorem() {
764     // body
765 }
766
767 fn lorem(ipsum: usize) {
768     // body
769 }
770
771 fn lorem<T>(ipsum: T)
772 where
773     T: Add + Sub + Mul + Div, {
774     // body
775 }
776 ```
777
778 ### Structs and enums
779
780 #### `"SameLineWhere"` (default):
781
782 ```rust
783 struct Lorem {
784     ipsum: bool,
785 }
786
787 struct Dolor<T>
788 where
789     T: Eq,
790 {
791     sit: T,
792 }
793 ```
794
795 #### `"AlwaysNextLine"`:
796
797 ```rust
798 struct Lorem
799 {
800     ipsum: bool,
801 }
802
803 struct Dolor<T>
804 where
805     T: Eq,
806 {
807     sit: T,
808 }
809 ```
810
811 #### `"PreferSameLine"`:
812
813 ```rust
814 struct Lorem {
815     ipsum: bool,
816 }
817
818 struct Dolor<T>
819 where
820     T: Eq, {
821     sit: T,
822 }
823 ```
824
825
826 ## `empty_item_single_line`
827
828 Put empty-body functions and impls on a single line
829
830 - **Default value**: `true`
831 - **Possible values**: `true`, `false`
832 - **Stable**: No
833
834 #### `true` (default):
835
836 ```rust
837 fn lorem() {}
838
839 impl Lorem {}
840 ```
841
842 #### `false`:
843
844 ```rust
845 fn lorem() {
846 }
847
848 impl Lorem {
849 }
850 ```
851
852 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
853
854
855 ## `fn_single_line`
856
857 Put single-expression functions on a single line
858
859 - **Default value**: `false`
860 - **Possible values**: `true`, `false`
861 - **Stable**: No
862
863 #### `false` (default):
864
865 ```rust
866 fn lorem() -> usize {
867     42
868 }
869
870 fn lorem() -> usize {
871     let ipsum = 42;
872     ipsum
873 }
874 ```
875
876 #### `true`:
877
878 ```rust
879 fn lorem() -> usize { 42 }
880
881 fn lorem() -> usize {
882     let ipsum = 42;
883     ipsum
884 }
885 ```
886
887 See also [`control_brace_style`](#control_brace_style).
888
889
890 ## `where_single_line`
891
892 To force single line where layout
893
894 - **Default value**: `false`
895 - **Possible values**: `true`, `false`
896 - **Stable**: No
897
898 #### `false` (default):
899
900 ```rust
901 impl<T> Lorem for T
902 where
903     Option<T>: Ipsum,
904 {
905     // body
906 }
907 ```
908
909 #### `true`:
910
911 ```rust
912 impl<T> Lorem for T
913 where Option<T>: Ipsum
914 {
915     // body
916 }
917 ```
918
919 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
920
921
922 ## `force_explicit_abi`
923
924 Always print the abi for extern items
925
926 - **Default value**: `true`
927 - **Possible values**: `true`, `false`
928 - **Stable**: Yes
929
930 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
931
932 #### `true` (default):
933
934 ```rust
935 extern "C" {
936     pub static lorem: c_int;
937 }
938 ```
939
940 #### `false`:
941
942 ```rust
943 extern {
944     pub static lorem: c_int;
945 }
946 ```
947
948 ## `format_strings`
949
950 Format string literals where necessary
951
952 - **Default value**: `false`
953 - **Possible values**: `true`, `false`
954 - **Stable**: No
955
956 #### `false` (default):
957
958 ```rust
959 fn main() {
960     let lorem =
961         "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
962 }
963 ```
964
965 #### `true`:
966
967 ```rust
968 fn main() {
969     let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
970                  consectetur adipiscing";
971 }
972 ```
973
974 See also [`max_width`](#max_width).
975
976 ## `hard_tabs`
977
978 Use tab characters for indentation, spaces for alignment
979
980 - **Default value**: `false`
981 - **Possible values**: `true`, `false`
982 - **Stable**: Yes
983
984 #### `false` (default):
985
986 ```rust
987 fn lorem() -> usize {
988     42 // spaces before 42
989 }
990 ```
991
992 #### `true`:
993
994 ```rust
995 fn lorem() -> usize {
996         42 // tabs before 42
997 }
998 ```
999
1000 See also: [`tab_spaces`](#tab_spaces).
1001
1002
1003 ## `imports_indent`
1004
1005 Indent style of imports
1006
1007 - **Default Value**: `"Visual"`
1008 - **Possible values**: `"Block"`, `"Visual"`
1009 - **Stable**: No
1010
1011 #### `"Visual"` (default):
1012
1013 ```rust
1014 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1015           zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1016 ```
1017
1018 #### `"Block"`:
1019
1020 ```rust
1021 use foo::{
1022     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1023     zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1024 };
1025 ```
1026
1027 See also: [`imports_layout`](#imports_layout).
1028
1029 ## `imports_layout`
1030
1031 Item layout inside a imports block
1032
1033 - **Default value**: "Mixed"
1034 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1035 - **Stable**: No
1036
1037 #### `"Mixed"` (default):
1038
1039 ```rust
1040 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1041
1042 use foo::{aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1043           eeeeeeeeeeeeeeeeee, ffffffffffffffffff};
1044 ```
1045
1046 #### `"Horizontal"`:
1047
1048 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1049
1050 ```rust
1051 use foo::{xxx, yyy, zzz};
1052
1053 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1054 ```
1055
1056 #### `"HorizontalVertical"`:
1057
1058 ```rust
1059 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1060
1061 use foo::{aaaaaaaaaaaaaaaaaa,
1062           bbbbbbbbbbbbbbbbbb,
1063           cccccccccccccccccc,
1064           dddddddddddddddddd,
1065           eeeeeeeeeeeeeeeeee,
1066           ffffffffffffffffff};
1067 ```
1068
1069 #### `"Vertical"`:
1070
1071 ```rust
1072 use foo::{xxx,
1073           yyy,
1074           zzz};
1075
1076 use foo::{aaa,
1077           bbb,
1078           ccc,
1079           ddd,
1080           eee,
1081           fff};
1082 ```
1083
1084
1085 ## `match_block_trailing_comma`
1086
1087 Put a trailing comma after a block based match arm (non-block arms are not affected)
1088
1089 - **Default value**: `false`
1090 - **Possible values**: `true`, `false`
1091 - **Stable**: No
1092
1093 #### `false` (default):
1094
1095 ```rust
1096 fn main() {
1097     match lorem {
1098         Lorem::Ipsum => {
1099             println!("ipsum");
1100         }
1101         Lorem::Dolor => println!("dolor"),
1102     }
1103 }
1104 ```
1105
1106 #### `true`:
1107
1108 ```rust
1109 fn main() {
1110     match lorem {
1111         Lorem::Ipsum => {
1112             println!("ipsum");
1113         },
1114         Lorem::Dolor => println!("dolor"),
1115     }
1116 }
1117 ```
1118
1119 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1120
1121 ## `max_width`
1122
1123 Maximum width of each line
1124
1125 - **Default value**: `100`
1126 - **Possible values**: any positive integer
1127 - **Stable**: Yes
1128
1129 See also [`error_on_line_overflow`](#error_on_line_overflow).
1130
1131 ## `merge_derives`
1132
1133 Merge multiple derives into a single one.
1134
1135 - **Default value**: `true`
1136 - **Possible values**: `true`, `false`
1137 - **Stable**: Yes
1138
1139 #### `true` (default):
1140
1141 ```rust
1142 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1143 pub enum Foo {}
1144 ```
1145
1146 #### `false`:
1147
1148 ```rust
1149 #[derive(Eq, PartialEq)]
1150 #[derive(Debug)]
1151 #[derive(Copy, Clone)]
1152 pub enum Foo {}
1153 ```
1154
1155 ## `force_multiline_blocks`
1156
1157 Force multiline closure and match arm bodies to be wrapped in a block
1158
1159 - **Default value**: `false`
1160 - **Possible values**: `false`, `true`
1161 - **Stable**: No
1162
1163 #### `false` (default):
1164
1165 ```rust
1166 fn main() {
1167     result.and_then(|maybe_value| match maybe_value {
1168         None => foo(),
1169         Some(value) => bar(),
1170     });
1171
1172     match lorem {
1173         None => if ipsum {
1174             println!("Hello World");
1175         },
1176         Some(dolor) => foo(),
1177     }
1178 }
1179 ```
1180
1181 #### `true`:
1182
1183 ```rust
1184 fn main() {
1185     result.and_then(|maybe_value| {
1186         match maybe_value {
1187             None => foo(),
1188             Some(value) => bar(),
1189         }
1190     });
1191
1192     match lorem {
1193         None => {
1194             if ipsum {
1195                 println!("Hello World");
1196             }
1197         }
1198         Some(dolor) => foo(),
1199     }
1200 }
1201 ```
1202
1203
1204 ## `newline_style`
1205
1206 Unix or Windows line endings
1207
1208 - **Default value**: `"Unix"`
1209 - **Possible values**: `"Native"`, `"Unix"`, `"Windows"`
1210 - **Stable**: Yes
1211
1212 ## `normalize_comments`
1213
1214 Convert /* */ comments to // comments where possible
1215
1216 - **Default value**: `false`
1217 - **Possible values**: `true`, `false`
1218 - **Stable**: Yes
1219
1220 #### `false` (default):
1221
1222 ```rust
1223 // Lorem ipsum:
1224 fn dolor() -> usize {}
1225
1226 /* sit amet: */
1227 fn adipiscing() -> usize {}
1228 ```
1229
1230 #### `true`:
1231
1232 ```rust
1233 // Lorem ipsum:
1234 fn dolor() -> usize {}
1235
1236 // sit amet:
1237 fn adipiscing() -> usize {}
1238 ```
1239
1240 ## `reorder_imported_names`
1241
1242 Reorder lists of names in import statements alphabetically
1243
1244 - **Default value**: `false`
1245 - **Possible values**: `true`, `false`
1246 - **Stable**: No
1247
1248 #### `false` (default):
1249
1250 ```rust
1251 use super::{lorem, ipsum, dolor, sit};
1252 ```
1253
1254 #### `true`:
1255
1256 ```rust
1257 use super::{dolor, ipsum, lorem, sit};
1258 ```
1259
1260 See also [`reorder_imports`](#reorder_imports).
1261
1262 ## `reorder_imports`
1263
1264 Reorder import statements alphabetically
1265
1266 - **Default value**: `false`
1267 - **Possible values**: `true`, `false`
1268 - **Stable**: No
1269
1270 #### `false` (default):
1271
1272 ```rust
1273 use lorem;
1274 use ipsum;
1275 use dolor;
1276 use sit;
1277 ```
1278
1279 #### `true`:
1280
1281 ```rust
1282 use dolor;
1283 use ipsum;
1284 use lorem;
1285 use sit;
1286 ```
1287
1288 See also [`reorder_imported_names`](#reorder_imported_names), [`reorder_imports_in_group`](#reorder_imports_in_group).
1289
1290 ## `reorder_imports_in_group`
1291
1292 Reorder import statements in group
1293
1294 - **Default value**: `false`
1295 - **Possible values**: `true`, `false`
1296 - **Stable**: No
1297
1298 **Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`.
1299
1300 #### `true` (default):
1301
1302 ```rust
1303 use std::io;
1304 use std::mem;
1305
1306 use dolor;
1307 use ipsum;
1308 use lorem;
1309 use sit;
1310 ```
1311
1312 #### `false`:
1313
1314
1315 ```rust
1316 use dolor;
1317 use ipsum;
1318 use lorem;
1319 use sit;
1320 use std::io;
1321 use std::mem;
1322 ```
1323
1324 See also [`reorder_imports`](#reorder_imports).
1325
1326 ## `reorder_extern_crates`
1327
1328 Reorder `extern crate` statements alphabetically
1329
1330 - **Default value**: `true`
1331 - **Possible values**: `true`, `false`
1332 - **Stable**: No
1333
1334 #### `true` (default):
1335
1336 ```rust
1337 extern crate dolor;
1338 extern crate ipsum;
1339 extern crate lorem;
1340 extern crate sit;
1341 ```
1342
1343 #### `false`:
1344
1345 ```rust
1346 extern crate lorem;
1347 extern crate ipsum;
1348
1349 extern crate dolor;
1350 extern crate sit;
1351 ```
1352
1353 See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group).
1354
1355 ## `reorder_extern_crates_in_group`
1356
1357 Reorder `extern crate` statements in group
1358
1359 - **Default value**: `true`
1360 - **Possible values**: `true`, `false`
1361 - **Stable**: No
1362
1363 #### `false` (default):
1364
1365 This value has no influence beyond the effect of the [`reorder_extern_crates`](#reorder_extern_crates) option. Set [`reorder_extern_crates`](#reorder_extern_crates) to `false` if you do not want `extern crate` groups to be collapsed and ordered.
1366
1367 #### `true`:
1368
1369 **Note:** This only takes effect when [`reorder_extern_crates`](#reorder_extern_crates) is set to `true`.
1370
1371 ```rust
1372 extern crate a;
1373 extern crate b;
1374
1375 extern crate dolor;
1376 extern crate ipsum;
1377 extern crate lorem;
1378 extern crate sit;
1379 ```
1380
1381 ## `reorder_modules`
1382
1383 Reorder `mod` declarations alphabetically in group.
1384
1385 - **Default value**: `true`
1386 - **Possible values**: `true`, `false`
1387 - **Stable**: No
1388
1389 #### `true` (default)
1390
1391 ```rust
1392 mod a;
1393 mod b;
1394
1395 mod dolor;
1396 mod ipsum;
1397 mod lorem;
1398 mod sit;
1399 ```
1400
1401 #### `false`
1402
1403 ```rust
1404 mod b;
1405 mod a;
1406
1407 mod lorem;
1408 mod ipsum;
1409 mod dolor;
1410 mod sit;
1411 ```
1412
1413 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantic
1414 of the original source code.
1415
1416 ## `report_todo`
1417
1418 Report `TODO` items in comments.
1419
1420 - **Default value**: `"Never"`
1421 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1422 - **Stable**: No
1423
1424 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1425 it contains a `#X` (with `X` being a number) in parentheses following the
1426 `TODO`, `"Unnumbered"` will ignore it.
1427
1428 See also [`report_fixme`](#report_fixme).
1429
1430 ## `report_fixme`
1431
1432 Report `FIXME` items in comments.
1433
1434 - **Default value**: `"Never"`
1435 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1436 - **Stable**: No
1437
1438 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1439 it contains a `#X` (with `X` being a number) in parentheses following the
1440 `FIXME`, `"Unnumbered"` will ignore it.
1441
1442 See also [`report_todo`](#report_todo).
1443
1444
1445 ## `skip_children`
1446
1447 Don't reformat out of line modules
1448
1449 - **Default value**: `false`
1450 - **Possible values**: `true`, `false`
1451 - **Stable**: No
1452
1453 ## `space_after_colon`
1454
1455 Leave a space after the colon.
1456
1457 - **Default value**: `true`
1458 - **Possible values**: `true`, `false`
1459 - **Stable**: No
1460
1461 #### `true` (default):
1462
1463 ```rust
1464 fn lorem<T: Eq>(t: T) {
1465     let lorem: Dolor = Lorem {
1466         ipsum: dolor,
1467         sit: amet,
1468     };
1469 }
1470 ```
1471
1472 #### `false`:
1473
1474 ```rust
1475 fn lorem<T:Eq>(t:T) {
1476     let lorem:Dolor = Lorem {
1477         ipsum:dolor,
1478         sit:amet,
1479     };
1480 }
1481 ```
1482
1483 See also: [`space_before_colon`](#space_before_colon).
1484
1485 ## `space_before_colon`
1486
1487 Leave a space before the colon.
1488
1489 - **Default value**: `false`
1490 - **Possible values**: `true`, `false`
1491 - **Stable**: No
1492
1493 #### `false` (default):
1494
1495 ```rust
1496 fn lorem<T: Eq>(t: T) {
1497     let lorem: Dolor = Lorem {
1498         ipsum: dolor,
1499         sit: amet,
1500     };
1501 }
1502 ```
1503
1504 #### `true`:
1505
1506 ```rust
1507 fn lorem<T : Eq>(t : T) {
1508     let lorem : Dolor = Lorem {
1509         ipsum : dolor,
1510         sit : amet,
1511     };
1512 }
1513 ```
1514
1515 See also: [`space_after_colon`](#space_after_colon).
1516
1517 ## `struct_field_align_threshold`
1518
1519 The maximum diff of width between struct fields to be aligned with each other.
1520
1521 - **Default value** : 0
1522 - **Possible values**: any positive integer
1523 - **Stable**: No
1524
1525 #### `0` (default):
1526
1527 ```rust
1528 struct Foo {
1529     x: u32,
1530     yy: u32,
1531     zzz: u32,
1532 }
1533 ```
1534
1535 #### `20`:
1536
1537 ```rust
1538 struct Foo {
1539     x:   u32,
1540     yy:  u32,
1541     zzz: u32,
1542 }
1543 ```
1544
1545 ## `spaces_around_ranges`
1546
1547 Put spaces around the .., ..=, and ... range operators
1548
1549 - **Default value**: `false`
1550 - **Possible values**: `true`, `false`
1551 - **Stable**: No
1552
1553 #### `false` (default):
1554
1555 ```rust
1556 fn main() {
1557     let lorem = 0..10;
1558     let ipsum = 0..=10;
1559
1560     match lorem {
1561         1..5 => foo(),
1562         _ => bar,
1563     }
1564
1565     match lorem {
1566         1..=5 => foo(),
1567         _ => bar,
1568     }
1569
1570     match lorem {
1571         1...5 => foo(),
1572         _ => bar,
1573     }
1574 }
1575 ```
1576
1577 #### `true`:
1578
1579 ```rust
1580 fn main() {
1581     let lorem = 0 .. 10;
1582     let ipsum = 0 ..= 10;
1583
1584     match lorem {
1585         1 .. 5 => foo(),
1586         _ => bar,
1587     }
1588
1589     match lorem {
1590         1 ..= 5 => foo(),
1591         _ => bar,
1592     }
1593
1594     match lorem {
1595         1 ... 5 => foo(),
1596         _ => bar,
1597     }
1598 }
1599 ```
1600
1601 ## `spaces_within_parens_and_brackets`
1602
1603 Put spaces within non-empty generic arguments, parentheses, and square brackets
1604
1605 - **Default value**: `false`
1606 - **Possible values**: `true`, `false`
1607 - **Stable**: No
1608
1609 #### `false` (default):
1610
1611 ```rust
1612 // generic arguments
1613 fn lorem<T: Eq>(t: T) {
1614     // body
1615 }
1616
1617 // non-empty parentheses
1618 fn lorem<T: Eq>(t: T) {
1619     let lorem = (ipsum, dolor);
1620 }
1621
1622 // non-empty square brackets
1623 fn lorem<T: Eq>(t: T) {
1624     let lorem: [usize; 2] = [ipsum, dolor];
1625 }
1626 ```
1627
1628 #### `true`:
1629
1630 ```rust
1631 // generic arguments
1632 fn lorem< T: Eq >( t: T ) {
1633     // body
1634 }
1635
1636 // non-empty parentheses
1637 fn lorem< T: Eq >( t: T ) {
1638     let lorem = ( ipsum, dolor );
1639 }
1640
1641 // non-empty square brackets
1642 fn lorem< T: Eq >( t: T ) {
1643     let lorem: [ usize; 2 ] = [ ipsum, dolor ];
1644 }
1645 ```
1646
1647 ## `struct_lit_single_line`
1648
1649 Put small struct literals on a single line
1650
1651 - **Default value**: `true`
1652 - **Possible values**: `true`, `false`
1653 - **Stable**: No
1654
1655 #### `true` (default):
1656
1657 ```rust
1658 fn main() {
1659     let lorem = Lorem { foo: bar, baz: ofo };
1660 }
1661 ```
1662
1663 #### `false`:
1664
1665 ```rust
1666 fn main() {
1667     let lorem = Lorem {
1668         foo: bar,
1669         baz: ofo,
1670     };
1671 }
1672 ```
1673
1674 See also: [`indent_style`](#indent_style).
1675
1676
1677 ## `tab_spaces`
1678
1679 Number of spaces per tab
1680
1681 - **Default value**: `4`
1682 - **Possible values**: any positive integer
1683 - **Stable**: Yes
1684
1685 #### `4` (default):
1686
1687 ```rust
1688 fn lorem() {
1689     let ipsum = dolor();
1690     let sit = vec![
1691         "amet consectetur adipiscing elit amet consectetur adipiscing elit amet consectetur.",
1692     ];
1693 }
1694 ```
1695
1696 #### `2`:
1697
1698 ```rust
1699 fn lorem() {
1700   let ipsum = dolor();
1701   let sit = vec![
1702     "amet consectetur adipiscing elit amet consectetur adipiscing elit amet consectetur.",
1703   ];
1704 }
1705 ```
1706
1707 See also: [`hard_tabs`](#hard_tabs).
1708
1709
1710 ## `trailing_comma`
1711
1712 How to handle trailing commas for lists
1713
1714 - **Default value**: `"Vertical"`
1715 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
1716 - **Stable**: No
1717
1718 #### `"Vertical"` (default):
1719
1720 ```rust
1721 fn main() {
1722     let Lorem { ipsum, dolor, sit } = amet;
1723     let Lorem {
1724         ipsum,
1725         dolor,
1726         sit,
1727         amet,
1728         consectetur,
1729         adipiscing,
1730     } = elit;
1731 }
1732 ```
1733
1734 #### `"Always"`:
1735
1736 ```rust
1737 fn main() {
1738     let Lorem { ipsum, dolor, sit, } = amet;
1739     let Lorem {
1740         ipsum,
1741         dolor,
1742         sit,
1743         amet,
1744         consectetur,
1745         adipiscing,
1746     } = elit;
1747 }
1748 ```
1749
1750 #### `"Never"`:
1751
1752 ```rust
1753 fn main() {
1754     let Lorem { ipsum, dolor, sit } = amet;
1755     let Lorem {
1756         ipsum,
1757         dolor,
1758         sit,
1759         amet,
1760         consectetur,
1761         adipiscing
1762     } = elit;
1763 }
1764 ```
1765
1766 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1767
1768 ## `trailing_semicolon`
1769
1770 Add trailing semicolon after break, continue and return
1771
1772 - **Default value**: `true`
1773 - **Possible values**: `true`, `false`
1774 - **Stable**: No
1775
1776 #### `true` (default):
1777 ```rust
1778 fn foo() -> usize {
1779     return 0;
1780 }
1781 ```
1782
1783 #### `false`:
1784 ```rust
1785 fn foo() -> usize {
1786     return 0
1787 }
1788 ```
1789
1790 ## `type_punctuation_density`
1791
1792 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
1793
1794 - **Default value**: `"Wide"`
1795 - **Possible values**: `"Compressed"`, `"Wide"`
1796 - **Stable**: No
1797
1798 #### `"Wide"` (default):
1799
1800 ```rust
1801 fn lorem<Ipsum: Dolor + Sit = Amet>() {
1802     // body
1803 }
1804 ```
1805
1806 #### `"Compressed"`:
1807
1808 ```rust
1809 fn lorem<Ipsum: Dolor+Sit=Amet>() {
1810     // body
1811 }
1812 ```
1813
1814 ## `use_field_init_shorthand`
1815
1816 Use field initialize shorthand if possible.
1817
1818 - **Default value**: `false`
1819 - **Possible values**: `true`, `false`
1820 - **Stable**: No
1821
1822 #### `false` (default):
1823
1824 ```rust
1825 struct Foo {
1826     x: u32,
1827     y: u32,
1828     z: u32,
1829 }
1830
1831 fn main() {
1832     let x = 1;
1833     let y = 2;
1834     let z = 3;
1835     let a = Foo { x: x, y: y, z: z };
1836 }
1837 ```
1838
1839 #### `true`:
1840
1841 ```rust
1842 struct Foo {
1843     x: u32,
1844     y: u32,
1845     z: u32,
1846 }
1847
1848 fn main() {
1849     let x = 1;
1850     let y = 2;
1851     let z = 3;
1852     let a = Foo { x, y, z };
1853 }
1854 ```
1855
1856 ## `use_try_shorthand`
1857
1858 Replace uses of the try! macro by the ? shorthand
1859
1860 - **Default value**: `false`
1861 - **Possible values**: `true`, `false`
1862 - **Stable**: No
1863
1864 #### `false` (default):
1865
1866 ```rust
1867 fn main() {
1868     let lorem = try!(ipsum.map(|dolor| dolor.sit()));
1869 }
1870 ```
1871
1872 #### `true`:
1873
1874 ```rust
1875 fn main() {
1876     let lorem = ipsum.map(|dolor| dolor.sit())?;
1877 }
1878 ```
1879
1880
1881 ## `wrap_comments`
1882
1883 Break comments to fit on the line
1884
1885 - **Default value**: `false`
1886 - **Possible values**: `true`, `false`
1887 - **Stable**: Yes
1888
1889 #### `false` (default):
1890
1891 ```rust
1892 // 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.
1893 ```
1894
1895 #### `true`:
1896
1897 ```rust
1898 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
1899 // sed do eiusmod tempor incididunt ut labore et dolore
1900 // magna aliqua. Ut enim ad minim veniam, quis nostrud
1901 // exercitation ullamco laboris nisi ut aliquip ex ea
1902 // commodo consequat.
1903 ```
1904
1905 ## `match_arm_blocks`
1906
1907 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1908
1909 - **Default value**: `true`
1910 - **Possible values**: `true`, `false`
1911 - **Stable**: No
1912
1913 #### `true` (default):
1914
1915 ```rust
1916 fn main() {
1917     match lorem {
1918         true => {
1919             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1920         }
1921         false => println!("{}", sit),
1922     }
1923 }
1924 ```
1925
1926 #### `false`:
1927
1928 ```rust
1929 fn main() {
1930     match lorem {
1931         true =>
1932             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1933         false => println!("{}", sit),
1934     }
1935 }
1936 ```
1937
1938 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1939
1940 ## `write_mode`
1941
1942 What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage
1943
1944 - **Default value**: `"Overwrite"`
1945 - **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"`
1946 - **Stable**: No
1947
1948 ## `blank_lines_upper_bound`
1949
1950 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
1951 lines are found, they are trimmed down to match this integer.
1952
1953 - **Default value**: `1`
1954 - **Possible values**: *unsigned integer*
1955 - **Stable**: No
1956
1957 ### Example
1958 Original Code:
1959
1960 ```rust
1961 #![rustfmt_skip]
1962
1963 fn foo() {
1964     println!("a");
1965 }
1966
1967
1968
1969 fn bar() {
1970     println!("b");
1971
1972
1973     println!("c");
1974 }
1975 ```
1976
1977 #### `1` (default):
1978 ```rust
1979 fn foo() {
1980     println!("a");
1981 }
1982
1983 fn bar() {
1984     println!("b");
1985
1986     println!("c");
1987 }
1988 ```
1989
1990 #### `2` (default):
1991 ```rust
1992 fn foo() {
1993     println!("a");
1994 }
1995
1996
1997 fn bar() {
1998     println!("b");
1999
2000
2001     println!("c");
2002 }
2003 ```
2004
2005 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
2006
2007 ## `blank_lines_lower_bound`
2008
2009 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
2010 them, additional blank lines are inserted.
2011
2012 - **Default value**: `0`
2013 - **Possible values**: *unsigned integer*
2014 - **Stable**: No
2015
2016 ### Example
2017 Original Code (rustfmt will not change it with the default value of `0`):
2018
2019 ```rust
2020 #![rustfmt_skip]
2021
2022 fn foo() {
2023     println!("a");
2024 }
2025 fn bar() {
2026     println!("b");
2027     println!("c");
2028 }
2029 ```
2030
2031 #### `1`
2032 ```rust
2033 fn foo() {
2034
2035     println!("a");
2036 }
2037
2038 fn bar() {
2039
2040     println!("b");
2041
2042     println!("c");
2043 }
2044 ```
2045
2046 ## `remove_blank_lines_at_start_or_end_of_block`
2047
2048 Remove blank lines at the start or the end of a block.
2049
2050 - **Default value**: `true`
2051 - **Possible values**: `true`, `false`
2052 - **Stable**: No
2053
2054 #### `true`
2055
2056 ```rust
2057 fn foo() {
2058     let msg = {
2059         let mut str = String::new();
2060         str.push_str("hello, ");
2061         str.push_str("world!");
2062         str
2063     };
2064     println!("{}", msg);
2065 }
2066 ```
2067
2068 #### `false`
2069
2070 ```rust
2071 fn foo() {
2072
2073     let msg = {
2074
2075         let mut str = String::new();
2076         str.push_str("hello, ");
2077         str.push_str("world!");
2078         str
2079
2080     };
2081     println!("{}", msg);
2082
2083 }
2084 ```
2085
2086 ## `required_version`
2087
2088 Require a specific version of rustfmt. If you want to make sure that the 
2089 specific version of rustfmt is used in your CI, use this option.
2090
2091 - **Default value**: `CARGO_PKG_VERSION`
2092 - **Possible values**: any published version (e.g. `"0.3.8"`)
2093 - **Stable**: No
2094
2095 ## `hide_parse_errors`
2096
2097 Do not show parse errors if the parser failed to parse files.
2098
2099 - **Default value**: `false`
2100 - **Possible values**: `true`, `false`
2101 - **Stable**: No
2102
2103 ## `color`
2104
2105 Whether to use colored output or not.
2106
2107 - **Default value**: `"Auto"`
2108 - **Possible values**: "Auto", "Always", "Never"
2109 - **Stable**: No
2110
2111 ## `unstable_features`
2112
2113 Enable unstable features on stable channel.
2114
2115 - **Default value**: `false`
2116 - **Possible values**: `true`, `false`
2117 - **Stable**: Yes
2118
2119 ## `license_template_path`
2120
2121 Check whether beginnings of files match a license template.
2122
2123 - **Default value**: `""``
2124 - **Possible values**: path to a license template file
2125 - **Stable**: No
2126
2127 A license template is a plain text file which is matched literally against the
2128 beginning of each source file, except for `{}`-delimited blocks, which are
2129 matched as regular expressions. The following license template therefore
2130 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
2131 Copyright 2018 The Rust Project Developers.`, etc.:
2132
2133 ```
2134 // Copyright {\d+} The Rust Project Developers.
2135 ```
2136
2137 `\{`, `\}` and `\\` match literal braces / backslashes.
2138
2139 ## `ignore`
2140
2141 Skip formatting the specified files and directories.
2142
2143 - **Default value**: format every files
2144 - **Possible values**: See an example below
2145 - **Stable**: No
2146
2147 ### Example
2148
2149 If you want to ignore specific files, put the following to your config file:
2150
2151 ```toml
2152 ignore = [
2153     "src/types.rs",
2154     "src/foo/bar.rs",
2155 ]
2156 ```
2157
2158 If you want to ignore every file under `examples/`, put the following to your config file:
2159
2160 ```toml
2161 ignore [
2162     "examples",
2163 ]
2164 ```