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