]> git.lizzy.rs Git - rust.git/blob - Configurations.md
meta: bump to v1.4.27
[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. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/1.0.4/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
4
5 A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
6
7 ```toml
8 indent_style = "Block"
9 reorder_imports = false
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 ## `binop_separator`
22
23 Where to put a binary operator when a binary expression goes multiline.
24
25 - **Default value**: `"Front"`
26 - **Possible values**: `"Front"`, `"Back"`
27 - **Stable**: No (tracking issue: #3368)
28
29 #### `"Front"` (default):
30
31 ```rust
32 fn main() {
33     let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
34         || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
35
36     let sum = 123456789012345678901234567890
37         + 123456789012345678901234567890
38         + 123456789012345678901234567890;
39
40     let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
41         ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
42 }
43 ```
44
45 #### `"Back"`:
46
47 ```rust
48 fn main() {
49     let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
50         barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
51
52     let sum = 123456789012345678901234567890 +
53         123456789012345678901234567890 +
54         123456789012345678901234567890;
55
56     let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
57         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
58 }
59 ```
60
61 ## `blank_lines_lower_bound`
62
63 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
64 them, additional blank lines are inserted.
65
66 - **Default value**: `0`
67 - **Possible values**: *unsigned integer*
68 - **Stable**: No (tracking issue: #3382)
69
70 ### Example
71 Original Code (rustfmt will not change it with the default value of `0`):
72
73 ```rust
74 #![rustfmt::skip]
75
76 fn foo() {
77     println!("a");
78 }
79 fn bar() {
80     println!("b");
81     println!("c");
82 }
83 ```
84
85 #### `1`
86 ```rust
87 fn foo() {
88
89     println!("a");
90 }
91
92 fn bar() {
93
94     println!("b");
95
96     println!("c");
97 }
98 ```
99
100
101 ## `blank_lines_upper_bound`
102
103 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
104 lines are found, they are trimmed down to match this integer.
105
106 - **Default value**: `1`
107 - **Possible values**: any non-negative integer
108 - **Stable**: No (tracking issue: #3381)
109
110 ### Example
111 Original Code:
112
113 ```rust
114 #![rustfmt::skip]
115
116 fn foo() {
117     println!("a");
118 }
119
120
121
122 fn bar() {
123     println!("b");
124
125
126     println!("c");
127 }
128 ```
129
130 #### `1` (default):
131 ```rust
132 fn foo() {
133     println!("a");
134 }
135
136 fn bar() {
137     println!("b");
138
139     println!("c");
140 }
141 ```
142
143 #### `2`:
144 ```rust
145 fn foo() {
146     println!("a");
147 }
148
149
150 fn bar() {
151     println!("b");
152
153
154     println!("c");
155 }
156 ```
157
158 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
159
160 ## `brace_style`
161
162 Brace style for items
163
164 - **Default value**: `"SameLineWhere"`
165 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
166 - **Stable**: No (tracking issue: #3376)
167
168 ### Functions
169
170 #### `"SameLineWhere"` (default):
171
172 ```rust
173 fn lorem() {
174     // body
175 }
176
177 fn lorem(ipsum: usize) {
178     // body
179 }
180
181 fn lorem<T>(ipsum: T)
182 where
183     T: Add + Sub + Mul + Div,
184 {
185     // body
186 }
187 ```
188
189 #### `"AlwaysNextLine"`:
190
191 ```rust
192 fn lorem()
193 {
194     // body
195 }
196
197 fn lorem(ipsum: usize)
198 {
199     // body
200 }
201
202 fn lorem<T>(ipsum: T)
203 where
204     T: Add + Sub + Mul + Div,
205 {
206     // body
207 }
208 ```
209
210 #### `"PreferSameLine"`:
211
212 ```rust
213 fn lorem() {
214     // body
215 }
216
217 fn lorem(ipsum: usize) {
218     // body
219 }
220
221 fn lorem<T>(ipsum: T)
222 where
223     T: Add + Sub + Mul + Div, {
224     // body
225 }
226 ```
227
228 ### Structs and enums
229
230 #### `"SameLineWhere"` (default):
231
232 ```rust
233 struct Lorem {
234     ipsum: bool,
235 }
236
237 struct Dolor<T>
238 where
239     T: Eq,
240 {
241     sit: T,
242 }
243 ```
244
245 #### `"AlwaysNextLine"`:
246
247 ```rust
248 struct Lorem
249 {
250     ipsum: bool,
251 }
252
253 struct Dolor<T>
254 where
255     T: Eq,
256 {
257     sit: T,
258 }
259 ```
260
261 #### `"PreferSameLine"`:
262
263 ```rust
264 struct Lorem {
265     ipsum: bool,
266 }
267
268 struct Dolor<T>
269 where
270     T: Eq, {
271     sit: T,
272 }
273 ```
274
275
276 ## `color`
277
278 Whether to use colored output or not.
279
280 - **Default value**: `"Auto"`
281 - **Possible values**: "Auto", "Always", "Never"
282 - **Stable**: No (tracking issue: #3385)
283
284 ## `combine_control_expr`
285
286 Combine control expressions with function calls.
287
288 - **Default value**: `true`
289 - **Possible values**: `true`, `false`
290 - **Stable**: No (tracking issue: #3369)
291
292 #### `true` (default):
293
294 ```rust
295 fn example() {
296     // If
297     foo!(if x {
298         foo();
299     } else {
300         bar();
301     });
302
303     // IfLet
304     foo!(if let Some(..) = x {
305         foo();
306     } else {
307         bar();
308     });
309
310     // While
311     foo!(while x {
312         foo();
313         bar();
314     });
315
316     // WhileLet
317     foo!(while let Some(..) = x {
318         foo();
319         bar();
320     });
321
322     // ForLoop
323     foo!(for x in y {
324         foo();
325         bar();
326     });
327
328     // Loop
329     foo!(loop {
330         foo();
331         bar();
332     });
333 }
334 ```
335
336 #### `false`:
337
338 ```rust
339 fn example() {
340     // If
341     foo!(
342         if x {
343             foo();
344         } else {
345             bar();
346         }
347     );
348
349     // IfLet
350     foo!(
351         if let Some(..) = x {
352             foo();
353         } else {
354             bar();
355         }
356     );
357
358     // While
359     foo!(
360         while x {
361             foo();
362             bar();
363         }
364     );
365
366     // WhileLet
367     foo!(
368         while let Some(..) = x {
369             foo();
370             bar();
371         }
372     );
373
374     // ForLoop
375     foo!(
376         for x in y {
377             foo();
378             bar();
379         }
380     );
381
382     // Loop
383     foo!(
384         loop {
385             foo();
386             bar();
387         }
388     );
389 }
390 ```
391
392 ## `comment_width`
393
394 Maximum length of comments. No effect unless`wrap_comments = true`.
395
396 - **Default value**: `80`
397 - **Possible values**: any positive integer
398 - **Stable**: No (tracking issue: #3349)
399
400 **Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
401
402 #### `80` (default; comments shorter than `comment_width`):
403 ```rust
404 // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
405 ```
406
407 #### `60` (comments longer than `comment_width`):
408 ```rust
409 // Lorem ipsum dolor sit amet,
410 // consectetur adipiscing elit.
411 ```
412
413 See also [`wrap_comments`](#wrap_comments).
414
415 ## `condense_wildcard_suffixes`
416
417 Replace strings of _ wildcards by a single .. in tuple patterns
418
419 - **Default value**: `false`
420 - **Possible values**: `true`, `false`
421 - **Stable**: No (tracking issue: #3384)
422
423 #### `false` (default):
424
425 ```rust
426 fn main() {
427     let (lorem, ipsum, _, _) = (1, 2, 3, 4);
428     let (lorem, ipsum, ..) = (1, 2, 3, 4);
429 }
430 ```
431
432 #### `true`:
433
434 ```rust
435 fn main() {
436     let (lorem, ipsum, ..) = (1, 2, 3, 4);
437 }
438 ```
439
440 ## `control_brace_style`
441
442 Brace style for control flow constructs
443
444 - **Default value**: `"AlwaysSameLine"`
445 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
446 - **Stable**: No (tracking issue: #3377)
447
448 #### `"AlwaysSameLine"` (default):
449
450 ```rust
451 fn main() {
452     if lorem {
453         println!("ipsum!");
454     } else {
455         println!("dolor!");
456     }
457 }
458 ```
459
460 #### `"AlwaysNextLine"`:
461
462 ```rust
463 fn main() {
464     if lorem
465     {
466         println!("ipsum!");
467     }
468     else
469     {
470         println!("dolor!");
471     }
472 }
473 ```
474
475 #### `"ClosingNextLine"`:
476
477 ```rust
478 fn main() {
479     if lorem {
480         println!("ipsum!");
481     }
482     else {
483         println!("dolor!");
484     }
485 }
486 ```
487
488 ## `disable_all_formatting`
489
490 Don't reformat anything
491
492 - **Default value**: `false`
493 - **Possible values**: `true`, `false`
494 - **Stable**: No (tracking issue: #3388)
495
496 ## `edition`
497
498 Specifies which edition is used by the parser.
499
500 - **Default value**: `2015`
501 - **Possible values**: `2015`, `2018`
502 - **Stable**: Yes
503
504 Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
505 through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
506 in your config file:
507
508 ```toml
509 edition = "2018"
510 ```
511
512 ## `empty_item_single_line`
513
514 Put empty-body functions and impls on a single line
515
516 - **Default value**: `true`
517 - **Possible values**: `true`, `false`
518 - **Stable**: No (tracking issue: #3356)
519
520 #### `true` (default):
521
522 ```rust
523 fn lorem() {}
524
525 impl Lorem {}
526 ```
527
528 #### `false`:
529
530 ```rust
531 fn lorem() {
532 }
533
534 impl Lorem {
535 }
536 ```
537
538 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
539
540
541 ## `enum_discrim_align_threshold`
542
543 The maximum length of enum variant having discriminant, that gets vertically aligned with others.
544 Variants without discriminants would be ignored for the purpose of alignment.
545
546 Note that this is not how much whitespace is inserted, but instead the longest variant name that
547 doesn't get ignored when aligning.
548
549 - **Default value** : 0
550 - **Possible values**: any positive integer
551 - **Stable**: No (tracking issue: #3372)
552
553 #### `0` (default):
554
555 ```rust
556 enum Bar {
557     A = 0,
558     Bb = 1,
559     RandomLongVariantGoesHere = 10,
560     Ccc = 71,
561 }
562
563 enum Bar {
564     VeryLongVariantNameHereA = 0,
565     VeryLongVariantNameHereBb = 1,
566     VeryLongVariantNameHereCcc = 2,
567 }
568 ```
569
570 #### `20`:
571
572 ```rust
573 enum Foo {
574     A   = 0,
575     Bb  = 1,
576     RandomLongVariantGoesHere = 10,
577     Ccc = 2,
578 }
579
580 enum Bar {
581     VeryLongVariantNameHereA = 0,
582     VeryLongVariantNameHereBb = 1,
583     VeryLongVariantNameHereCcc = 2,
584 }
585 ```
586
587
588 ## `error_on_line_overflow`
589
590 Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
591 literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
592 refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
593 using a shorter name.
594
595 - **Default value**: `false`
596 - **Possible values**: `true`, `false`
597 - **Stable**: No (tracking issue: #3391)
598
599 See also [`max_width`](#max_width).
600
601 ## `error_on_unformatted`
602
603 Error if unable to get comments or string literals within `max_width`, or they are left with
604 trailing whitespaces.
605
606 - **Default value**: `false`
607 - **Possible values**: `true`, `false`
608 - **Stable**: No (tracking issue: #3392)
609
610 ## `fn_args_layout`
611
612 Control the layout of arguments in a function
613
614 - **Default value**: `"Tall"`
615 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
616 - **Stable**: Yes
617
618 #### `"Tall"` (default):
619
620 ```rust
621 trait Lorem {
622     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
623
624     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
625         // body
626     }
627
628     fn lorem(
629         ipsum: Ipsum,
630         dolor: Dolor,
631         sit: Sit,
632         amet: Amet,
633         consectetur: Consectetur,
634         adipiscing: Adipiscing,
635         elit: Elit,
636     );
637
638     fn lorem(
639         ipsum: Ipsum,
640         dolor: Dolor,
641         sit: Sit,
642         amet: Amet,
643         consectetur: Consectetur,
644         adipiscing: Adipiscing,
645         elit: Elit,
646     ) {
647         // body
648     }
649 }
650 ```
651
652 #### `"Compressed"`:
653
654 ```rust
655 trait Lorem {
656     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
657
658     fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
659         // body
660     }
661
662     fn lorem(
663         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
664         adipiscing: Adipiscing, elit: Elit,
665     );
666
667     fn lorem(
668         ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
669         adipiscing: Adipiscing, elit: Elit,
670     ) {
671         // body
672     }
673 }
674 ```
675
676 #### `"Vertical"`:
677
678 ```rust
679 trait Lorem {
680     fn lorem(
681         ipsum: Ipsum,
682         dolor: Dolor,
683         sit: Sit,
684         amet: Amet,
685     );
686
687     fn lorem(
688         ipsum: Ipsum,
689         dolor: Dolor,
690         sit: Sit,
691         amet: Amet,
692     ) {
693         // body
694     }
695
696     fn lorem(
697         ipsum: Ipsum,
698         dolor: Dolor,
699         sit: Sit,
700         amet: Amet,
701         consectetur: Consectetur,
702         adipiscing: Adipiscing,
703         elit: Elit,
704     );
705
706     fn lorem(
707         ipsum: Ipsum,
708         dolor: Dolor,
709         sit: Sit,
710         amet: Amet,
711         consectetur: Consectetur,
712         adipiscing: Adipiscing,
713         elit: Elit,
714     ) {
715         // body
716     }
717 }
718 ```
719
720
721 ## `fn_single_line`
722
723 Put single-expression functions on a single line
724
725 - **Default value**: `false`
726 - **Possible values**: `true`, `false`
727 - **Stable**: No (tracking issue: #3358)
728
729 #### `false` (default):
730
731 ```rust
732 fn lorem() -> usize {
733     42
734 }
735
736 fn lorem() -> usize {
737     let ipsum = 42;
738     ipsum
739 }
740 ```
741
742 #### `true`:
743
744 ```rust
745 fn lorem() -> usize { 42 }
746
747 fn lorem() -> usize {
748     let ipsum = 42;
749     ipsum
750 }
751 ```
752
753 See also [`control_brace_style`](#control_brace_style).
754
755
756 ## `force_explicit_abi`
757
758 Always print the abi for extern items
759
760 - **Default value**: `true`
761 - **Possible values**: `true`, `false`
762 - **Stable**: Yes
763
764 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
765
766 #### `true` (default):
767
768 ```rust
769 extern "C" {
770     pub static lorem: c_int;
771 }
772 ```
773
774 #### `false`:
775
776 ```rust
777 extern {
778     pub static lorem: c_int;
779 }
780 ```
781
782 ## `force_multiline_blocks`
783
784 Force multiline closure and match arm bodies to be wrapped in a block
785
786 - **Default value**: `false`
787 - **Possible values**: `false`, `true`
788 - **Stable**: No (tracking issue: #3374)
789
790 #### `false` (default):
791
792 ```rust
793 fn main() {
794     result.and_then(|maybe_value| match maybe_value {
795         None => foo(),
796         Some(value) => bar(),
797     });
798
799     match lorem {
800         None => |ipsum| {
801             println!("Hello World");
802         },
803         Some(dolor) => foo(),
804     }
805 }
806 ```
807
808 #### `true`:
809
810 ```rust
811 fn main() {
812     result.and_then(|maybe_value| {
813         match maybe_value {
814             None => foo(),
815             Some(value) => bar(),
816         }
817     });
818
819     match lorem {
820         None => {
821             |ipsum| {
822                 println!("Hello World");
823             }
824         }
825         Some(dolor) => foo(),
826     }
827 }
828 ```
829
830
831 ## `format_code_in_doc_comments`
832
833 Format code snippet included in doc comments.
834
835 - **Default value**: `false`
836 - **Possible values**: `true`, `false`
837 - **Stable**: No (tracking issue: #3348)
838
839 #### `false` (default):
840
841 ```rust
842 /// Adds one to the number given.
843 ///
844 /// # Examples
845 ///
846 /// ```rust
847 /// let five=5;
848 ///
849 /// assert_eq!(
850 ///     6,
851 ///     add_one(5)
852 /// );
853 /// # fn add_one(x: i32) -> i32 {
854 /// #     x + 1
855 /// # }
856 /// ```
857 fn add_one(x: i32) -> i32 {
858     x + 1
859 }
860 ```
861
862 #### `true`
863
864 ```rust
865 /// Adds one to the number given.
866 ///
867 /// # Examples
868 ///
869 /// ```rust
870 /// let five = 5;
871 ///
872 /// assert_eq!(6, add_one(5));
873 /// # fn add_one(x: i32) -> i32 {
874 /// #     x + 1
875 /// # }
876 /// ```
877 fn add_one(x: i32) -> i32 {
878     x + 1
879 }
880 ```
881
882 ## `format_macro_matchers`
883
884 Format the metavariable matching patterns in macros.
885
886 - **Default value**: `false`
887 - **Possible values**: `true`, `false`
888 - **Stable**: No (tracking issue: #3354)
889
890 #### `false` (default):
891
892 ```rust
893 macro_rules! foo {
894     ($a: ident : $b: ty) => {
895         $a(42): $b;
896     };
897     ($a: ident $b: ident $c: ident) => {
898         $a = $b + $c;
899     };
900 }
901 ```
902
903 #### `true`:
904
905 ```rust
906 macro_rules! foo {
907     ($a:ident : $b:ty) => {
908         $a(42): $b;
909     };
910     ($a:ident $b:ident $c:ident) => {
911         $a = $b + $c;
912     };
913 }
914 ```
915
916 See also [`format_macro_bodies`](#format_macro_bodies).
917
918
919 ## `format_macro_bodies`
920
921 Format the bodies of macros.
922
923 - **Default value**: `true`
924 - **Possible values**: `true`, `false`
925 - **Stable**: No (tracking issue: #3355)
926
927 #### `true` (default):
928
929 ```rust
930 macro_rules! foo {
931     ($a: ident : $b: ty) => {
932         $a(42): $b;
933     };
934     ($a: ident $b: ident $c: ident) => {
935         $a = $b + $c;
936     };
937 }
938 ```
939
940 #### `false`:
941
942 ```rust
943 macro_rules! foo {
944     ($a: ident : $b: ty) => { $a(42): $b; };
945     ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
946 }
947 ```
948
949 See also [`format_macro_matchers`](#format_macro_matchers).
950
951
952 ## `format_strings`
953
954 Format string literals where necessary
955
956 - **Default value**: `false`
957 - **Possible values**: `true`, `false`
958 - **Stable**: No (tracking issue: #3353)
959
960 #### `false` (default):
961
962 ```rust
963 fn main() {
964     let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
965 }
966 ```
967
968 #### `true`:
969
970 ```rust
971 fn main() {
972     let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
973                  consectetur adipiscing";
974 }
975 ```
976
977 See also [`max_width`](#max_width).
978
979 ## `hard_tabs`
980
981 Use tab characters for indentation, spaces for alignment
982
983 - **Default value**: `false`
984 - **Possible values**: `true`, `false`
985 - **Stable**: Yes
986
987 #### `false` (default):
988
989 ```rust
990 fn lorem() -> usize {
991     42 // spaces before 42
992 }
993 ```
994
995 #### `true`:
996
997 ```rust
998 fn lorem() -> usize {
999         42 // tabs before 42
1000 }
1001 ```
1002
1003 See also: [`tab_spaces`](#tab_spaces).
1004
1005
1006 ## `hide_parse_errors`
1007
1008 Do not show parse errors if the parser failed to parse files.
1009
1010 - **Default value**: `false`
1011 - **Possible values**: `true`, `false`
1012 - **Stable**: No (tracking issue: #3390)
1013
1014 ## `ignore`
1015
1016 Skip formatting files and directories that match the specified pattern.
1017 The pattern format is the same as [.gitignore](https://git-scm.com/docs/gitignore#_pattern_format). Be sure to use Unix/forwardslash `/` style  paths. This path style will work on all platforms. Windows style paths with backslashes `\` are not supported.
1018
1019 - **Default value**: format every file
1020 - **Possible values**: See an example below
1021 - **Stable**: No (tracking issue: #3395)
1022
1023 ### Example
1024
1025 If you want to ignore specific files, put the following to your config file:
1026
1027 ```toml
1028 ignore = [
1029     "src/types.rs",
1030     "src/foo/bar.rs",
1031 ]
1032 ```
1033
1034 If you want to ignore every file under `examples/`, put the following to your config file:
1035
1036 ```toml
1037 ignore = [
1038     "examples",
1039 ]
1040 ```
1041
1042 If you want to ignore every file under the directory where you put your rustfmt.toml:
1043
1044 ```toml
1045 ignore = ["/"]
1046 ```
1047
1048 ## `imports_indent`
1049
1050 Indent style of imports
1051
1052 - **Default Value**: `"Block"`
1053 - **Possible values**: `"Block"`, `"Visual"`
1054 - **Stable**: No (tracking issue: #3360)
1055
1056 #### `"Block"` (default):
1057
1058 ```rust
1059 use foo::{
1060     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1061     zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1062 };
1063 ```
1064
1065 #### `"Visual"`:
1066
1067 ```rust
1068 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1069           zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1070 ```
1071
1072 See also: [`imports_layout`](#imports_layout).
1073
1074 ## `imports_layout`
1075
1076 Item layout inside a imports block
1077
1078 - **Default value**: "Mixed"
1079 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1080 - **Stable**: No (tracking issue: #3361)
1081
1082 #### `"Mixed"` (default):
1083
1084 ```rust
1085 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1086
1087 use foo::{
1088     aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1089     eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1090 };
1091 ```
1092
1093 #### `"Horizontal"`:
1094
1095 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1096
1097 ```rust
1098 use foo::{xxx, yyy, zzz};
1099
1100 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1101 ```
1102
1103 #### `"HorizontalVertical"`:
1104
1105 ```rust
1106 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1107
1108 use foo::{
1109     aaaaaaaaaaaaaaaaaa,
1110     bbbbbbbbbbbbbbbbbb,
1111     cccccccccccccccccc,
1112     dddddddddddddddddd,
1113     eeeeeeeeeeeeeeeeee,
1114     ffffffffffffffffff,
1115 };
1116 ```
1117
1118 #### `"Vertical"`:
1119
1120 ```rust
1121 use foo::{
1122     xxx,
1123     yyy,
1124     zzz,
1125 };
1126
1127 use foo::{
1128     aaa,
1129     bbb,
1130     ccc,
1131     ddd,
1132     eee,
1133     fff,
1134 };
1135 ```
1136
1137 ## `indent_style`
1138
1139 Indent on expressions or items.
1140
1141 - **Default value**: `"Block"`
1142 - **Possible values**: `"Block"`, `"Visual"`
1143 - **Stable**: No (tracking issue: #3346)
1144
1145 ### Array
1146
1147 #### `"Block"` (default):
1148
1149 ```rust
1150 fn main() {
1151     let lorem = vec![
1152         "ipsum",
1153         "dolor",
1154         "sit",
1155         "amet",
1156         "consectetur",
1157         "adipiscing",
1158         "elit",
1159     ];
1160 }
1161 ```
1162
1163 #### `"Visual"`:
1164
1165 ```rust
1166 fn main() {
1167     let lorem = vec!["ipsum",
1168                      "dolor",
1169                      "sit",
1170                      "amet",
1171                      "consectetur",
1172                      "adipiscing",
1173                      "elit"];
1174 }
1175 ```
1176
1177 ### Control flow
1178
1179 #### `"Block"` (default):
1180
1181 ```rust
1182 fn main() {
1183     if lorem_ipsum
1184         && dolor_sit
1185         && amet_consectetur
1186         && lorem_sit
1187         && dolor_consectetur
1188         && amet_ipsum
1189         && lorem_consectetur
1190     {
1191         // ...
1192     }
1193 }
1194 ```
1195
1196 #### `"Visual"`:
1197
1198 ```rust
1199 fn main() {
1200     if lorem_ipsum
1201        && dolor_sit
1202        && amet_consectetur
1203        && lorem_sit
1204        && dolor_consectetur
1205        && amet_ipsum
1206        && lorem_consectetur
1207     {
1208         // ...
1209     }
1210 }
1211 ```
1212
1213 See also: [`control_brace_style`](#control_brace_style).
1214
1215 ### Function arguments
1216
1217 #### `"Block"` (default):
1218
1219 ```rust
1220 fn lorem() {}
1221
1222 fn lorem(ipsum: usize) {}
1223
1224 fn lorem(
1225     ipsum: usize,
1226     dolor: usize,
1227     sit: usize,
1228     amet: usize,
1229     consectetur: usize,
1230     adipiscing: usize,
1231     elit: usize,
1232 ) {
1233     // body
1234 }
1235 ```
1236
1237 #### `"Visual"`:
1238
1239 ```rust
1240 fn lorem() {}
1241
1242 fn lorem(ipsum: usize) {}
1243
1244 fn lorem(ipsum: usize,
1245          dolor: usize,
1246          sit: usize,
1247          amet: usize,
1248          consectetur: usize,
1249          adipiscing: usize,
1250          elit: usize) {
1251     // body
1252 }
1253 ```
1254
1255 ### Function calls
1256
1257 #### `"Block"` (default):
1258
1259 ```rust
1260 fn main() {
1261     lorem(
1262         "lorem",
1263         "ipsum",
1264         "dolor",
1265         "sit",
1266         "amet",
1267         "consectetur",
1268         "adipiscing",
1269         "elit",
1270     );
1271 }
1272 ```
1273
1274 #### `"Visual"`:
1275
1276 ```rust
1277 fn main() {
1278     lorem("lorem",
1279           "ipsum",
1280           "dolor",
1281           "sit",
1282           "amet",
1283           "consectetur",
1284           "adipiscing",
1285           "elit");
1286 }
1287 ```
1288
1289 ### Generics
1290
1291 #### `"Block"` (default):
1292
1293 ```rust
1294 fn lorem<
1295     Ipsum: Eq = usize,
1296     Dolor: Eq = usize,
1297     Sit: Eq = usize,
1298     Amet: Eq = usize,
1299     Adipiscing: Eq = usize,
1300     Consectetur: Eq = usize,
1301     Elit: Eq = usize,
1302 >(
1303     ipsum: Ipsum,
1304     dolor: Dolor,
1305     sit: Sit,
1306     amet: Amet,
1307     adipiscing: Adipiscing,
1308     consectetur: Consectetur,
1309     elit: Elit,
1310 ) -> T {
1311     // body
1312 }
1313 ```
1314
1315 #### `"Visual"`:
1316
1317 ```rust
1318 fn lorem<Ipsum: Eq = usize,
1319          Dolor: Eq = usize,
1320          Sit: Eq = usize,
1321          Amet: Eq = usize,
1322          Adipiscing: Eq = usize,
1323          Consectetur: Eq = usize,
1324          Elit: Eq = usize>(
1325     ipsum: Ipsum,
1326     dolor: Dolor,
1327     sit: Sit,
1328     amet: Amet,
1329     adipiscing: Adipiscing,
1330     consectetur: Consectetur,
1331     elit: Elit)
1332     -> T {
1333     // body
1334 }
1335 ```
1336
1337 #### Struct
1338
1339 #### `"Block"` (default):
1340
1341 ```rust
1342 fn main() {
1343     let lorem = Lorem {
1344         ipsum: dolor,
1345         sit: amet,
1346     };
1347 }
1348 ```
1349
1350 #### `"Visual"`:
1351
1352 ```rust
1353 fn main() {
1354     let lorem = Lorem { ipsum: dolor,
1355                         sit: amet };
1356 }
1357 ```
1358
1359 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
1360
1361 ### Where predicates
1362
1363 #### `"Block"` (default):
1364
1365 ```rust
1366 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1367 where
1368     Ipsum: Eq,
1369     Dolor: Eq,
1370     Sit: Eq,
1371     Amet: Eq,
1372 {
1373     // body
1374 }
1375 ```
1376
1377 #### `"Visual"`:
1378
1379 ```rust
1380 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1381     where Ipsum: Eq,
1382           Dolor: Eq,
1383           Sit: Eq,
1384           Amet: Eq
1385 {
1386     // body
1387 }
1388 ```
1389
1390 ## `inline_attribute_width`
1391
1392 Write an item and its attribute on the same line if their combined width is below a threshold
1393
1394 - **Default value**: 0
1395 - **Possible values**: any positive integer
1396 - **Stable**: No (tracking issue: #3343)
1397
1398 ### Example
1399
1400 #### `0` (default):
1401 ```rust
1402 #[cfg(feature = "alloc")]
1403 use core::slice;
1404 ```
1405
1406 #### `50`:
1407 ```rust
1408 #[cfg(feature = "alloc")] use core::slice;
1409 ```
1410
1411 ## `license_template_path`
1412
1413 Check whether beginnings of files match a license template.
1414
1415 - **Default value**: `""`
1416 - **Possible values**: path to a license template file
1417 - **Stable**: No (tracking issue: #3352)
1418
1419 A license template is a plain text file which is matched literally against the
1420 beginning of each source file, except for `{}`-delimited blocks, which are
1421 matched as regular expressions. The following license template therefore
1422 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
1423 Copyright 2018 The Rust Project Developers.`, etc.:
1424
1425 ```
1426 // Copyright {\d+} The Rust Project Developers.
1427 ```
1428
1429 `\{`, `\}` and `\\` match literal braces / backslashes.
1430
1431 ## `match_arm_blocks`
1432
1433 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1434
1435 - **Default value**: `true`
1436 - **Possible values**: `true`, `false`
1437 - **Stable**: No (tracking issue: #3373)
1438
1439 #### `true` (default):
1440
1441 ```rust
1442 fn main() {
1443     match lorem {
1444         true => {
1445             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1446         }
1447         false => println!("{}", sit),
1448     }
1449 }
1450 ```
1451
1452 #### `false`:
1453
1454 ```rust
1455 fn main() {
1456     match lorem {
1457         true =>
1458             foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1459         false => println!("{}", sit),
1460     }
1461 }
1462 ```
1463
1464 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1465
1466 ## `match_arm_leading_pipes`
1467
1468 Controls whether to include a leading pipe on match arms
1469
1470 - **Default value**: `Never`
1471 - **Possible values**: `Always`, `Never`, `Preserve`
1472 - **Stable**: Yes
1473
1474 #### `Never` (default):
1475 ```rust
1476 // Leading pipes are removed from this:
1477 // fn foo() {
1478 //     match foo {
1479 //         | "foo" | "bar" => {}
1480 //         | "baz"
1481 //         | "something relatively long"
1482 //         | "something really really really realllllllllllllly long" => println!("x"),
1483 //         | "qux" => println!("y"),
1484 //         _ => {}
1485 //     }
1486 // }
1487
1488 // Becomes
1489 fn foo() {
1490     match foo {
1491         "foo" | "bar" => {}
1492         "baz"
1493         | "something relatively long"
1494         | "something really really really realllllllllllllly long" => println!("x"),
1495         "qux" => println!("y"),
1496         _ => {}
1497     }
1498 }
1499 ```
1500
1501 #### `Always`:
1502 ```rust
1503 // Leading pipes are emitted on all arms of this:
1504 // fn foo() {
1505 //     match foo {
1506 //         "foo" | "bar" => {}
1507 //         "baz"
1508 //         | "something relatively long"
1509 //         | "something really really really realllllllllllllly long" => println!("x"),
1510 //         "qux" => println!("y"),
1511 //         _ => {}
1512 //     }
1513 // }
1514
1515 // Becomes:
1516 fn foo() {
1517     match foo {
1518         | "foo" | "bar" => {}
1519         | "baz"
1520         | "something relatively long"
1521         | "something really really really realllllllllllllly long" => println!("x"),
1522         | "qux" => println!("y"),
1523         | _ => {}
1524     }
1525 }
1526 ```
1527
1528 #### `Preserve`:
1529 ```rust
1530 fn foo() {
1531     match foo {
1532         | "foo" | "bar" => {}
1533         | "baz"
1534         | "something relatively long"
1535         | "something really really really realllllllllllllly long" => println!("x"),
1536         | "qux" => println!("y"),
1537         _ => {}
1538     }
1539
1540     match baz {
1541         "qux" => {}
1542         "foo" | "bar" => {}
1543         _ => {}
1544     }
1545 }
1546 ```
1547
1548 ## `match_block_trailing_comma`
1549
1550 Put a trailing comma after a block based match arm (non-block arms are not affected)
1551
1552 - **Default value**: `false`
1553 - **Possible values**: `true`, `false`
1554 - **Stable**: No (tracking issue: #3380)
1555
1556 #### `false` (default):
1557
1558 ```rust
1559 fn main() {
1560     match lorem {
1561         Lorem::Ipsum => {
1562             println!("ipsum");
1563         }
1564         Lorem::Dolor => println!("dolor"),
1565     }
1566 }
1567 ```
1568
1569 #### `true`:
1570
1571 ```rust
1572 fn main() {
1573     match lorem {
1574         Lorem::Ipsum => {
1575             println!("ipsum");
1576         },
1577         Lorem::Dolor => println!("dolor"),
1578     }
1579 }
1580 ```
1581
1582 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1583
1584 ## `max_width`
1585
1586 Maximum width of each line
1587
1588 - **Default value**: `100`
1589 - **Possible values**: any positive integer
1590 - **Stable**: Yes
1591
1592 See also [`error_on_line_overflow`](#error_on_line_overflow).
1593
1594 ## `merge_derives`
1595
1596 Merge multiple derives into a single one.
1597
1598 - **Default value**: `true`
1599 - **Possible values**: `true`, `false`
1600 - **Stable**: Yes
1601
1602 #### `true` (default):
1603
1604 ```rust
1605 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1606 pub enum Foo {}
1607 ```
1608
1609 #### `false`:
1610
1611 ```rust
1612 #[derive(Eq, PartialEq)]
1613 #[derive(Debug)]
1614 #[derive(Copy, Clone)]
1615 pub enum Foo {}
1616 ```
1617
1618 ## `merge_imports`
1619
1620 Merge multiple imports into a single nested import.
1621
1622 - **Default value**: `false`
1623 - **Possible values**: `true`, `false`
1624 - **Stable**: No (tracking issue: #3362)
1625
1626 #### `false` (default):
1627
1628 ```rust
1629 use foo::{a, c, d};
1630 use foo::{b, g};
1631 use foo::{e, f};
1632 ```
1633
1634 #### `true`:
1635
1636 ```rust
1637 use foo::{a, b, c, d, e, f, g};
1638 ```
1639
1640
1641 ## `newline_style`
1642
1643 Unix or Windows line endings
1644
1645 - **Default value**: `"Auto"`
1646 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1647 - **Stable**: Yes
1648
1649 #### `Auto` (default):
1650
1651 The newline style is detected automatically on a per-file basis. Files
1652 with mixed line endings will be converted to the first detected line
1653 ending style.
1654
1655 #### `Native`
1656
1657 Line endings will be converted to `\r\n` on Windows and `\n` on all
1658 other platforms.
1659
1660 #### `Unix`
1661
1662 Line endings will be converted to `\n`.
1663
1664 #### `Windows`
1665
1666 Line endings will be converted to `\r\n`.
1667
1668 ## `normalize_comments`
1669
1670 Convert /* */ comments to // comments where possible
1671
1672 - **Default value**: `false`
1673 - **Possible values**: `true`, `false`
1674 - **Stable**: No (tracking issue: #3350)
1675
1676 #### `false` (default):
1677
1678 ```rust
1679 // Lorem ipsum:
1680 fn dolor() -> usize {}
1681
1682 /* sit amet: */
1683 fn adipiscing() -> usize {}
1684 ```
1685
1686 #### `true`:
1687
1688 ```rust
1689 // Lorem ipsum:
1690 fn dolor() -> usize {}
1691
1692 // sit amet:
1693 fn adipiscing() -> usize {}
1694 ```
1695
1696 ## `normalize_doc_attributes`
1697
1698 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1699
1700 - **Default value**: `false`
1701 - **Possible values**: `true`, `false`
1702 - **Stable**: No (tracking issue: #3351)
1703
1704 #### `false` (default):
1705
1706 ```rust
1707 #![doc = "Example documentation"]
1708
1709 #[doc = "Example item documentation"]
1710 pub enum Foo {}
1711 ```
1712
1713 #### `true`:
1714
1715 ```rust
1716 //! Example documentation
1717
1718 /// Example item documentation
1719 pub enum Foo {}
1720 ```
1721
1722 ## `overflow_delimited_expr`
1723
1724 When structs, slices, arrays, and block/array-like macros are used as the last
1725 argument in an expression list, allow them to overflow (like blocks/closures)
1726 instead of being indented on a new line.
1727
1728 - **Default value**: `false`
1729 - **Possible values**: `true`, `false`
1730 - **Stable**: No (tracking issue: #3370)
1731
1732 #### `false` (default):
1733
1734 ```rust
1735 fn example() {
1736     foo(ctx, |param| {
1737         action();
1738         foo(param)
1739     });
1740
1741     foo(
1742         ctx,
1743         Bar {
1744             x: value,
1745             y: value2,
1746         },
1747     );
1748
1749     foo(
1750         ctx,
1751         &[
1752             MAROON_TOMATOES,
1753             PURPLE_POTATOES,
1754             ORGANE_ORANGES,
1755             GREEN_PEARS,
1756             RED_APPLES,
1757         ],
1758     );
1759
1760     foo(
1761         ctx,
1762         vec![
1763             MAROON_TOMATOES,
1764             PURPLE_POTATOES,
1765             ORGANE_ORANGES,
1766             GREEN_PEARS,
1767             RED_APPLES,
1768         ],
1769     );
1770 }
1771 ```
1772
1773 #### `true`:
1774
1775 ```rust
1776 fn example() {
1777     foo(ctx, |param| {
1778         action();
1779         foo(param)
1780     });
1781
1782     foo(ctx, Bar {
1783         x: value,
1784         y: value2,
1785     });
1786
1787     foo(ctx, &[
1788         MAROON_TOMATOES,
1789         PURPLE_POTATOES,
1790         ORGANE_ORANGES,
1791         GREEN_PEARS,
1792         RED_APPLES,
1793     ]);
1794
1795     foo(ctx, vec![
1796         MAROON_TOMATOES,
1797         PURPLE_POTATOES,
1798         ORGANE_ORANGES,
1799         GREEN_PEARS,
1800         RED_APPLES,
1801     ]);
1802 }
1803 ```
1804
1805 ## `remove_nested_parens`
1806
1807 Remove nested parens.
1808
1809 - **Default value**: `true`,
1810 - **Possible values**: `true`, `false`
1811 - **Stable**: Yes
1812
1813
1814 #### `true` (default):
1815 ```rust
1816 fn main() {
1817     (foo());
1818 }
1819 ```
1820
1821 #### `false`:
1822 ```rust
1823 fn main() {
1824     ((((foo()))));
1825 }
1826 ```
1827
1828
1829 ## `reorder_impl_items`
1830
1831 Reorder impl items. `type` and `const` are put first, then macros and methods.
1832
1833 - **Default value**: `false`
1834 - **Possible values**: `true`, `false`
1835 - **Stable**: No (tracking issue: #3363)
1836
1837 #### `false` (default)
1838
1839 ```rust
1840 struct Dummy;
1841
1842 impl Iterator for Dummy {
1843     fn next(&mut self) -> Option<Self::Item> {
1844         None
1845     }
1846
1847     type Item = i32;
1848 }
1849 ```
1850
1851 #### `true`
1852
1853 ```rust
1854 struct Dummy;
1855
1856 impl Iterator for Dummy {
1857     type Item = i32;
1858
1859     fn next(&mut self) -> Option<Self::Item> {
1860         None
1861     }
1862 }
1863 ```
1864
1865 ## `reorder_imports`
1866
1867 Reorder import and extern crate statements alphabetically in groups (a group is
1868 separated by a newline).
1869
1870 - **Default value**: `true`
1871 - **Possible values**: `true`, `false`
1872 - **Stable**: Yes
1873
1874 #### `true` (default):
1875
1876 ```rust
1877 use dolor;
1878 use ipsum;
1879 use lorem;
1880 use sit;
1881 ```
1882
1883 #### `false`:
1884
1885 ```rust
1886 use lorem;
1887 use ipsum;
1888 use dolor;
1889 use sit;
1890 ```
1891
1892
1893 ## `reorder_modules`
1894
1895 Reorder `mod` declarations alphabetically in group.
1896
1897 - **Default value**: `true`
1898 - **Possible values**: `true`, `false`
1899 - **Stable**: Yes
1900
1901 #### `true` (default)
1902
1903 ```rust
1904 mod a;
1905 mod b;
1906
1907 mod dolor;
1908 mod ipsum;
1909 mod lorem;
1910 mod sit;
1911 ```
1912
1913 #### `false`
1914
1915 ```rust
1916 mod b;
1917 mod a;
1918
1919 mod lorem;
1920 mod ipsum;
1921 mod dolor;
1922 mod sit;
1923 ```
1924
1925 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
1926 of the original source code.
1927
1928 ## `report_fixme`
1929
1930 Report `FIXME` items in comments.
1931
1932 - **Default value**: `"Never"`
1933 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1934 - **Stable**: No (tracking issue: #3394)
1935
1936 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1937 it contains a `#X` (with `X` being a number) in parentheses following the
1938 `FIXME`, `"Unnumbered"` will ignore it.
1939
1940 See also [`report_todo`](#report_todo).
1941
1942
1943 ## `report_todo`
1944
1945 Report `TODO` items in comments.
1946
1947 - **Default value**: `"Never"`
1948 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1949 - **Stable**: No (tracking issue: #3393)
1950
1951 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1952 it contains a `#X` (with `X` being a number) in parentheses following the
1953 `TODO`, `"Unnumbered"` will ignore it.
1954
1955 See also [`report_fixme`](#report_fixme).
1956
1957 ## `required_version`
1958
1959 Require a specific version of rustfmt. If you want to make sure that the
1960 specific version of rustfmt is used in your CI, use this option.
1961
1962 - **Default value**: `CARGO_PKG_VERSION`
1963 - **Possible values**: any published version (e.g. `"0.3.8"`)
1964 - **Stable**: No (tracking issue: #3386)
1965
1966 ## `skip_children`
1967
1968 Don't reformat out of line modules
1969
1970 - **Default value**: `false`
1971 - **Possible values**: `true`, `false`
1972 - **Stable**: No (tracking issue: #3389)
1973
1974 ## `space_after_colon`
1975
1976 Leave a space after the colon.
1977
1978 - **Default value**: `true`
1979 - **Possible values**: `true`, `false`
1980 - **Stable**: No (tracking issue: #3366)
1981
1982 #### `true` (default):
1983
1984 ```rust
1985 fn lorem<T: Eq>(t: T) {
1986     let lorem: Dolor = Lorem {
1987         ipsum: dolor,
1988         sit: amet,
1989     };
1990 }
1991 ```
1992
1993 #### `false`:
1994
1995 ```rust
1996 fn lorem<T:Eq>(t:T) {
1997     let lorem:Dolor = Lorem {
1998         ipsum:dolor,
1999         sit:amet,
2000     };
2001 }
2002 ```
2003
2004 See also: [`space_before_colon`](#space_before_colon).
2005
2006 ## `space_before_colon`
2007
2008 Leave a space before the colon.
2009
2010 - **Default value**: `false`
2011 - **Possible values**: `true`, `false`
2012 - **Stable**: No (tracking issue: #3365)
2013
2014 #### `false` (default):
2015
2016 ```rust
2017 fn lorem<T: Eq>(t: T) {
2018     let lorem: Dolor = Lorem {
2019         ipsum: dolor,
2020         sit: amet,
2021     };
2022 }
2023 ```
2024
2025 #### `true`:
2026
2027 ```rust
2028 fn lorem<T : Eq>(t : T) {
2029     let lorem : Dolor = Lorem {
2030         ipsum : dolor,
2031         sit : amet,
2032     };
2033 }
2034 ```
2035
2036 See also: [`space_after_colon`](#space_after_colon).
2037
2038 ## `spaces_around_ranges`
2039
2040 Put spaces around the .., ..=, and ... range operators
2041
2042 - **Default value**: `false`
2043 - **Possible values**: `true`, `false`
2044 - **Stable**: No (tracking issue: #3367)
2045
2046 #### `false` (default):
2047
2048 ```rust
2049 fn main() {
2050     let lorem = 0..10;
2051     let ipsum = 0..=10;
2052
2053     match lorem {
2054         1..5 => foo(),
2055         _ => bar,
2056     }
2057
2058     match lorem {
2059         1..=5 => foo(),
2060         _ => bar,
2061     }
2062
2063     match lorem {
2064         1...5 => foo(),
2065         _ => bar,
2066     }
2067 }
2068 ```
2069
2070 #### `true`:
2071
2072 ```rust
2073 fn main() {
2074     let lorem = 0 .. 10;
2075     let ipsum = 0 ..= 10;
2076
2077     match lorem {
2078         1 .. 5 => foo(),
2079         _ => bar,
2080     }
2081
2082     match lorem {
2083         1 ..= 5 => foo(),
2084         _ => bar,
2085     }
2086
2087     match lorem {
2088         1 ... 5 => foo(),
2089         _ => bar,
2090     }
2091 }
2092 ```
2093
2094 ## `struct_field_align_threshold`
2095
2096 The maximum diff of width between struct fields to be aligned with each other.
2097
2098 - **Default value** : 0
2099 - **Possible values**: any non-negative integer
2100 - **Stable**: No (tracking issue: #3371)
2101
2102 #### `0` (default):
2103
2104 ```rust
2105 struct Foo {
2106     x: u32,
2107     yy: u32,
2108     zzz: u32,
2109 }
2110 ```
2111
2112 #### `20`:
2113
2114 ```rust
2115 struct Foo {
2116     x:   u32,
2117     yy:  u32,
2118     zzz: u32,
2119 }
2120 ```
2121
2122 ## `struct_lit_single_line`
2123
2124 Put small struct literals on a single line
2125
2126 - **Default value**: `true`
2127 - **Possible values**: `true`, `false`
2128 - **Stable**: No (tracking issue: #3357)
2129
2130 #### `true` (default):
2131
2132 ```rust
2133 fn main() {
2134     let lorem = Lorem { foo: bar, baz: ofo };
2135 }
2136 ```
2137
2138 #### `false`:
2139
2140 ```rust
2141 fn main() {
2142     let lorem = Lorem {
2143         foo: bar,
2144         baz: ofo,
2145     };
2146 }
2147 ```
2148
2149 See also: [`indent_style`](#indent_style).
2150
2151
2152 ## `tab_spaces`
2153
2154 Number of spaces per tab
2155
2156 - **Default value**: `4`
2157 - **Possible values**: any positive integer
2158 - **Stable**: Yes
2159
2160 #### `4` (default):
2161
2162 ```rust
2163 fn lorem() {
2164     let ipsum = dolor();
2165     let sit = vec![
2166         "amet consectetur adipiscing elit amet",
2167         "consectetur adipiscing elit amet consectetur.",
2168     ];
2169 }
2170 ```
2171
2172 #### `2`:
2173
2174 ```rust
2175 fn lorem() {
2176   let ipsum = dolor();
2177   let sit = vec![
2178     "amet consectetur adipiscing elit amet",
2179     "consectetur adipiscing elit amet consectetur.",
2180   ];
2181 }
2182 ```
2183
2184 See also: [`hard_tabs`](#hard_tabs).
2185
2186
2187 ## `trailing_comma`
2188
2189 How to handle trailing commas for lists
2190
2191 - **Default value**: `"Vertical"`
2192 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
2193 - **Stable**: No (tracking issue: #3379)
2194
2195 #### `"Vertical"` (default):
2196
2197 ```rust
2198 fn main() {
2199     let Lorem { ipsum, dolor, sit } = amet;
2200     let Lorem {
2201         ipsum,
2202         dolor,
2203         sit,
2204         amet,
2205         consectetur,
2206         adipiscing,
2207     } = elit;
2208 }
2209 ```
2210
2211 #### `"Always"`:
2212
2213 ```rust
2214 fn main() {
2215     let Lorem { ipsum, dolor, sit, } = amet;
2216     let Lorem {
2217         ipsum,
2218         dolor,
2219         sit,
2220         amet,
2221         consectetur,
2222         adipiscing,
2223     } = elit;
2224 }
2225 ```
2226
2227 #### `"Never"`:
2228
2229 ```rust
2230 fn main() {
2231     let Lorem { ipsum, dolor, sit } = amet;
2232     let Lorem {
2233         ipsum,
2234         dolor,
2235         sit,
2236         amet,
2237         consectetur,
2238         adipiscing
2239     } = elit;
2240 }
2241 ```
2242
2243 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2244
2245 ## `trailing_semicolon`
2246
2247 Add trailing semicolon after break, continue and return
2248
2249 - **Default value**: `true`
2250 - **Possible values**: `true`, `false`
2251 - **Stable**: No (tracking issue: #3378)
2252
2253 #### `true` (default):
2254 ```rust
2255 fn foo() -> usize {
2256     return 0;
2257 }
2258 ```
2259
2260 #### `false`:
2261 ```rust
2262 fn foo() -> usize {
2263     return 0
2264 }
2265 ```
2266
2267 ## `type_punctuation_density`
2268
2269 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2270
2271 - **Default value**: `"Wide"`
2272 - **Possible values**: `"Compressed"`, `"Wide"`
2273 - **Stable**: No (tracking issue: #3364)
2274
2275 #### `"Wide"` (default):
2276
2277 ```rust
2278 fn lorem<Ipsum: Dolor + Sit = Amet>() {
2279     // body
2280 }
2281 ```
2282
2283 #### `"Compressed"`:
2284
2285 ```rust
2286 fn lorem<Ipsum: Dolor+Sit=Amet>() {
2287     // body
2288 }
2289 ```
2290
2291 ## `unstable_features`
2292
2293 Enable unstable features on the unstable channel.
2294
2295 - **Default value**: `false`
2296 - **Possible values**: `true`, `false`
2297 - **Stable**: No (tracking issue: #3387)
2298
2299 ## `use_field_init_shorthand`
2300
2301 Use field initialize shorthand if possible.
2302
2303 - **Default value**: `false`
2304 - **Possible values**: `true`, `false`
2305 - **Stable**: Yes
2306
2307 #### `false` (default):
2308
2309 ```rust
2310 struct Foo {
2311     x: u32,
2312     y: u32,
2313     z: u32,
2314 }
2315
2316 fn main() {
2317     let x = 1;
2318     let y = 2;
2319     let z = 3;
2320     let a = Foo { x: x, y: y, z: z };
2321 }
2322 ```
2323
2324 #### `true`:
2325
2326 ```rust
2327 struct Foo {
2328     x: u32,
2329     y: u32,
2330     z: u32,
2331 }
2332
2333 fn main() {
2334     let x = 1;
2335     let y = 2;
2336     let z = 3;
2337     let a = Foo { x, y, z };
2338 }
2339 ```
2340
2341 ## `use_small_heuristics`
2342
2343 Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2344
2345 - **Default value**: `"Default"`
2346 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
2347 - **Stable**: Yes
2348
2349 #### `Default` (default):
2350
2351 ```rust
2352 enum Lorem {
2353     Ipsum,
2354     Dolor(bool),
2355     Sit { amet: Consectetur, adipiscing: Elit },
2356 }
2357
2358 fn main() {
2359     lorem(
2360         "lorem",
2361         "ipsum",
2362         "dolor",
2363         "sit",
2364         "amet",
2365         "consectetur",
2366         "adipiscing",
2367     );
2368
2369     let lorem = Lorem {
2370         ipsum: dolor,
2371         sit: amet,
2372     };
2373     let lorem = Lorem { ipsum: dolor };
2374
2375     let lorem = if ipsum { dolor } else { sit };
2376 }
2377 ```
2378
2379 #### `Off`:
2380
2381 ```rust
2382 enum Lorem {
2383     Ipsum,
2384     Dolor(bool),
2385     Sit {
2386         amet: Consectetur,
2387         adipiscing: Elit,
2388     },
2389 }
2390
2391 fn main() {
2392     lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2393
2394     let lorem = Lorem {
2395         ipsum: dolor,
2396         sit: amet,
2397     };
2398
2399     let lorem = if ipsum {
2400         dolor
2401     } else {
2402         sit
2403     };
2404 }
2405 ```
2406
2407 #### `Max`:
2408
2409 ```rust
2410 enum Lorem {
2411     Ipsum,
2412     Dolor(bool),
2413     Sit { amet: Consectetur, adipiscing: Elit },
2414 }
2415
2416 fn main() {
2417     lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2418
2419     let lorem = Lorem { ipsum: dolor, sit: amet };
2420
2421     let lorem = if ipsum { dolor } else { sit };
2422 }
2423 ```
2424
2425 ## `use_try_shorthand`
2426
2427 Replace uses of the try! macro by the ? shorthand
2428
2429 - **Default value**: `false`
2430 - **Possible values**: `true`, `false`
2431 - **Stable**: Yes
2432
2433 #### `false` (default):
2434
2435 ```rust
2436 fn main() {
2437     let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2438 }
2439 ```
2440
2441 #### `true`:
2442
2443 ```rust
2444 fn main() {
2445     let lorem = ipsum.map(|dolor| dolor.sit())?;
2446 }
2447 ```
2448
2449 ## `version`
2450
2451 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2452 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2453 version number.
2454
2455 - **Default value**: `One`
2456 - **Possible values**: `One`, `Two`
2457 - **Stable**: No (tracking issue: #3383)
2458
2459 ### Example
2460
2461 ```toml
2462 version = "Two"
2463 ```
2464
2465 ## `where_single_line`
2466
2467 Forces the `where` clause to be laid out on a single line.
2468
2469 - **Default value**: `false`
2470 - **Possible values**: `true`, `false`
2471 - **Stable**: No (tracking issue: #3359)
2472
2473 #### `false` (default):
2474
2475 ```rust
2476 impl<T> Lorem for T
2477 where
2478     Option<T>: Ipsum,
2479 {
2480     // body
2481 }
2482 ```
2483
2484 #### `true`:
2485
2486 ```rust
2487 impl<T> Lorem for T
2488 where Option<T>: Ipsum
2489 {
2490     // body
2491 }
2492 ```
2493
2494 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2495
2496
2497 ## `wrap_comments`
2498
2499 Break comments to fit on the line
2500
2501 - **Default value**: `false`
2502 - **Possible values**: `true`, `false`
2503 - **Stable**: No (tracking issue: #3347)
2504
2505 #### `false` (default):
2506
2507 ```rust
2508 // 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.
2509 ```
2510
2511 #### `true`:
2512
2513 ```rust
2514 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2515 // sed do eiusmod tempor incididunt ut labore et dolore
2516 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2517 // exercitation ullamco laboris nisi ut aliquip ex ea
2518 // commodo consequat.
2519 ```
2520
2521 # Internal Options
2522
2523 ## `emit_mode`
2524
2525 Internal option
2526
2527 ## `make_backup`
2528
2529 Internal option, use `--backup`
2530
2531 ## `print_misformatted_file_names`
2532
2533 Internal option, use `-l` or `--files-with-diff`