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_macro_matchers`
929 Format the metavariable matching patterns in macros.
931 - **Default value**: `false`
932 - **Possible values**: `true`, `false`
933 - **Stable**: No (tracking issue: #3354)
935 #### `false` (default):
939 ($a: ident : $b: ty) => {
942 ($a: ident $b: ident $c: ident) => {
952 ($a:ident : $b:ty) => {
955 ($a:ident $b:ident $c:ident) => {
961 See also [`format_macro_bodies`](#format_macro_bodies).
964 ## `format_macro_bodies`
966 Format the bodies of macros.
968 - **Default value**: `true`
969 - **Possible values**: `true`, `false`
970 - **Stable**: No (tracking issue: #3355)
972 #### `true` (default):
976 ($a: ident : $b: ty) => {
979 ($a: ident $b: ident $c: ident) => {
989 ($a: ident : $b: ty) => { $a(42): $b; };
990 ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
994 See also [`format_macro_matchers`](#format_macro_matchers).
999 Format string literals where necessary
1001 - **Default value**: `false`
1002 - **Possible values**: `true`, `false`
1003 - **Stable**: No (tracking issue: #3353)
1005 #### `false` (default):
1009 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
1017 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
1018 consectetur adipiscing";
1022 See also [`max_width`](#max_width).
1026 Use tab characters for indentation, spaces for alignment
1028 - **Default value**: `false`
1029 - **Possible values**: `true`, `false`
1032 #### `false` (default):
1035 fn lorem() -> usize {
1036 42 // spaces before 42
1043 fn lorem() -> usize {
1044 42 // tabs before 42
1048 See also: [`tab_spaces`](#tab_spaces).
1051 ## `hide_parse_errors`
1053 Do not show parse errors if the parser failed to parse files.
1055 - **Default value**: `false`
1056 - **Possible values**: `true`, `false`
1057 - **Stable**: No (tracking issue: #3390)
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.
1064 - **Default value**: format every file
1065 - **Possible values**: See an example below
1066 - **Stable**: No (tracking issue: #3395)
1070 If you want to ignore specific files, put the following to your config file:
1079 If you want to ignore every file under `examples/`, put the following to your config file:
1087 If you want to ignore every file under the directory where you put your rustfmt.toml:
1095 Indent style of imports
1097 - **Default Value**: `"Block"`
1098 - **Possible values**: `"Block"`, `"Visual"`
1099 - **Stable**: No (tracking issue: #3360)
1101 #### `"Block"` (default):
1105 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1106 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1113 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1114 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1117 See also: [`imports_layout`](#imports_layout).
1121 Item layout inside a imports block
1123 - **Default value**: "Mixed"
1124 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1125 - **Stable**: No (tracking issue: #3361)
1127 #### `"Mixed"` (default):
1130 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1133 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1134 eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1138 #### `"Horizontal"`:
1140 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1143 use foo::{xxx, yyy, zzz};
1145 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1148 #### `"HorizontalVertical"`:
1151 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1184 Indent on expressions or items.
1186 - **Default value**: `"Block"`
1187 - **Possible values**: `"Block"`, `"Visual"`
1188 - **Stable**: No (tracking issue: #3346)
1192 #### `"Block"` (default):
1212 let lorem = vec!["ipsum",
1224 #### `"Block"` (default):
1232 && dolor_consectetur
1234 && lorem_consectetur
1249 && dolor_consectetur
1251 && lorem_consectetur
1258 See also: [`control_brace_style`](#control_brace_style).
1260 ### Function arguments
1262 #### `"Block"` (default):
1267 fn lorem(ipsum: usize) {}
1287 fn lorem(ipsum: usize) {}
1289 fn lorem(ipsum: usize,
1302 #### `"Block"` (default):
1336 #### `"Block"` (default):
1344 Adipiscing: Eq = usize,
1345 Consectetur: Eq = usize,
1352 adipiscing: Adipiscing,
1353 consectetur: Consectetur,
1363 fn lorem<Ipsum: Eq = usize,
1367 Adipiscing: Eq = usize,
1368 Consectetur: Eq = usize,
1374 adipiscing: Adipiscing,
1375 consectetur: Consectetur,
1384 #### `"Block"` (default):
1399 let lorem = Lorem { ipsum: dolor,
1404 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
1406 ### Where predicates
1408 #### `"Block"` (default):
1411 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1425 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1435 ## `inline_attribute_width`
1437 Write an item and its attribute on the same line if their combined width is below a threshold
1439 - **Default value**: 0
1440 - **Possible values**: any positive integer
1441 - **Stable**: No (tracking issue: #3343)
1447 #[cfg(feature = "alloc")]
1453 #[cfg(feature = "alloc")] use core::slice;
1456 ## `license_template_path`
1458 Check whether beginnings of files match a license template.
1460 - **Default value**: `""`
1461 - **Possible values**: path to a license template file
1462 - **Stable**: No (tracking issue: #3352)
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.:
1471 // Copyright {\d+} The Rust Project Developers.
1474 `\{`, `\}` and `\\` match literal braces / backslashes.
1476 ## `match_arm_blocks`
1478 Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.
1480 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.
1482 - **Default value**: `true`
1483 - **Possible values**: `true`, `false`
1484 - **Stable**: No (tracking issue: #3373)
1486 #### `true` (default):
1492 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1494 dolor => println!("{}", sit),
1496 "foooooooooooooooooooooooo",
1497 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1498 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1499 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1511 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1512 ipsum => println!("{}", sit),
1514 "foooooooooooooooooooooooo",
1515 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1516 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1517 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1523 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1525 ## `match_arm_leading_pipes`
1527 Controls whether to include a leading pipe on match arms
1529 - **Default value**: `Never`
1530 - **Possible values**: `Always`, `Never`, `Preserve`
1533 #### `Never` (default):
1535 // Leading pipes are removed from this:
1538 // | "foo" | "bar" => {}
1540 // | "something relatively long"
1541 // | "something really really really realllllllllllllly long" => println!("x"),
1542 // | "qux" => println!("y"),
1552 | "something relatively long"
1553 | "something really really really realllllllllllllly long" => println!("x"),
1554 "qux" => println!("y"),
1562 // Leading pipes are emitted on all arms of this:
1565 // "foo" | "bar" => {}
1567 // | "something relatively long"
1568 // | "something really really really realllllllllllllly long" => println!("x"),
1569 // "qux" => println!("y"),
1577 | "foo" | "bar" => {}
1579 | "something relatively long"
1580 | "something really really really realllllllllllllly long" => println!("x"),
1581 | "qux" => println!("y"),
1591 | "foo" | "bar" => {}
1593 | "something relatively long"
1594 | "something really really really realllllllllllllly long" => println!("x"),
1595 | "qux" => println!("y"),
1607 ## `match_block_trailing_comma`
1609 Put a trailing comma after a block based match arm (non-block arms are not affected)
1611 - **Default value**: `false`
1612 - **Possible values**: `true`, `false`
1613 - **Stable**: No (tracking issue: #3380)
1615 #### `false` (default):
1623 Lorem::Dolor => println!("dolor"),
1636 Lorem::Dolor => println!("dolor"),
1641 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1645 Maximum width of each line
1647 - **Default value**: `100`
1648 - **Possible values**: any positive integer
1651 See also [`error_on_line_overflow`](#error_on_line_overflow).
1655 Merge multiple derives into a single one.
1657 - **Default value**: `true`
1658 - **Possible values**: `true`, `false`
1661 #### `true` (default):
1664 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1671 #[derive(Eq, PartialEq)]
1673 #[derive(Copy, Clone)]
1677 ## `imports_granularity`
1679 How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
1681 - **Default value**: `Preserve`
1682 - **Possible values**: `Preserve`, `Crate`, `Module`, `Item`
1685 #### `Preserve` (default):
1687 Do not change the granularity of any imports and preserve the original structure written by the developer.
1692 use foo::{a, c, d::e};
1698 Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements.
1712 Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements.
1723 Flatten imports so that each has its own `use` statement.
1738 This option is deprecated. Use `imports_granularity = "Crate"` instead.
1740 - **Default value**: `false`
1741 - **Possible values**: `true`, `false`
1743 #### `false` (default):
1754 use foo::{a, b, c, d, e, f, g};
1760 Unix or Windows line endings
1762 - **Default value**: `"Auto"`
1763 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1766 #### `Auto` (default):
1768 The newline style is detected automatically on a per-file basis. Files
1769 with mixed line endings will be converted to the first detected line
1774 Line endings will be converted to `\r\n` on Windows and `\n` on all
1779 Line endings will be converted to `\n`.
1783 Line endings will be converted to `\r\n`.
1785 ## `normalize_comments`
1787 Convert /* */ comments to // comments where possible
1789 - **Default value**: `false`
1790 - **Possible values**: `true`, `false`
1791 - **Stable**: No (tracking issue: #3350)
1793 #### `false` (default):
1797 fn dolor() -> usize {}
1800 fn adipiscing() -> usize {}
1807 fn dolor() -> usize {}
1810 fn adipiscing() -> usize {}
1813 ## `normalize_doc_attributes`
1815 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1817 - **Default value**: `false`
1818 - **Possible values**: `true`, `false`
1819 - **Stable**: No (tracking issue: #3351)
1821 #### `false` (default):
1824 #![doc = "Example documentation"]
1826 #[doc = "Example item documentation"]
1833 //! Example documentation
1835 /// Example item documentation
1839 ## `overflow_delimited_expr`
1841 When structs, slices, arrays, and block/array-like macros are used as the last
1842 argument in an expression list, allow them to overflow (like blocks/closures)
1843 instead of being indented on a new line.
1845 - **Default value**: `false`
1846 - **Possible values**: `true`, `false`
1847 - **Stable**: No (tracking issue: #3370)
1849 #### `false` (default):
1922 ## `remove_nested_parens`
1924 Remove nested parens.
1926 - **Default value**: `true`,
1927 - **Possible values**: `true`, `false`
1931 #### `true` (default):
1946 ## `reorder_impl_items`
1948 Reorder impl items. `type` and `const` are put first, then macros and methods.
1950 - **Default value**: `false`
1951 - **Possible values**: `true`, `false`
1952 - **Stable**: No (tracking issue: #3363)
1954 #### `false` (default)
1959 impl Iterator for Dummy {
1960 fn next(&mut self) -> Option<Self::Item> {
1973 impl Iterator for Dummy {
1976 fn next(&mut self) -> Option<Self::Item> {
1982 ## `reorder_imports`
1984 Reorder import and extern crate statements alphabetically in groups (a group is
1985 separated by a newline).
1987 - **Default value**: `true`
1988 - **Possible values**: `true`, `false`
1991 #### `true` (default):
2011 Controls the strategy for how imports are grouped together.
2013 - **Default value**: `Preserve`
2014 - **Possible values**: `Preserve`, `StdExternalCrate`
2017 #### `Preserve` (default):
2019 Preserve the source file's import groups.
2022 use super::update::convert_publish_payload;
2025 use alloc::alloc::Layout;
2026 use juniper::{FieldError, FieldResult};
2031 use broker::database::PooledConnection;
2033 use super::schema::{Context, Payload};
2034 use crate::models::Event;
2038 #### `StdExternalCrate`:
2040 Discard existing import groups, and create three groups for:
2041 1. `std`, `core` and `alloc`,
2043 3. `self`, `super` and `crate` imports.
2046 use alloc::alloc::Layout;
2050 use broker::database::PooledConnection;
2052 use juniper::{FieldError, FieldResult};
2055 use super::schema::{Context, Payload};
2056 use super::update::convert_publish_payload;
2057 use crate::models::Event;
2060 ## `reorder_modules`
2062 Reorder `mod` declarations alphabetically in group.
2064 - **Default value**: `true`
2065 - **Possible values**: `true`, `false`
2068 #### `true` (default)
2092 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
2093 of the original source code.
2097 Report `FIXME` items in comments.
2099 - **Default value**: `"Never"`
2100 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2101 - **Stable**: No (tracking issue: #3394)
2103 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
2104 it contains a `#X` (with `X` being a number) in parentheses following the
2105 `FIXME`, `"Unnumbered"` will ignore it.
2107 See also [`report_todo`](#report_todo).
2112 Report `TODO` items in comments.
2114 - **Default value**: `"Never"`
2115 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2116 - **Stable**: No (tracking issue: #3393)
2118 Warns about any comments containing `TODO` in them when set to `"Always"`. If
2119 it contains a `#X` (with `X` being a number) in parentheses following the
2120 `TODO`, `"Unnumbered"` will ignore it.
2122 See also [`report_fixme`](#report_fixme).
2124 ## `required_version`
2126 Require a specific version of rustfmt. If you want to make sure that the
2127 specific version of rustfmt is used in your CI, use this option.
2129 - **Default value**: `CARGO_PKG_VERSION`
2130 - **Possible values**: any published version (e.g. `"0.3.8"`)
2131 - **Stable**: No (tracking issue: #3386)
2135 Don't reformat out of line modules
2137 - **Default value**: `false`
2138 - **Possible values**: `true`, `false`
2139 - **Stable**: No (tracking issue: #3389)
2141 ## `single_line_if_else_max_width`
2143 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`.
2145 - **Default value**: `50`
2146 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2149 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.
2151 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2153 ## `space_after_colon`
2155 Leave a space after the colon.
2157 - **Default value**: `true`
2158 - **Possible values**: `true`, `false`
2159 - **Stable**: No (tracking issue: #3366)
2161 #### `true` (default):
2164 fn lorem<T: Eq>(t: T) {
2165 let lorem: Dolor = Lorem {
2175 fn lorem<T:Eq>(t:T) {
2176 let lorem:Dolor = Lorem {
2183 See also: [`space_before_colon`](#space_before_colon).
2185 ## `space_before_colon`
2187 Leave a space before the colon.
2189 - **Default value**: `false`
2190 - **Possible values**: `true`, `false`
2191 - **Stable**: No (tracking issue: #3365)
2193 #### `false` (default):
2196 fn lorem<T: Eq>(t: T) {
2197 let lorem: Dolor = Lorem {
2207 fn lorem<T : Eq>(t : T) {
2208 let lorem : Dolor = Lorem {
2215 See also: [`space_after_colon`](#space_after_colon).
2217 ## `spaces_around_ranges`
2219 Put spaces around the .., ..=, and ... range operators
2221 - **Default value**: `false`
2222 - **Possible values**: `true`, `false`
2223 - **Stable**: No (tracking issue: #3367)
2225 #### `false` (default):
2253 let lorem = 0 .. 10;
2254 let ipsum = 0 ..= 10;
2273 ## `struct_field_align_threshold`
2275 The maximum diff of width between struct fields to be aligned with each other.
2277 - **Default value** : 0
2278 - **Possible values**: any non-negative integer
2279 - **Stable**: No (tracking issue: #3371)
2301 ## `struct_lit_single_line`
2303 Put small struct literals on a single line
2305 - **Default value**: `true`
2306 - **Possible values**: `true`, `false`
2307 - **Stable**: No (tracking issue: #3357)
2309 #### `true` (default):
2313 let lorem = Lorem { foo: bar, baz: ofo };
2328 See also: [`indent_style`](#indent_style).
2330 ## `struct_lit_width`
2332 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`.
2334 - **Default value**: `18`
2335 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2338 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.
2340 See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2342 ## `struct_variant_width`
2344 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`.
2346 - **Default value**: `35`
2347 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2350 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.
2352 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2356 Number of spaces per tab
2358 - **Default value**: `4`
2359 - **Possible values**: any positive integer
2366 let ipsum = dolor();
2368 "amet consectetur adipiscing elit amet",
2369 "consectetur adipiscing elit amet consectetur.",
2378 let ipsum = dolor();
2380 "amet consectetur adipiscing elit amet",
2381 "consectetur adipiscing elit amet consectetur.",
2386 See also: [`hard_tabs`](#hard_tabs).
2391 How to handle trailing commas for lists
2393 - **Default value**: `"Vertical"`
2394 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
2395 - **Stable**: No (tracking issue: #3379)
2397 #### `"Vertical"` (default):
2401 let Lorem { ipsum, dolor, sit } = amet;
2417 let Lorem { ipsum, dolor, sit, } = amet;
2433 let Lorem { ipsum, dolor, sit } = amet;
2445 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2447 ## `trailing_semicolon`
2449 Add trailing semicolon after break, continue and return
2451 - **Default value**: `true`
2452 - **Possible values**: `true`, `false`
2453 - **Stable**: No (tracking issue: #3378)
2455 #### `true` (default):
2469 ## `type_punctuation_density`
2471 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2473 - **Default value**: `"Wide"`
2474 - **Possible values**: `"Compressed"`, `"Wide"`
2475 - **Stable**: No (tracking issue: #3364)
2477 #### `"Wide"` (default):
2480 fn lorem<Ipsum: Dolor + Sit = Amet>() {
2485 #### `"Compressed"`:
2488 fn lorem<Ipsum: Dolor+Sit=Amet>() {
2493 ## `unstable_features`
2495 Enable unstable features on the unstable channel.
2497 - **Default value**: `false`
2498 - **Possible values**: `true`, `false`
2499 - **Stable**: No (tracking issue: #3387)
2501 ## `use_field_init_shorthand`
2503 Use field initialize shorthand if possible.
2505 - **Default value**: `false`
2506 - **Possible values**: `true`, `false`
2509 #### `false` (default):
2522 let a = Foo { x: x, y: y, z: z };
2539 let a = Foo { x, y, z };
2543 ## `use_small_heuristics`
2545 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.
2547 Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
2549 - **Default value**: `"Default"`
2550 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
2553 #### `Default` (default):
2554 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`.
2557 * [`fn_call_width`](#fn_call_width) - `60%`
2558 * [`attr_fn_like_width`](#attr_fn_like_width) - `70%`
2559 * [`struct_lit_width`](#struct_lit_width) - `18%`
2560 * [`struct_variant_width`](#struct_variant_width) - `35%`
2561 * [`array_width`](#array_width) - `60%`
2562 * [`chain_width`](#chain_width) - `60%`
2563 * [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%`
2565 For example when `max_width` is set to `100`, the width settings are:
2566 * `fn_call_width=60`
2567 * `attr_fn_like_width=70`
2568 * `struct_lit_width=18`
2569 * `struct_variant_width=35`
2572 * `single_line_if_else_max_width=50`
2574 and when `max_width` is set to `200`:
2575 * `fn_call_width=120`
2576 * `attr_fn_like_width=140`
2577 * `struct_lit_width=36`
2578 * `struct_variant_width=70`
2581 * `single_line_if_else_max_width=100`
2587 Sit { amet: Consectetur, adipiscing: Elit },
2605 let lorem = Lorem { ipsum: dolor };
2607 let lorem = if ipsum { dolor } else { sit };
2612 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.
2625 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2632 let lorem = if ipsum {
2641 When `use_small_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2643 So if `max_width` is set to `200`, then all the width settings are also set to `200`.
2644 * `fn_call_width=200`
2645 * `attr_fn_like_width=200`
2646 * `struct_lit_width=200`
2647 * `struct_variant_width=200`
2650 * `single_line_if_else_max_width=200`
2656 Sit { amet: Consectetur, adipiscing: Elit },
2660 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2662 let lorem = Lorem { ipsum: dolor, sit: amet };
2664 let lorem = if ipsum { dolor } else { sit };
2670 * [`max_width`](#max_width)
2671 * [`fn_call_width`](#fn_call_width)
2672 * [`attr_fn_like_width`](#attr_fn_like_width)
2673 * [`struct_lit_width`](#struct_lit_width)
2674 * [`struct_variant_width`](#struct_variant_width)
2675 * [`array_width`](#array_width)
2676 * [`chain_width`](#chain_width)
2677 * [`single_line_if_else_max_width`](#single_line_if_else_max_width)
2679 ## `use_try_shorthand`
2681 Replace uses of the try! macro by the ? shorthand
2683 - **Default value**: `false`
2684 - **Possible values**: `true`, `false`
2687 #### `false` (default):
2691 let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2699 let lorem = ipsum.map(|dolor| dolor.sit())?;
2705 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2706 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2709 - **Default value**: `One`
2710 - **Possible values**: `One`, `Two`
2711 - **Stable**: No (tracking issue: #3383)
2719 ## `where_single_line`
2721 Forces the `where` clause to be laid out on a single line.
2723 - **Default value**: `false`
2724 - **Possible values**: `true`, `false`
2725 - **Stable**: No (tracking issue: #3359)
2727 #### `false` (default):
2742 where Option<T>: Ipsum
2748 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2753 Break comments to fit on the line
2755 - **Default value**: `false`
2756 - **Possible values**: `true`, `false`
2757 - **Stable**: No (tracking issue: #3347)
2759 #### `false` (default):
2762 // 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.
2768 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2769 // sed do eiusmod tempor incididunt ut labore et dolore
2770 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2771 // exercitation ullamco laboris nisi ut aliquip ex ea
2772 // commodo consequat.
2783 Internal option, use `--backup`
2785 ## `print_misformatted_file_names`
2787 Internal option, use `-l` or `--files-with-diff`