]> git.lizzy.rs Git - rust.git/blob - Configurations.md
fix: handling of empty str for license template path (#3804)
[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_block_trailing_comma`
1467
1468 Put a trailing comma after a block based match arm (non-block arms are not affected)
1469
1470 - **Default value**: `false`
1471 - **Possible values**: `true`, `false`
1472 - **Stable**: No (tracking issue: #3380)
1473
1474 #### `false` (default):
1475
1476 ```rust
1477 fn main() {
1478     match lorem {
1479         Lorem::Ipsum => {
1480             println!("ipsum");
1481         }
1482         Lorem::Dolor => println!("dolor"),
1483     }
1484 }
1485 ```
1486
1487 #### `true`:
1488
1489 ```rust
1490 fn main() {
1491     match lorem {
1492         Lorem::Ipsum => {
1493             println!("ipsum");
1494         },
1495         Lorem::Dolor => println!("dolor"),
1496     }
1497 }
1498 ```
1499
1500 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1501
1502 ## `max_width`
1503
1504 Maximum width of each line
1505
1506 - **Default value**: `100`
1507 - **Possible values**: any positive integer
1508 - **Stable**: Yes
1509
1510 See also [`error_on_line_overflow`](#error_on_line_overflow).
1511
1512 ## `merge_derives`
1513
1514 Merge multiple derives into a single one.
1515
1516 - **Default value**: `true`
1517 - **Possible values**: `true`, `false`
1518 - **Stable**: Yes
1519
1520 #### `true` (default):
1521
1522 ```rust
1523 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1524 pub enum Foo {}
1525 ```
1526
1527 #### `false`:
1528
1529 ```rust
1530 #[derive(Eq, PartialEq)]
1531 #[derive(Debug)]
1532 #[derive(Copy, Clone)]
1533 pub enum Foo {}
1534 ```
1535
1536 ## `merge_imports`
1537
1538 Merge multiple imports into a single nested import.
1539
1540 - **Default value**: `false`
1541 - **Possible values**: `true`, `false`
1542 - **Stable**: No (tracking issue: #3362)
1543
1544 #### `false` (default):
1545
1546 ```rust
1547 use foo::{a, c, d};
1548 use foo::{b, g};
1549 use foo::{e, f};
1550 ```
1551
1552 #### `true`:
1553
1554 ```rust
1555 use foo::{a, b, c, d, e, f, g};
1556 ```
1557
1558
1559 ## `newline_style`
1560
1561 Unix or Windows line endings
1562
1563 - **Default value**: `"Auto"`
1564 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1565 - **Stable**: Yes
1566
1567 #### `Auto` (default):
1568
1569 The newline style is detected automatically on a per-file basis. Files
1570 with mixed line endings will be converted to the first detected line
1571 ending style.
1572
1573 #### `Native`
1574
1575 Line endings will be converted to `\r\n` on Windows and `\n` on all
1576 other platforms.
1577
1578 #### `Unix`
1579
1580 Line endings will be converted to `\n`.
1581
1582 #### `Windows`
1583
1584 Line endings will be converted to `\r\n`.
1585
1586 ## `normalize_comments`
1587
1588 Convert /* */ comments to // comments where possible
1589
1590 - **Default value**: `false`
1591 - **Possible values**: `true`, `false`
1592 - **Stable**: No (tracking issue: #3350)
1593
1594 #### `false` (default):
1595
1596 ```rust
1597 // Lorem ipsum:
1598 fn dolor() -> usize {}
1599
1600 /* sit amet: */
1601 fn adipiscing() -> usize {}
1602 ```
1603
1604 #### `true`:
1605
1606 ```rust
1607 // Lorem ipsum:
1608 fn dolor() -> usize {}
1609
1610 // sit amet:
1611 fn adipiscing() -> usize {}
1612 ```
1613
1614 ## `normalize_doc_attributes`
1615
1616 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1617
1618 - **Default value**: `false`
1619 - **Possible values**: `true`, `false`
1620 - **Stable**: No (tracking issue: #3351)
1621
1622 #### `false` (default):
1623
1624 ```rust
1625 #![doc = "Example documentation"]
1626
1627 #[doc = "Example item documentation"]
1628 pub enum Foo {}
1629 ```
1630
1631 #### `true`:
1632
1633 ```rust
1634 //! Example documentation
1635
1636 /// Example item documentation
1637 pub enum Foo {}
1638 ```
1639
1640 ## `overflow_delimited_expr`
1641
1642 When structs, slices, arrays, and block/array-like macros are used as the last
1643 argument in an expression list, allow them to overflow (like blocks/closures)
1644 instead of being indented on a new line.
1645
1646 - **Default value**: `false`
1647 - **Possible values**: `true`, `false`
1648 - **Stable**: No (tracking issue: #3370)
1649
1650 #### `false` (default):
1651
1652 ```rust
1653 fn example() {
1654     foo(ctx, |param| {
1655         action();
1656         foo(param)
1657     });
1658
1659     foo(
1660         ctx,
1661         Bar {
1662             x: value,
1663             y: value2,
1664         },
1665     );
1666
1667     foo(
1668         ctx,
1669         &[
1670             MAROON_TOMATOES,
1671             PURPLE_POTATOES,
1672             ORGANE_ORANGES,
1673             GREEN_PEARS,
1674             RED_APPLES,
1675         ],
1676     );
1677
1678     foo(
1679         ctx,
1680         vec![
1681             MAROON_TOMATOES,
1682             PURPLE_POTATOES,
1683             ORGANE_ORANGES,
1684             GREEN_PEARS,
1685             RED_APPLES,
1686         ],
1687     );
1688 }
1689 ```
1690
1691 #### `true`:
1692
1693 ```rust
1694 fn example() {
1695     foo(ctx, |param| {
1696         action();
1697         foo(param)
1698     });
1699
1700     foo(ctx, Bar {
1701         x: value,
1702         y: value2,
1703     });
1704
1705     foo(ctx, &[
1706         MAROON_TOMATOES,
1707         PURPLE_POTATOES,
1708         ORGANE_ORANGES,
1709         GREEN_PEARS,
1710         RED_APPLES,
1711     ]);
1712
1713     foo(ctx, vec![
1714         MAROON_TOMATOES,
1715         PURPLE_POTATOES,
1716         ORGANE_ORANGES,
1717         GREEN_PEARS,
1718         RED_APPLES,
1719     ]);
1720 }
1721 ```
1722
1723 ## `remove_nested_parens`
1724
1725 Remove nested parens.
1726
1727 - **Default value**: `true`,
1728 - **Possible values**: `true`, `false`
1729 - **Stable**: Yes
1730
1731
1732 #### `true` (default):
1733 ```rust
1734 fn main() {
1735     (foo());
1736 }
1737 ```
1738
1739 #### `false`:
1740 ```rust
1741 fn main() {
1742     ((((foo()))));
1743 }
1744 ```
1745
1746
1747 ## `reorder_impl_items`
1748
1749 Reorder impl items. `type` and `const` are put first, then macros and methods.
1750
1751 - **Default value**: `false`
1752 - **Possible values**: `true`, `false`
1753 - **Stable**: No (tracking issue: #3363)
1754
1755 #### `false` (default)
1756
1757 ```rust
1758 struct Dummy;
1759
1760 impl Iterator for Dummy {
1761     fn next(&mut self) -> Option<Self::Item> {
1762         None
1763     }
1764
1765     type Item = i32;
1766 }
1767 ```
1768
1769 #### `true`
1770
1771 ```rust
1772 struct Dummy;
1773
1774 impl Iterator for Dummy {
1775     type Item = i32;
1776
1777     fn next(&mut self) -> Option<Self::Item> {
1778         None
1779     }
1780 }
1781 ```
1782
1783 ## `reorder_imports`
1784
1785 Reorder import and extern crate statements alphabetically in groups (a group is
1786 separated by a newline).
1787
1788 - **Default value**: `true`
1789 - **Possible values**: `true`, `false`
1790 - **Stable**: Yes
1791
1792 #### `true` (default):
1793
1794 ```rust
1795 use dolor;
1796 use ipsum;
1797 use lorem;
1798 use sit;
1799 ```
1800
1801 #### `false`:
1802
1803 ```rust
1804 use lorem;
1805 use ipsum;
1806 use dolor;
1807 use sit;
1808 ```
1809
1810
1811 ## `reorder_modules`
1812
1813 Reorder `mod` declarations alphabetically in group.
1814
1815 - **Default value**: `true`
1816 - **Possible values**: `true`, `false`
1817 - **Stable**: Yes
1818
1819 #### `true` (default)
1820
1821 ```rust
1822 mod a;
1823 mod b;
1824
1825 mod dolor;
1826 mod ipsum;
1827 mod lorem;
1828 mod sit;
1829 ```
1830
1831 #### `false`
1832
1833 ```rust
1834 mod b;
1835 mod a;
1836
1837 mod lorem;
1838 mod ipsum;
1839 mod dolor;
1840 mod sit;
1841 ```
1842
1843 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
1844 of the original source code.
1845
1846 ## `report_fixme`
1847
1848 Report `FIXME` items in comments.
1849
1850 - **Default value**: `"Never"`
1851 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1852 - **Stable**: No (tracking issue: #3394)
1853
1854 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1855 it contains a `#X` (with `X` being a number) in parentheses following the
1856 `FIXME`, `"Unnumbered"` will ignore it.
1857
1858 See also [`report_todo`](#report_todo).
1859
1860
1861 ## `report_todo`
1862
1863 Report `TODO` items in comments.
1864
1865 - **Default value**: `"Never"`
1866 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1867 - **Stable**: No (tracking issue: #3393)
1868
1869 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1870 it contains a `#X` (with `X` being a number) in parentheses following the
1871 `TODO`, `"Unnumbered"` will ignore it.
1872
1873 See also [`report_fixme`](#report_fixme).
1874
1875 ## `required_version`
1876
1877 Require a specific version of rustfmt. If you want to make sure that the
1878 specific version of rustfmt is used in your CI, use this option.
1879
1880 - **Default value**: `CARGO_PKG_VERSION`
1881 - **Possible values**: any published version (e.g. `"0.3.8"`)
1882 - **Stable**: No (tracking issue: #3386)
1883
1884 ## `skip_children`
1885
1886 Don't reformat out of line modules
1887
1888 - **Default value**: `false`
1889 - **Possible values**: `true`, `false`
1890 - **Stable**: No (tracking issue: #3389)
1891
1892 ## `space_after_colon`
1893
1894 Leave a space after the colon.
1895
1896 - **Default value**: `true`
1897 - **Possible values**: `true`, `false`
1898 - **Stable**: No (tracking issue: #3366)
1899
1900 #### `true` (default):
1901
1902 ```rust
1903 fn lorem<T: Eq>(t: T) {
1904     let lorem: Dolor = Lorem {
1905         ipsum: dolor,
1906         sit: amet,
1907     };
1908 }
1909 ```
1910
1911 #### `false`:
1912
1913 ```rust
1914 fn lorem<T:Eq>(t:T) {
1915     let lorem:Dolor = Lorem {
1916         ipsum:dolor,
1917         sit:amet,
1918     };
1919 }
1920 ```
1921
1922 See also: [`space_before_colon`](#space_before_colon).
1923
1924 ## `space_before_colon`
1925
1926 Leave a space before the colon.
1927
1928 - **Default value**: `false`
1929 - **Possible values**: `true`, `false`
1930 - **Stable**: No (tracking issue: #3365)
1931
1932 #### `false` (default):
1933
1934 ```rust
1935 fn lorem<T: Eq>(t: T) {
1936     let lorem: Dolor = Lorem {
1937         ipsum: dolor,
1938         sit: amet,
1939     };
1940 }
1941 ```
1942
1943 #### `true`:
1944
1945 ```rust
1946 fn lorem<T : Eq>(t : T) {
1947     let lorem : Dolor = Lorem {
1948         ipsum : dolor,
1949         sit : amet,
1950     };
1951 }
1952 ```
1953
1954 See also: [`space_after_colon`](#space_after_colon).
1955
1956 ## `spaces_around_ranges`
1957
1958 Put spaces around the .., ..=, and ... range operators
1959
1960 - **Default value**: `false`
1961 - **Possible values**: `true`, `false`
1962 - **Stable**: No (tracking issue: #3367)
1963
1964 #### `false` (default):
1965
1966 ```rust
1967 fn main() {
1968     let lorem = 0..10;
1969     let ipsum = 0..=10;
1970
1971     match lorem {
1972         1..5 => foo(),
1973         _ => bar,
1974     }
1975
1976     match lorem {
1977         1..=5 => foo(),
1978         _ => bar,
1979     }
1980
1981     match lorem {
1982         1...5 => foo(),
1983         _ => bar,
1984     }
1985 }
1986 ```
1987
1988 #### `true`:
1989
1990 ```rust
1991 fn main() {
1992     let lorem = 0 .. 10;
1993     let ipsum = 0 ..= 10;
1994
1995     match lorem {
1996         1 .. 5 => foo(),
1997         _ => bar,
1998     }
1999
2000     match lorem {
2001         1 ..= 5 => foo(),
2002         _ => bar,
2003     }
2004
2005     match lorem {
2006         1 ... 5 => foo(),
2007         _ => bar,
2008     }
2009 }
2010 ```
2011
2012 ## `struct_field_align_threshold`
2013
2014 The maximum diff of width between struct fields to be aligned with each other.
2015
2016 - **Default value** : 0
2017 - **Possible values**: any non-negative integer
2018 - **Stable**: No (tracking issue: #3371)
2019
2020 #### `0` (default):
2021
2022 ```rust
2023 struct Foo {
2024     x: u32,
2025     yy: u32,
2026     zzz: u32,
2027 }
2028 ```
2029
2030 #### `20`:
2031
2032 ```rust
2033 struct Foo {
2034     x:   u32,
2035     yy:  u32,
2036     zzz: u32,
2037 }
2038 ```
2039
2040 ## `struct_lit_single_line`
2041
2042 Put small struct literals on a single line
2043
2044 - **Default value**: `true`
2045 - **Possible values**: `true`, `false`
2046 - **Stable**: No (tracking issue: #3357)
2047
2048 #### `true` (default):
2049
2050 ```rust
2051 fn main() {
2052     let lorem = Lorem { foo: bar, baz: ofo };
2053 }
2054 ```
2055
2056 #### `false`:
2057
2058 ```rust
2059 fn main() {
2060     let lorem = Lorem {
2061         foo: bar,
2062         baz: ofo,
2063     };
2064 }
2065 ```
2066
2067 See also: [`indent_style`](#indent_style).
2068
2069
2070 ## `tab_spaces`
2071
2072 Number of spaces per tab
2073
2074 - **Default value**: `4`
2075 - **Possible values**: any positive integer
2076 - **Stable**: Yes
2077
2078 #### `4` (default):
2079
2080 ```rust
2081 fn lorem() {
2082     let ipsum = dolor();
2083     let sit = vec![
2084         "amet consectetur adipiscing elit amet",
2085         "consectetur adipiscing elit amet consectetur.",
2086     ];
2087 }
2088 ```
2089
2090 #### `2`:
2091
2092 ```rust
2093 fn lorem() {
2094   let ipsum = dolor();
2095   let sit = vec![
2096     "amet consectetur adipiscing elit amet",
2097     "consectetur adipiscing elit amet consectetur.",
2098   ];
2099 }
2100 ```
2101
2102 See also: [`hard_tabs`](#hard_tabs).
2103
2104
2105 ## `trailing_comma`
2106
2107 How to handle trailing commas for lists
2108
2109 - **Default value**: `"Vertical"`
2110 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
2111 - **Stable**: No (tracking issue: #3379)
2112
2113 #### `"Vertical"` (default):
2114
2115 ```rust
2116 fn main() {
2117     let Lorem { ipsum, dolor, sit } = amet;
2118     let Lorem {
2119         ipsum,
2120         dolor,
2121         sit,
2122         amet,
2123         consectetur,
2124         adipiscing,
2125     } = elit;
2126 }
2127 ```
2128
2129 #### `"Always"`:
2130
2131 ```rust
2132 fn main() {
2133     let Lorem { ipsum, dolor, sit, } = amet;
2134     let Lorem {
2135         ipsum,
2136         dolor,
2137         sit,
2138         amet,
2139         consectetur,
2140         adipiscing,
2141     } = elit;
2142 }
2143 ```
2144
2145 #### `"Never"`:
2146
2147 ```rust
2148 fn main() {
2149     let Lorem { ipsum, dolor, sit } = amet;
2150     let Lorem {
2151         ipsum,
2152         dolor,
2153         sit,
2154         amet,
2155         consectetur,
2156         adipiscing
2157     } = elit;
2158 }
2159 ```
2160
2161 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2162
2163 ## `trailing_semicolon`
2164
2165 Add trailing semicolon after break, continue and return
2166
2167 - **Default value**: `true`
2168 - **Possible values**: `true`, `false`
2169 - **Stable**: No (tracking issue: #3378)
2170
2171 #### `true` (default):
2172 ```rust
2173 fn foo() -> usize {
2174     return 0;
2175 }
2176 ```
2177
2178 #### `false`:
2179 ```rust
2180 fn foo() -> usize {
2181     return 0
2182 }
2183 ```
2184
2185 ## `type_punctuation_density`
2186
2187 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2188
2189 - **Default value**: `"Wide"`
2190 - **Possible values**: `"Compressed"`, `"Wide"`
2191 - **Stable**: No (tracking issue: #3364)
2192
2193 #### `"Wide"` (default):
2194
2195 ```rust
2196 fn lorem<Ipsum: Dolor + Sit = Amet>() {
2197     // body
2198 }
2199 ```
2200
2201 #### `"Compressed"`:
2202
2203 ```rust
2204 fn lorem<Ipsum: Dolor+Sit=Amet>() {
2205     // body
2206 }
2207 ```
2208
2209 ## `unstable_features`
2210
2211 Enable unstable features on the unstable channel.
2212
2213 - **Default value**: `false`
2214 - **Possible values**: `true`, `false`
2215 - **Stable**: No (tracking issue: #3387)
2216
2217 ## `use_field_init_shorthand`
2218
2219 Use field initialize shorthand if possible.
2220
2221 - **Default value**: `false`
2222 - **Possible values**: `true`, `false`
2223 - **Stable**: Yes
2224
2225 #### `false` (default):
2226
2227 ```rust
2228 struct Foo {
2229     x: u32,
2230     y: u32,
2231     z: u32,
2232 }
2233
2234 fn main() {
2235     let x = 1;
2236     let y = 2;
2237     let z = 3;
2238     let a = Foo { x: x, y: y, z: z };
2239 }
2240 ```
2241
2242 #### `true`:
2243
2244 ```rust
2245 struct Foo {
2246     x: u32,
2247     y: u32,
2248     z: u32,
2249 }
2250
2251 fn main() {
2252     let x = 1;
2253     let y = 2;
2254     let z = 3;
2255     let a = Foo { x, y, z };
2256 }
2257 ```
2258
2259 ## `use_small_heuristics`
2260
2261 Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2262
2263 - **Default value**: `"Default"`
2264 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
2265 - **Stable**: Yes
2266
2267 #### `Default` (default):
2268
2269 ```rust
2270 enum Lorem {
2271     Ipsum,
2272     Dolor(bool),
2273     Sit { amet: Consectetur, adipiscing: Elit },
2274 }
2275
2276 fn main() {
2277     lorem(
2278         "lorem",
2279         "ipsum",
2280         "dolor",
2281         "sit",
2282         "amet",
2283         "consectetur",
2284         "adipiscing",
2285     );
2286
2287     let lorem = Lorem {
2288         ipsum: dolor,
2289         sit: amet,
2290     };
2291     let lorem = Lorem { ipsum: dolor };
2292
2293     let lorem = if ipsum { dolor } else { sit };
2294 }
2295 ```
2296
2297 #### `Off`:
2298
2299 ```rust
2300 enum Lorem {
2301     Ipsum,
2302     Dolor(bool),
2303     Sit {
2304         amet: Consectetur,
2305         adipiscing: Elit,
2306     },
2307 }
2308
2309 fn main() {
2310     lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2311
2312     let lorem = Lorem {
2313         ipsum: dolor,
2314         sit: amet,
2315     };
2316
2317     let lorem = if ipsum {
2318         dolor
2319     } else {
2320         sit
2321     };
2322 }
2323 ```
2324
2325 #### `Max`:
2326
2327 ```rust
2328 enum Lorem {
2329     Ipsum,
2330     Dolor(bool),
2331     Sit { amet: Consectetur, adipiscing: Elit },
2332 }
2333
2334 fn main() {
2335     lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2336
2337     let lorem = Lorem { ipsum: dolor, sit: amet };
2338
2339     let lorem = if ipsum { dolor } else { sit };
2340 }
2341 ```
2342
2343 ## `use_try_shorthand`
2344
2345 Replace uses of the try! macro by the ? shorthand
2346
2347 - **Default value**: `false`
2348 - **Possible values**: `true`, `false`
2349 - **Stable**: Yes
2350
2351 #### `false` (default):
2352
2353 ```rust
2354 fn main() {
2355     let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2356 }
2357 ```
2358
2359 #### `true`:
2360
2361 ```rust
2362 fn main() {
2363     let lorem = ipsum.map(|dolor| dolor.sit())?;
2364 }
2365 ```
2366
2367 ## `version`
2368
2369 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2370 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2371 version number.
2372
2373 - **Default value**: `One`
2374 - **Possible values**: `One`, `Two`
2375 - **Stable**: No (tracking issue: #3383)
2376
2377 ### Example
2378
2379 ```toml
2380 version = "Two"
2381 ```
2382
2383 ## `where_single_line`
2384
2385 Forces the `where` clause to be laid out on a single line.
2386
2387 - **Default value**: `false`
2388 - **Possible values**: `true`, `false`
2389 - **Stable**: No (tracking issue: #3359)
2390
2391 #### `false` (default):
2392
2393 ```rust
2394 impl<T> Lorem for T
2395 where
2396     Option<T>: Ipsum,
2397 {
2398     // body
2399 }
2400 ```
2401
2402 #### `true`:
2403
2404 ```rust
2405 impl<T> Lorem for T
2406 where Option<T>: Ipsum
2407 {
2408     // body
2409 }
2410 ```
2411
2412 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2413
2414
2415 ## `wrap_comments`
2416
2417 Break comments to fit on the line
2418
2419 - **Default value**: `false`
2420 - **Possible values**: `true`, `false`
2421 - **Stable**: No (tracking issue: #3347)
2422
2423 #### `false` (default):
2424
2425 ```rust
2426 // 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.
2427 ```
2428
2429 #### `true`:
2430
2431 ```rust
2432 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2433 // sed do eiusmod tempor incididunt ut labore et dolore
2434 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2435 // exercitation ullamco laboris nisi ut aliquip ex ea
2436 // commodo consequat.
2437 ```
2438
2439 # Internal Options
2440
2441 ## `emit_mode`
2442
2443 Internal option
2444
2445 ## `make_backup`
2446
2447 Internal option, use `--backup`
2448
2449 ## `print_misformatted_file_names`
2450
2451 Internal option, use `-l` or `--files-with-diff`