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.
5 A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
9 reorder_imports = false
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.
16 # Configuration Options
18 Below you find a detailed visual guide on all the supported configuration options of rustfmt:
22 Maximum width of an array literal before falling back to vertical formatting.
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)
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.
30 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
32 ## `attr_fn_like_width`
34 Maximum width of the args of a function-like attributes before falling back to vertical formatting.
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)
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.
42 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
46 Where to put a binary operator when a binary expression goes multiline.
48 - **Default value**: `"Front"`
49 - **Possible values**: `"Front"`, `"Back"`
50 - **Stable**: No (tracking issue: #3368)
52 #### `"Front"` (default):
56 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
57 || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
59 let sum = 123456789012345678901234567890
60 + 123456789012345678901234567890
61 + 123456789012345678901234567890;
63 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
64 ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
72 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
73 barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
75 let sum = 123456789012345678901234567890 +
76 123456789012345678901234567890 +
77 123456789012345678901234567890;
79 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
80 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
84 ## `blank_lines_lower_bound`
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.
89 - **Default value**: `0`
90 - **Possible values**: *unsigned integer*
91 - **Stable**: No (tracking issue: #3382)
94 Original Code (rustfmt will not change it with the default value of `0`):
124 ## `blank_lines_upper_bound`
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.
129 - **Default value**: `1`
130 - **Possible values**: any non-negative integer
131 - **Stable**: No (tracking issue: #3381)
181 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
185 Brace style for items
187 - **Default value**: `"SameLineWhere"`
188 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
189 - **Stable**: No (tracking issue: #3376)
193 #### `"SameLineWhere"` (default):
200 fn lorem(ipsum: usize) {
204 fn lorem<T>(ipsum: T)
206 T: Add + Sub + Mul + Div,
212 #### `"AlwaysNextLine"`:
220 fn lorem(ipsum: usize)
225 fn lorem<T>(ipsum: T)
227 T: Add + Sub + Mul + Div,
233 #### `"PreferSameLine"`:
240 fn lorem(ipsum: usize) {
244 fn lorem<T>(ipsum: T)
246 T: Add + Sub + Mul + Div, {
251 ### Structs and enums
253 #### `"SameLineWhere"` (default):
268 #### `"AlwaysNextLine"`:
284 #### `"PreferSameLine"`:
300 Maximum width of a chain to fit on one line.
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)
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.
308 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
312 Whether to use colored output or not.
314 - **Default value**: `"Auto"`
315 - **Possible values**: "Auto", "Always", "Never"
316 - **Stable**: No (tracking issue: #3385)
318 ## `combine_control_expr`
320 Combine control expressions with function calls.
322 - **Default value**: `true`
323 - **Possible values**: `true`, `false`
324 - **Stable**: No (tracking issue: #3369)
326 #### `true` (default):
338 foo!(if let Some(..) = x {
351 foo!(while let Some(..) = x {
385 if let Some(..) = x {
402 while let Some(..) = x {
428 Maximum length of comments. No effect unless`wrap_comments = true`.
430 - **Default value**: `80`
431 - **Possible values**: any positive integer
432 - **Stable**: No (tracking issue: #3349)
434 **Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
436 #### `80` (default; comments shorter than `comment_width`):
438 // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
441 #### `60` (comments longer than `comment_width`):
443 // Lorem ipsum dolor sit amet,
444 // consectetur adipiscing elit.
447 See also [`wrap_comments`](#wrap_comments).
449 ## `condense_wildcard_suffixes`
451 Replace strings of _ wildcards by a single .. in tuple patterns
453 - **Default value**: `false`
454 - **Possible values**: `true`, `false`
455 - **Stable**: No (tracking issue: #3384)
457 #### `false` (default):
461 let (lorem, ipsum, _, _) = (1, 2, 3, 4);
462 let (lorem, ipsum, ..) = (1, 2, 3, 4);
470 let (lorem, ipsum, ..) = (1, 2, 3, 4);
474 ## `control_brace_style`
476 Brace style for control flow constructs
478 - **Default value**: `"AlwaysSameLine"`
479 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
480 - **Stable**: No (tracking issue: #3377)
482 #### `"AlwaysSameLine"` (default):
494 #### `"AlwaysNextLine"`:
509 #### `"ClosingNextLine"`:
522 ## `disable_all_formatting`
524 Don't reformat anything
526 - **Default value**: `false`
527 - **Possible values**: `true`, `false`
528 - **Stable**: No (tracking issue: #3388)
532 Specifies which edition is used by the parser.
534 - **Default value**: `"2015"`
535 - **Possible values**: `"2015"`, `"2018"`, `"2021"`
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
546 ## `empty_item_single_line`
548 Put empty-body functions and impls on a single line
550 - **Default value**: `true`
551 - **Possible values**: `true`, `false`
552 - **Stable**: No (tracking issue: #3356)
554 #### `true` (default):
572 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
575 ## `enum_discrim_align_threshold`
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.
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.
583 - **Default value** : 0
584 - **Possible values**: any positive integer
585 - **Stable**: No (tracking issue: #3372)
593 RandomLongVariantGoesHere = 10,
598 VeryLongVariantNameHereA = 0,
599 VeryLongVariantNameHereBb = 1,
600 VeryLongVariantNameHereCcc = 2,
610 RandomLongVariantGoesHere = 10,
615 VeryLongVariantNameHereA = 0,
616 VeryLongVariantNameHereBb = 1,
617 VeryLongVariantNameHereCcc = 2,
622 ## `error_on_line_overflow`
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.
629 - **Default value**: `false`
630 - **Possible values**: `true`, `false`
631 - **Stable**: No (tracking issue: #3391)
633 See also [`max_width`](#max_width).
635 ## `error_on_unformatted`
637 Error if unable to get comments or string literals within `max_width`, or they are left with
638 trailing whitespaces.
640 - **Default value**: `false`
641 - **Possible values**: `true`, `false`
642 - **Stable**: No (tracking issue: #3392)
646 Control the layout of arguments in a function
648 - **Default value**: `"Tall"`
649 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
652 #### `"Tall"` (default):
656 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
658 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
667 consectetur: Consectetur,
668 adipiscing: Adipiscing,
677 consectetur: Consectetur,
678 adipiscing: Adipiscing,
690 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
692 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
697 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
698 adipiscing: Adipiscing, elit: Elit,
702 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
703 adipiscing: Adipiscing, elit: Elit,
735 consectetur: Consectetur,
736 adipiscing: Adipiscing,
745 consectetur: Consectetur,
746 adipiscing: Adipiscing,
756 Maximum width of the args of a function call before falling back to vertical formatting.
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)
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.
764 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
768 Put single-expression functions on a single line
770 - **Default value**: `false`
771 - **Possible values**: `true`, `false`
772 - **Stable**: No (tracking issue: #3358)
774 #### `false` (default):
777 fn lorem() -> usize {
781 fn lorem() -> usize {
790 fn lorem() -> usize { 42 }
792 fn lorem() -> usize {
798 See also [`control_brace_style`](#control_brace_style).
801 ## `force_explicit_abi`
803 Always print the abi for extern items
805 - **Default value**: `true`
806 - **Possible values**: `true`, `false`
809 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
811 #### `true` (default):
815 pub static lorem: c_int;
823 pub static lorem: c_int;
827 ## `force_multiline_blocks`
829 Force multiline closure and match arm bodies to be wrapped in a block
831 - **Default value**: `false`
832 - **Possible values**: `false`, `true`
833 - **Stable**: No (tracking issue: #3374)
835 #### `false` (default):
839 result.and_then(|maybe_value| match maybe_value {
841 Some(value) => bar(),
846 println!("Hello World");
848 Some(dolor) => foo(),
857 result.and_then(|maybe_value| {
860 Some(value) => bar(),
867 println!("Hello World");
870 Some(dolor) => foo(),
876 ## `format_code_in_doc_comments`
878 Format code snippet included in doc comments.
880 - **Default value**: `false`
881 - **Possible values**: `true`, `false`
882 - **Stable**: No (tracking issue: #3348)
884 #### `false` (default):
887 /// Adds one to the number given.
898 /// # fn add_one(x: i32) -> i32 {
902 fn add_one(x: i32) -> i32 {
910 /// Adds one to the number given.
917 /// assert_eq!(6, add_one(5));
918 /// # fn add_one(x: i32) -> i32 {
922 fn add_one(x: i32) -> i32 {
927 ## `format_generated_files`
929 Format generated files. A file is considered generated
930 if any of the first five lines contains `@generated` marker.
932 - **Default value**: `false`
933 - **Possible values**: `true`, `false`
936 ## `format_macro_matchers`
938 Format the metavariable matching patterns in macros.
940 - **Default value**: `false`
941 - **Possible values**: `true`, `false`
942 - **Stable**: No (tracking issue: #3354)
944 #### `false` (default):
948 ($a: ident : $b: ty) => {
951 ($a: ident $b: ident $c: ident) => {
961 ($a:ident : $b:ty) => {
964 ($a:ident $b:ident $c:ident) => {
970 See also [`format_macro_bodies`](#format_macro_bodies).
973 ## `format_macro_bodies`
975 Format the bodies of macros.
977 - **Default value**: `true`
978 - **Possible values**: `true`, `false`
979 - **Stable**: No (tracking issue: #3355)
981 #### `true` (default):
985 ($a: ident : $b: ty) => {
988 ($a: ident $b: ident $c: ident) => {
998 ($a: ident : $b: ty) => { $a(42): $b; };
999 ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
1003 See also [`format_macro_matchers`](#format_macro_matchers).
1008 Format string literals where necessary
1010 - **Default value**: `false`
1011 - **Possible values**: `true`, `false`
1012 - **Stable**: No (tracking issue: #3353)
1014 #### `false` (default):
1018 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
1026 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
1027 consectetur adipiscing";
1031 See also [`max_width`](#max_width).
1035 Use tab characters for indentation, spaces for alignment
1037 - **Default value**: `false`
1038 - **Possible values**: `true`, `false`
1041 #### `false` (default):
1044 fn lorem() -> usize {
1045 42 // spaces before 42
1052 fn lorem() -> usize {
1053 42 // tabs before 42
1057 See also: [`tab_spaces`](#tab_spaces).
1059 ## `hex_literal_case`
1061 Control the case of the letters in hexadecimal literal values
1063 - **Default value**: `Preserve`
1064 - **Possible values**: `Upper`, `Lower`
1067 ## `hide_parse_errors`
1069 Do not show parse errors if the parser failed to parse files.
1071 - **Default value**: `false`
1072 - **Possible values**: `true`, `false`
1073 - **Stable**: No (tracking issue: #3390)
1077 Skip formatting files and directories that match the specified pattern.
1078 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.
1080 - **Default value**: format every file
1081 - **Possible values**: See an example below
1082 - **Stable**: No (tracking issue: #3395)
1086 If you want to ignore specific files, put the following to your config file:
1095 If you want to ignore every file under `examples/`, put the following to your config file:
1103 If you want to ignore every file under the directory where you put your rustfmt.toml:
1111 Indent style of imports
1113 - **Default Value**: `"Block"`
1114 - **Possible values**: `"Block"`, `"Visual"`
1115 - **Stable**: No (tracking issue: #3360)
1117 #### `"Block"` (default):
1121 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1122 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1129 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1130 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1133 See also: [`imports_layout`](#imports_layout).
1137 Item layout inside a imports block
1139 - **Default value**: "Mixed"
1140 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1141 - **Stable**: No (tracking issue: #3361)
1143 #### `"Mixed"` (default):
1146 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1149 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1150 eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1154 #### `"Horizontal"`:
1156 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1159 use foo::{xxx, yyy, zzz};
1161 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1164 #### `"HorizontalVertical"`:
1167 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1200 Indent on expressions or items.
1202 - **Default value**: `"Block"`
1203 - **Possible values**: `"Block"`, `"Visual"`
1204 - **Stable**: No (tracking issue: #3346)
1208 #### `"Block"` (default):
1228 let lorem = vec!["ipsum",
1240 #### `"Block"` (default):
1248 && dolor_consectetur
1250 && lorem_consectetur
1265 && dolor_consectetur
1267 && lorem_consectetur
1274 See also: [`control_brace_style`](#control_brace_style).
1276 ### Function arguments
1278 #### `"Block"` (default):
1283 fn lorem(ipsum: usize) {}
1303 fn lorem(ipsum: usize) {}
1305 fn lorem(ipsum: usize,
1318 #### `"Block"` (default):
1352 #### `"Block"` (default):
1360 Adipiscing: Eq = usize,
1361 Consectetur: Eq = usize,
1368 adipiscing: Adipiscing,
1369 consectetur: Consectetur,
1379 fn lorem<Ipsum: Eq = usize,
1383 Adipiscing: Eq = usize,
1384 Consectetur: Eq = usize,
1390 adipiscing: Adipiscing,
1391 consectetur: Consectetur,
1400 #### `"Block"` (default):
1415 let lorem = Lorem { ipsum: dolor,
1420 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
1422 ### Where predicates
1424 #### `"Block"` (default):
1427 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1441 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1451 ## `inline_attribute_width`
1453 Write an item and its attribute on the same line if their combined width is below a threshold
1455 - **Default value**: 0
1456 - **Possible values**: any positive integer
1457 - **Stable**: No (tracking issue: #3343)
1463 #[cfg(feature = "alloc")]
1469 #[cfg(feature = "alloc")] use core::slice;
1472 ## `license_template_path`
1474 Check whether beginnings of files match a license template.
1476 - **Default value**: `""`
1477 - **Possible values**: path to a license template file
1478 - **Stable**: No (tracking issue: #3352)
1480 A license template is a plain text file which is matched literally against the
1481 beginning of each source file, except for `{}`-delimited blocks, which are
1482 matched as regular expressions. The following license template therefore
1483 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
1484 Copyright 2018 The Rust Project Developers.`, etc.:
1487 // Copyright {\d+} The Rust Project Developers.
1490 `\{`, `\}` and `\\` match literal braces / backslashes.
1492 ## `match_arm_blocks`
1494 Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.
1496 The Style Guide requires that bodies are block wrapped by default if a line break is required after the `=>`, but this option can be used to disable that behavior to prevent wrapping arm bodies in that event, so long as the body does not contain multiple statements nor line comments.
1498 - **Default value**: `true`
1499 - **Possible values**: `true`, `false`
1500 - **Stable**: No (tracking issue: #3373)
1502 #### `true` (default):
1508 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1510 dolor => println!("{}", sit),
1512 "foooooooooooooooooooooooo",
1513 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1514 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1515 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1527 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1528 ipsum => println!("{}", sit),
1530 "foooooooooooooooooooooooo",
1531 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1532 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1533 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1539 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1541 ## `match_arm_leading_pipes`
1543 Controls whether to include a leading pipe on match arms
1545 - **Default value**: `Never`
1546 - **Possible values**: `Always`, `Never`, `Preserve`
1549 #### `Never` (default):
1551 // Leading pipes are removed from this:
1554 // | "foo" | "bar" => {}
1556 // | "something relatively long"
1557 // | "something really really really realllllllllllllly long" => println!("x"),
1558 // | "qux" => println!("y"),
1568 | "something relatively long"
1569 | "something really really really realllllllllllllly long" => println!("x"),
1570 "qux" => println!("y"),
1578 // Leading pipes are emitted on all arms of this:
1581 // "foo" | "bar" => {}
1583 // | "something relatively long"
1584 // | "something really really really realllllllllllllly long" => println!("x"),
1585 // "qux" => println!("y"),
1593 | "foo" | "bar" => {}
1595 | "something relatively long"
1596 | "something really really really realllllllllllllly long" => println!("x"),
1597 | "qux" => println!("y"),
1607 | "foo" | "bar" => {}
1609 | "something relatively long"
1610 | "something really really really realllllllllllllly long" => println!("x"),
1611 | "qux" => println!("y"),
1623 ## `match_block_trailing_comma`
1625 Put a trailing comma after a block based match arm (non-block arms are not affected)
1627 - **Default value**: `false`
1628 - **Possible values**: `true`, `false`
1629 - **Stable**: No (tracking issue: #3380)
1631 #### `false` (default):
1639 Lorem::Dolor => println!("dolor"),
1652 Lorem::Dolor => println!("dolor"),
1657 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1661 Maximum width of each line
1663 - **Default value**: `100`
1664 - **Possible values**: any positive integer
1667 See also [`error_on_line_overflow`](#error_on_line_overflow).
1671 Merge multiple derives into a single one.
1673 - **Default value**: `true`
1674 - **Possible values**: `true`, `false`
1677 #### `true` (default):
1680 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1687 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1690 #[derive(Eq, PartialEq)]
1692 #[derive(Copy, Clone)]
1696 ## `imports_granularity`
1698 How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
1700 - **Default value**: `Preserve`
1701 - **Possible values**: `Preserve`, `Crate`, `Module`, `Item`, `One`
1704 #### `Preserve` (default):
1706 Do not change the granularity of any imports and preserve the original structure written by the developer.
1711 use foo::{a, c, d::e};
1717 Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements.
1731 Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements.
1742 Flatten imports so that each has its own `use` statement.
1757 Merge all imports into a single `use` statement as long as they have the same visibility.
1760 pub use foo::{x, y};
1774 This option is deprecated. Use `imports_granularity = "Crate"` instead.
1776 - **Default value**: `false`
1777 - **Possible values**: `true`, `false`
1779 #### `false` (default):
1790 use foo::{a, b, c, d, e, f, g};
1796 Unix or Windows line endings
1798 - **Default value**: `"Auto"`
1799 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1802 #### `Auto` (default):
1804 The newline style is detected automatically on a per-file basis. Files
1805 with mixed line endings will be converted to the first detected line
1810 Line endings will be converted to `\r\n` on Windows and `\n` on all
1815 Line endings will be converted to `\n`.
1819 Line endings will be converted to `\r\n`.
1821 ## `normalize_comments`
1823 Convert /* */ comments to // comments where possible
1825 - **Default value**: `false`
1826 - **Possible values**: `true`, `false`
1827 - **Stable**: No (tracking issue: #3350)
1829 #### `false` (default):
1833 fn dolor() -> usize {}
1836 fn adipiscing() -> usize {}
1843 fn dolor() -> usize {}
1846 fn adipiscing() -> usize {}
1849 ## `normalize_doc_attributes`
1851 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1853 - **Default value**: `false`
1854 - **Possible values**: `true`, `false`
1855 - **Stable**: No (tracking issue: #3351)
1857 #### `false` (default):
1860 #![doc = "Example documentation"]
1862 #[doc = "Example item documentation"]
1865 /// Example item documentation
1872 //! Example documentation
1874 /// Example item documentation
1878 ## `overflow_delimited_expr`
1880 When structs, slices, arrays, and block/array-like macros are used as the last
1881 argument in an expression list, allow them to overflow (like blocks/closures)
1882 instead of being indented on a new line.
1884 - **Default value**: `false`
1885 - **Possible values**: `true`, `false`
1886 - **Stable**: No (tracking issue: #3370)
1888 #### `false` (default):
1961 ## `remove_nested_parens`
1963 Remove nested parens.
1965 - **Default value**: `true`,
1966 - **Possible values**: `true`, `false`
1970 #### `true` (default):
1987 ## `reorder_impl_items`
1989 Reorder impl items. `type` and `const` are put first, then macros and methods.
1991 - **Default value**: `false`
1992 - **Possible values**: `true`, `false`
1993 - **Stable**: No (tracking issue: #3363)
1995 #### `false` (default)
2000 impl Iterator for Dummy {
2001 fn next(&mut self) -> Option<Self::Item> {
2008 impl Iterator for Dummy {
2011 fn next(&mut self) -> Option<Self::Item> {
2022 impl Iterator for Dummy {
2025 fn next(&mut self) -> Option<Self::Item> {
2031 ## `reorder_imports`
2033 Reorder import and extern crate statements alphabetically in groups (a group is
2034 separated by a newline).
2036 - **Default value**: `true`
2037 - **Possible values**: `true`, `false`
2040 #### `true` (default):
2060 Controls the strategy for how imports are grouped together.
2062 - **Default value**: `Preserve`
2063 - **Possible values**: `Preserve`, `StdExternalCrate`
2066 #### `Preserve` (default):
2068 Preserve the source file's import groups.
2071 use super::update::convert_publish_payload;
2074 use alloc::alloc::Layout;
2075 use juniper::{FieldError, FieldResult};
2080 use broker::database::PooledConnection;
2082 use super::schema::{Context, Payload};
2083 use crate::models::Event;
2087 #### `StdExternalCrate`:
2089 Discard existing import groups, and create three groups for:
2090 1. `std`, `core` and `alloc`,
2092 3. `self`, `super` and `crate` imports.
2095 use alloc::alloc::Layout;
2099 use broker::database::PooledConnection;
2101 use juniper::{FieldError, FieldResult};
2104 use super::schema::{Context, Payload};
2105 use super::update::convert_publish_payload;
2106 use crate::models::Event;
2109 ## `reorder_modules`
2111 Reorder `mod` declarations alphabetically in group.
2113 - **Default value**: `true`
2114 - **Possible values**: `true`, `false`
2117 #### `true` (default)
2141 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
2142 of the original source code.
2146 Report `FIXME` items in comments.
2148 - **Default value**: `"Never"`
2149 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2150 - **Stable**: No (tracking issue: #3394)
2152 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
2153 it contains a `#X` (with `X` being a number) in parentheses following the
2154 `FIXME`, `"Unnumbered"` will ignore it.
2156 See also [`report_todo`](#report_todo).
2161 Report `TODO` items in comments.
2163 - **Default value**: `"Never"`
2164 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2165 - **Stable**: No (tracking issue: #3393)
2167 Warns about any comments containing `TODO` in them when set to `"Always"`. If
2168 it contains a `#X` (with `X` being a number) in parentheses following the
2169 `TODO`, `"Unnumbered"` will ignore it.
2171 See also [`report_fixme`](#report_fixme).
2173 ## `required_version`
2175 Require a specific version of rustfmt. If you want to make sure that the
2176 specific version of rustfmt is used in your CI, use this option.
2178 - **Default value**: `CARGO_PKG_VERSION`
2179 - **Possible values**: any published version (e.g. `"0.3.8"`)
2180 - **Stable**: No (tracking issue: #3386)
2184 Don't reformat out of line modules
2186 - **Default value**: `false`
2187 - **Possible values**: `true`, `false`
2188 - **Stable**: No (tracking issue: #3389)
2190 ## `single_line_if_else_max_width`
2192 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`.
2194 - **Default value**: `50`
2195 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2198 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.
2200 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2202 ## `space_after_colon`
2204 Leave a space after the colon.
2206 - **Default value**: `true`
2207 - **Possible values**: `true`, `false`
2208 - **Stable**: No (tracking issue: #3366)
2210 #### `true` (default):
2213 fn lorem<T: Eq>(t: T) {
2214 let lorem: Dolor = Lorem {
2224 fn lorem<T:Eq>(t:T) {
2225 let lorem:Dolor = Lorem {
2232 See also: [`space_before_colon`](#space_before_colon).
2234 ## `space_before_colon`
2236 Leave a space before the colon.
2238 - **Default value**: `false`
2239 - **Possible values**: `true`, `false`
2240 - **Stable**: No (tracking issue: #3365)
2242 #### `false` (default):
2245 fn lorem<T: Eq>(t: T) {
2246 let lorem: Dolor = Lorem {
2256 fn lorem<T : Eq>(t : T) {
2257 let lorem : Dolor = Lorem {
2264 See also: [`space_after_colon`](#space_after_colon).
2266 ## `spaces_around_ranges`
2268 Put spaces around the .., ..=, and ... range operators
2270 - **Default value**: `false`
2271 - **Possible values**: `true`, `false`
2272 - **Stable**: No (tracking issue: #3367)
2274 #### `false` (default):
2302 let lorem = 0 .. 10;
2303 let ipsum = 0 ..= 10;
2322 ## `struct_field_align_threshold`
2324 The maximum diff of width between struct fields to be aligned with each other.
2326 - **Default value** : 0
2327 - **Possible values**: any non-negative integer
2328 - **Stable**: No (tracking issue: #3371)
2350 ## `struct_lit_single_line`
2352 Put small struct literals on a single line
2354 - **Default value**: `true`
2355 - **Possible values**: `true`, `false`
2356 - **Stable**: No (tracking issue: #3357)
2358 #### `true` (default):
2362 let lorem = Lorem { foo: bar, baz: ofo };
2377 See also: [`indent_style`](#indent_style).
2379 ## `struct_lit_width`
2381 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`.
2383 - **Default value**: `18`
2384 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2387 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.
2389 See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2391 ## `struct_variant_width`
2393 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`.
2395 - **Default value**: `35`
2396 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2399 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.
2401 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2405 Number of spaces per tab
2407 - **Default value**: `4`
2408 - **Possible values**: any positive integer
2415 let ipsum = dolor();
2417 "amet consectetur adipiscing elit amet",
2418 "consectetur adipiscing elit amet consectetur.",
2427 let ipsum = dolor();
2429 "amet consectetur adipiscing elit amet",
2430 "consectetur adipiscing elit amet consectetur.",
2435 See also: [`hard_tabs`](#hard_tabs).
2440 How to handle trailing commas for lists
2442 - **Default value**: `"Vertical"`
2443 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
2444 - **Stable**: No (tracking issue: #3379)
2446 #### `"Vertical"` (default):
2450 let Lorem { ipsum, dolor, sit } = amet;
2466 let Lorem { ipsum, dolor, sit, } = amet;
2482 let Lorem { ipsum, dolor, sit } = amet;
2494 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2496 ## `trailing_semicolon`
2498 Add trailing semicolon after break, continue and return
2500 - **Default value**: `true`
2501 - **Possible values**: `true`, `false`
2502 - **Stable**: No (tracking issue: #3378)
2504 #### `true` (default):
2518 ## `type_punctuation_density`
2520 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2522 - **Default value**: `"Wide"`
2523 - **Possible values**: `"Compressed"`, `"Wide"`
2524 - **Stable**: No (tracking issue: #3364)
2526 #### `"Wide"` (default):
2529 fn lorem<Ipsum: Dolor + Sit = Amet>() {
2534 #### `"Compressed"`:
2537 fn lorem<Ipsum: Dolor+Sit=Amet>() {
2542 ## `unstable_features`
2544 Enable unstable features on the unstable channel.
2546 - **Default value**: `false`
2547 - **Possible values**: `true`, `false`
2548 - **Stable**: No (tracking issue: #3387)
2550 ## `use_field_init_shorthand`
2552 Use field initialize shorthand if possible.
2554 - **Default value**: `false`
2555 - **Possible values**: `true`, `false`
2558 #### `false` (default):
2571 let a = Foo { x, y, z };
2572 let b = Foo { x: x, y: y, z: z };
2589 let a = Foo { x, y, z };
2593 ## `use_small_heuristics`
2595 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.
2597 Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
2599 - **Default value**: `"Default"`
2600 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
2603 #### `Default` (default):
2604 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`.
2607 * [`fn_call_width`](#fn_call_width) - `60%`
2608 * [`attr_fn_like_width`](#attr_fn_like_width) - `70%`
2609 * [`struct_lit_width`](#struct_lit_width) - `18%`
2610 * [`struct_variant_width`](#struct_variant_width) - `35%`
2611 * [`array_width`](#array_width) - `60%`
2612 * [`chain_width`](#chain_width) - `60%`
2613 * [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%`
2615 For example when `max_width` is set to `100`, the width settings are:
2616 * `fn_call_width=60`
2617 * `attr_fn_like_width=70`
2618 * `struct_lit_width=18`
2619 * `struct_variant_width=35`
2622 * `single_line_if_else_max_width=50`
2624 and when `max_width` is set to `200`:
2625 * `fn_call_width=120`
2626 * `attr_fn_like_width=140`
2627 * `struct_lit_width=36`
2628 * `struct_variant_width=70`
2631 * `single_line_if_else_max_width=100`
2637 Sit { amet: Consectetur, adipiscing: Elit },
2655 let lorem = Lorem { ipsum: dolor };
2657 let lorem = if ipsum { dolor } else { sit };
2662 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.
2675 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2682 let lorem = if ipsum {
2691 When `use_small_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2693 So if `max_width` is set to `200`, then all the width settings are also set to `200`.
2694 * `fn_call_width=200`
2695 * `attr_fn_like_width=200`
2696 * `struct_lit_width=200`
2697 * `struct_variant_width=200`
2700 * `single_line_if_else_max_width=200`
2706 Sit { amet: Consectetur, adipiscing: Elit },
2710 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2712 let lorem = Lorem { ipsum: dolor, sit: amet };
2714 let lorem = if ipsum { dolor } else { sit };
2720 * [`max_width`](#max_width)
2721 * [`fn_call_width`](#fn_call_width)
2722 * [`attr_fn_like_width`](#attr_fn_like_width)
2723 * [`struct_lit_width`](#struct_lit_width)
2724 * [`struct_variant_width`](#struct_variant_width)
2725 * [`array_width`](#array_width)
2726 * [`chain_width`](#chain_width)
2727 * [`single_line_if_else_max_width`](#single_line_if_else_max_width)
2729 ## `use_try_shorthand`
2731 Replace uses of the try! macro by the ? shorthand
2733 - **Default value**: `false`
2734 - **Possible values**: `true`, `false`
2737 #### `false` (default):
2741 let lorem = ipsum.map(|dolor| dolor.sit())?;
2743 let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2751 let lorem = ipsum.map(|dolor| dolor.sit())?;
2757 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2758 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2761 - **Default value**: `One`
2762 - **Possible values**: `One`, `Two`
2763 - **Stable**: No (tracking issue: #3383)
2771 ## `where_single_line`
2773 Forces the `where` clause to be laid out on a single line.
2775 - **Default value**: `false`
2776 - **Possible values**: `true`, `false`
2777 - **Stable**: No (tracking issue: #3359)
2779 #### `false` (default):
2794 where Option<T>: Ipsum
2800 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2805 Break comments to fit on the line
2807 - **Default value**: `false`
2808 - **Possible values**: `true`, `false`
2809 - **Stable**: No (tracking issue: #3347)
2811 #### `false` (default):
2814 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2815 // sed do eiusmod tempor incididunt ut labore et dolore
2816 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2817 // exercitation ullamco laboris nisi ut aliquip ex ea
2818 // commodo consequat.
2820 // 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.
2826 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2827 // sed do eiusmod tempor incididunt ut labore et dolore
2828 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2829 // exercitation ullamco laboris nisi ut aliquip ex ea
2830 // commodo consequat.
2841 Internal option, use `--backup`
2843 ## `print_misformatted_file_names`
2845 Internal option, use `-l` or `--files-with-diff`