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:
23 Where to put a binary operator when a binary expression goes multiline.
25 - **Default value**: `"Front"`
26 - **Possible values**: `"Front"`, `"Back"`
27 - **Stable**: No (tracking issue: #3368)
29 #### `"Front"` (default):
33 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
34 || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
36 let sum = 123456789012345678901234567890
37 + 123456789012345678901234567890
38 + 123456789012345678901234567890;
40 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
41 ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
49 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
50 barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
52 let sum = 123456789012345678901234567890 +
53 123456789012345678901234567890 +
54 123456789012345678901234567890;
56 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
57 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
61 ## `blank_lines_lower_bound`
63 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
64 them, additional blank lines are inserted.
66 - **Default value**: `0`
67 - **Possible values**: *unsigned integer*
68 - **Stable**: No (tracking issue: #3382)
71 Original Code (rustfmt will not change it with the default value of `0`):
101 ## `blank_lines_upper_bound`
103 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
104 lines are found, they are trimmed down to match this integer.
106 - **Default value**: `1`
107 - **Possible values**: any non-negative integer
108 - **Stable**: No (tracking issue: #3381)
158 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
162 Brace style for items
164 - **Default value**: `"SameLineWhere"`
165 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
166 - **Stable**: No (tracking issue: #3376)
170 #### `"SameLineWhere"` (default):
177 fn lorem(ipsum: usize) {
181 fn lorem<T>(ipsum: T)
183 T: Add + Sub + Mul + Div,
189 #### `"AlwaysNextLine"`:
197 fn lorem(ipsum: usize)
202 fn lorem<T>(ipsum: T)
204 T: Add + Sub + Mul + Div,
210 #### `"PreferSameLine"`:
217 fn lorem(ipsum: usize) {
221 fn lorem<T>(ipsum: T)
223 T: Add + Sub + Mul + Div, {
228 ### Structs and enums
230 #### `"SameLineWhere"` (default):
245 #### `"AlwaysNextLine"`:
261 #### `"PreferSameLine"`:
278 Whether to use colored output or not.
280 - **Default value**: `"Auto"`
281 - **Possible values**: "Auto", "Always", "Never"
282 - **Stable**: No (tracking issue: #3385)
284 ## `combine_control_expr`
286 Combine control expressions with function calls.
288 - **Default value**: `true`
289 - **Possible values**: `true`, `false`
290 - **Stable**: No (tracking issue: #3369)
292 #### `true` (default):
304 foo!(if let Some(..) = x {
317 foo!(while let Some(..) = x {
351 if let Some(..) = x {
368 while let Some(..) = x {
394 Maximum length of comments. No effect unless`wrap_comments = true`.
396 - **Default value**: `80`
397 - **Possible values**: any positive integer
398 - **Stable**: No (tracking issue: #3349)
400 **Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
402 #### `80` (default; comments shorter than `comment_width`):
404 // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
407 #### `60` (comments longer than `comment_width`):
409 // Lorem ipsum dolor sit amet,
410 // consectetur adipiscing elit.
413 See also [`wrap_comments`](#wrap_comments).
415 ## `condense_wildcard_suffixes`
417 Replace strings of _ wildcards by a single .. in tuple patterns
419 - **Default value**: `false`
420 - **Possible values**: `true`, `false`
421 - **Stable**: No (tracking issue: #3384)
423 #### `false` (default):
427 let (lorem, ipsum, _, _) = (1, 2, 3, 4);
428 let (lorem, ipsum, ..) = (1, 2, 3, 4);
436 let (lorem, ipsum, ..) = (1, 2, 3, 4);
440 ## `control_brace_style`
442 Brace style for control flow constructs
444 - **Default value**: `"AlwaysSameLine"`
445 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
446 - **Stable**: No (tracking issue: #3377)
448 #### `"AlwaysSameLine"` (default):
460 #### `"AlwaysNextLine"`:
475 #### `"ClosingNextLine"`:
488 ## `disable_all_formatting`
490 Don't reformat anything
492 - **Default value**: `false`
493 - **Possible values**: `true`, `false`
494 - **Stable**: No (tracking issue: #3388)
498 Specifies which edition is used by the parser.
500 - **Default value**: `"2015"`
501 - **Possible values**: `"2015"`, `"2018"`, `"2021"`
504 Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
505 through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
512 ## `empty_item_single_line`
514 Put empty-body functions and impls on a single line
516 - **Default value**: `true`
517 - **Possible values**: `true`, `false`
518 - **Stable**: No (tracking issue: #3356)
520 #### `true` (default):
538 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
541 ## `enum_discrim_align_threshold`
543 The maximum length of enum variant having discriminant, that gets vertically aligned with others.
544 Variants without discriminants would be ignored for the purpose of alignment.
546 Note that this is not how much whitespace is inserted, but instead the longest variant name that
547 doesn't get ignored when aligning.
549 - **Default value** : 0
550 - **Possible values**: any positive integer
551 - **Stable**: No (tracking issue: #3372)
559 RandomLongVariantGoesHere = 10,
564 VeryLongVariantNameHereA = 0,
565 VeryLongVariantNameHereBb = 1,
566 VeryLongVariantNameHereCcc = 2,
576 RandomLongVariantGoesHere = 10,
581 VeryLongVariantNameHereA = 0,
582 VeryLongVariantNameHereBb = 1,
583 VeryLongVariantNameHereCcc = 2,
588 ## `error_on_line_overflow`
590 Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
591 literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
592 refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
593 using a shorter name.
595 - **Default value**: `false`
596 - **Possible values**: `true`, `false`
597 - **Stable**: No (tracking issue: #3391)
599 See also [`max_width`](#max_width).
601 ## `error_on_unformatted`
603 Error if unable to get comments or string literals within `max_width`, or they are left with
604 trailing whitespaces.
606 - **Default value**: `false`
607 - **Possible values**: `true`, `false`
608 - **Stable**: No (tracking issue: #3392)
612 Control the layout of arguments in a function
614 - **Default value**: `"Tall"`
615 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
618 #### `"Tall"` (default):
622 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
624 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
633 consectetur: Consectetur,
634 adipiscing: Adipiscing,
643 consectetur: Consectetur,
644 adipiscing: Adipiscing,
656 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
658 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
663 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
664 adipiscing: Adipiscing, elit: Elit,
668 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
669 adipiscing: Adipiscing, elit: Elit,
701 consectetur: Consectetur,
702 adipiscing: Adipiscing,
711 consectetur: Consectetur,
712 adipiscing: Adipiscing,
723 Put single-expression functions on a single line
725 - **Default value**: `false`
726 - **Possible values**: `true`, `false`
727 - **Stable**: No (tracking issue: #3358)
729 #### `false` (default):
732 fn lorem() -> usize {
736 fn lorem() -> usize {
745 fn lorem() -> usize { 42 }
747 fn lorem() -> usize {
753 See also [`control_brace_style`](#control_brace_style).
756 ## `force_explicit_abi`
758 Always print the abi for extern items
760 - **Default value**: `true`
761 - **Possible values**: `true`, `false`
764 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
766 #### `true` (default):
770 pub static lorem: c_int;
778 pub static lorem: c_int;
782 ## `force_multiline_blocks`
784 Force multiline closure and match arm bodies to be wrapped in a block
786 - **Default value**: `false`
787 - **Possible values**: `false`, `true`
788 - **Stable**: No (tracking issue: #3374)
790 #### `false` (default):
794 result.and_then(|maybe_value| match maybe_value {
796 Some(value) => bar(),
801 println!("Hello World");
803 Some(dolor) => foo(),
812 result.and_then(|maybe_value| {
815 Some(value) => bar(),
822 println!("Hello World");
825 Some(dolor) => foo(),
831 ## `format_code_in_doc_comments`
833 Format code snippet included in doc comments.
835 - **Default value**: `false`
836 - **Possible values**: `true`, `false`
837 - **Stable**: No (tracking issue: #3348)
839 #### `false` (default):
842 /// Adds one to the number given.
853 /// # fn add_one(x: i32) -> i32 {
857 fn add_one(x: i32) -> i32 {
865 /// Adds one to the number given.
872 /// assert_eq!(6, add_one(5));
873 /// # fn add_one(x: i32) -> i32 {
877 fn add_one(x: i32) -> i32 {
882 ## `format_macro_matchers`
884 Format the metavariable matching patterns in macros.
886 - **Default value**: `false`
887 - **Possible values**: `true`, `false`
888 - **Stable**: No (tracking issue: #3354)
890 #### `false` (default):
894 ($a: ident : $b: ty) => {
897 ($a: ident $b: ident $c: ident) => {
907 ($a:ident : $b:ty) => {
910 ($a:ident $b:ident $c:ident) => {
916 See also [`format_macro_bodies`](#format_macro_bodies).
919 ## `format_macro_bodies`
921 Format the bodies of macros.
923 - **Default value**: `true`
924 - **Possible values**: `true`, `false`
925 - **Stable**: No (tracking issue: #3355)
927 #### `true` (default):
931 ($a: ident : $b: ty) => {
934 ($a: ident $b: ident $c: ident) => {
944 ($a: ident : $b: ty) => { $a(42): $b; };
945 ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
949 See also [`format_macro_matchers`](#format_macro_matchers).
954 Format string literals where necessary
956 - **Default value**: `false`
957 - **Possible values**: `true`, `false`
958 - **Stable**: No (tracking issue: #3353)
960 #### `false` (default):
964 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
972 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
973 consectetur adipiscing";
977 See also [`max_width`](#max_width).
981 Use tab characters for indentation, spaces for alignment
983 - **Default value**: `false`
984 - **Possible values**: `true`, `false`
987 #### `false` (default):
990 fn lorem() -> usize {
991 42 // spaces before 42
998 fn lorem() -> usize {
1003 See also: [`tab_spaces`](#tab_spaces).
1006 ## `hide_parse_errors`
1008 Do not show parse errors if the parser failed to parse files.
1010 - **Default value**: `false`
1011 - **Possible values**: `true`, `false`
1012 - **Stable**: No (tracking issue: #3390)
1016 Skip formatting files and directories that match the specified pattern.
1017 The pattern format is the same as [.gitignore](https://git-scm.com/docs/gitignore#_pattern_format). Be sure to use Unix/forwardslash `/` style paths. This path style will work on all platforms. Windows style paths with backslashes `\` are not supported.
1019 - **Default value**: format every file
1020 - **Possible values**: See an example below
1021 - **Stable**: No (tracking issue: #3395)
1025 If you want to ignore specific files, put the following to your config file:
1034 If you want to ignore every file under `examples/`, put the following to your config file:
1042 If you want to ignore every file under the directory where you put your rustfmt.toml:
1050 Indent style of imports
1052 - **Default Value**: `"Block"`
1053 - **Possible values**: `"Block"`, `"Visual"`
1054 - **Stable**: No (tracking issue: #3360)
1056 #### `"Block"` (default):
1060 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1061 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1068 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1069 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1072 See also: [`imports_layout`](#imports_layout).
1076 Item layout inside a imports block
1078 - **Default value**: "Mixed"
1079 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1080 - **Stable**: No (tracking issue: #3361)
1082 #### `"Mixed"` (default):
1085 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1088 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1089 eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1093 #### `"Horizontal"`:
1095 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1098 use foo::{xxx, yyy, zzz};
1100 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1103 #### `"HorizontalVertical"`:
1106 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1139 Indent on expressions or items.
1141 - **Default value**: `"Block"`
1142 - **Possible values**: `"Block"`, `"Visual"`
1143 - **Stable**: No (tracking issue: #3346)
1147 #### `"Block"` (default):
1167 let lorem = vec!["ipsum",
1179 #### `"Block"` (default):
1187 && dolor_consectetur
1189 && lorem_consectetur
1204 && dolor_consectetur
1206 && lorem_consectetur
1213 See also: [`control_brace_style`](#control_brace_style).
1215 ### Function arguments
1217 #### `"Block"` (default):
1222 fn lorem(ipsum: usize) {}
1242 fn lorem(ipsum: usize) {}
1244 fn lorem(ipsum: usize,
1257 #### `"Block"` (default):
1291 #### `"Block"` (default):
1299 Adipiscing: Eq = usize,
1300 Consectetur: Eq = usize,
1307 adipiscing: Adipiscing,
1308 consectetur: Consectetur,
1318 fn lorem<Ipsum: Eq = usize,
1322 Adipiscing: Eq = usize,
1323 Consectetur: Eq = usize,
1329 adipiscing: Adipiscing,
1330 consectetur: Consectetur,
1339 #### `"Block"` (default):
1354 let lorem = Lorem { ipsum: dolor,
1359 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
1361 ### Where predicates
1363 #### `"Block"` (default):
1366 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1380 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1390 ## `inline_attribute_width`
1392 Write an item and its attribute on the same line if their combined width is below a threshold
1394 - **Default value**: 0
1395 - **Possible values**: any positive integer
1396 - **Stable**: No (tracking issue: #3343)
1402 #[cfg(feature = "alloc")]
1408 #[cfg(feature = "alloc")] use core::slice;
1411 ## `license_template_path`
1413 Check whether beginnings of files match a license template.
1415 - **Default value**: `""`
1416 - **Possible values**: path to a license template file
1417 - **Stable**: No (tracking issue: #3352)
1419 A license template is a plain text file which is matched literally against the
1420 beginning of each source file, except for `{}`-delimited blocks, which are
1421 matched as regular expressions. The following license template therefore
1422 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
1423 Copyright 2018 The Rust Project Developers.`, etc.:
1426 // Copyright {\d+} The Rust Project Developers.
1429 `\{`, `\}` and `\\` match literal braces / backslashes.
1431 ## `match_arm_blocks`
1433 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
1435 - **Default value**: `true`
1436 - **Possible values**: `true`, `false`
1437 - **Stable**: No (tracking issue: #3373)
1439 #### `true` (default):
1445 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1447 false => println!("{}", sit),
1458 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1459 false => println!("{}", sit),
1464 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1466 ## `match_arm_leading_pipes`
1468 Controls whether to include a leading pipe on match arms
1470 - **Default value**: `Never`
1471 - **Possible values**: `Always`, `Never`, `Preserve`
1474 #### `Never` (default):
1476 // Leading pipes are removed from this:
1479 // | "foo" | "bar" => {}
1481 // | "something relatively long"
1482 // | "something really really really realllllllllllllly long" => println!("x"),
1483 // | "qux" => println!("y"),
1493 | "something relatively long"
1494 | "something really really really realllllllllllllly long" => println!("x"),
1495 "qux" => println!("y"),
1503 // Leading pipes are emitted on all arms of this:
1506 // "foo" | "bar" => {}
1508 // | "something relatively long"
1509 // | "something really really really realllllllllllllly long" => println!("x"),
1510 // "qux" => println!("y"),
1518 | "foo" | "bar" => {}
1520 | "something relatively long"
1521 | "something really really really realllllllllllllly long" => println!("x"),
1522 | "qux" => println!("y"),
1532 | "foo" | "bar" => {}
1534 | "something relatively long"
1535 | "something really really really realllllllllllllly long" => println!("x"),
1536 | "qux" => println!("y"),
1548 ## `match_block_trailing_comma`
1550 Put a trailing comma after a block based match arm (non-block arms are not affected)
1552 - **Default value**: `false`
1553 - **Possible values**: `true`, `false`
1554 - **Stable**: No (tracking issue: #3380)
1556 #### `false` (default):
1564 Lorem::Dolor => println!("dolor"),
1577 Lorem::Dolor => println!("dolor"),
1582 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1586 Maximum width of each line
1588 - **Default value**: `100`
1589 - **Possible values**: any positive integer
1592 See also [`error_on_line_overflow`](#error_on_line_overflow).
1596 Merge multiple derives into a single one.
1598 - **Default value**: `true`
1599 - **Possible values**: `true`, `false`
1602 #### `true` (default):
1605 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1612 #[derive(Eq, PartialEq)]
1614 #[derive(Copy, Clone)]
1618 ## `imports_granularity`
1620 Merge together related imports based on their paths.
1622 - **Default value**: `Preserve`
1623 - **Possible values**: `Preserve`, `Crate`, `Module`
1626 #### `Preserve` (default):
1628 Do not perform any merging and preserve the original structure written by the developer.
1633 use foo::{a, c, d::e};
1639 Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements.
1653 Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements.
1664 This option is deprecated. Use `imports_granularity = "Crate"` instead.
1666 - **Default value**: `false`
1667 - **Possible values**: `true`, `false`
1669 #### `false` (default):
1680 use foo::{a, b, c, d, e, f, g};
1686 Unix or Windows line endings
1688 - **Default value**: `"Auto"`
1689 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1692 #### `Auto` (default):
1694 The newline style is detected automatically on a per-file basis. Files
1695 with mixed line endings will be converted to the first detected line
1700 Line endings will be converted to `\r\n` on Windows and `\n` on all
1705 Line endings will be converted to `\n`.
1709 Line endings will be converted to `\r\n`.
1711 ## `normalize_comments`
1713 Convert /* */ comments to // comments where possible
1715 - **Default value**: `false`
1716 - **Possible values**: `true`, `false`
1717 - **Stable**: No (tracking issue: #3350)
1719 #### `false` (default):
1723 fn dolor() -> usize {}
1726 fn adipiscing() -> usize {}
1733 fn dolor() -> usize {}
1736 fn adipiscing() -> usize {}
1739 ## `normalize_doc_attributes`
1741 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1743 - **Default value**: `false`
1744 - **Possible values**: `true`, `false`
1745 - **Stable**: No (tracking issue: #3351)
1747 #### `false` (default):
1750 #![doc = "Example documentation"]
1752 #[doc = "Example item documentation"]
1759 //! Example documentation
1761 /// Example item documentation
1765 ## `overflow_delimited_expr`
1767 When structs, slices, arrays, and block/array-like macros are used as the last
1768 argument in an expression list, allow them to overflow (like blocks/closures)
1769 instead of being indented on a new line.
1771 - **Default value**: `false`
1772 - **Possible values**: `true`, `false`
1773 - **Stable**: No (tracking issue: #3370)
1775 #### `false` (default):
1848 ## `remove_nested_parens`
1850 Remove nested parens.
1852 - **Default value**: `true`,
1853 - **Possible values**: `true`, `false`
1857 #### `true` (default):
1872 ## `reorder_impl_items`
1874 Reorder impl items. `type` and `const` are put first, then macros and methods.
1876 - **Default value**: `false`
1877 - **Possible values**: `true`, `false`
1878 - **Stable**: No (tracking issue: #3363)
1880 #### `false` (default)
1885 impl Iterator for Dummy {
1886 fn next(&mut self) -> Option<Self::Item> {
1899 impl Iterator for Dummy {
1902 fn next(&mut self) -> Option<Self::Item> {
1908 ## `reorder_imports`
1910 Reorder import and extern crate statements alphabetically in groups (a group is
1911 separated by a newline).
1913 - **Default value**: `true`
1914 - **Possible values**: `true`, `false`
1917 #### `true` (default):
1937 Controls the strategy for how imports are grouped together.
1939 - **Default value**: `Preserve`
1940 - **Possible values**: `Preserve`, `StdExternalCrate`
1943 #### `Preserve` (default):
1945 Preserve the source file's import groups.
1948 use super::update::convert_publish_payload;
1951 use alloc::alloc::Layout;
1952 use juniper::{FieldError, FieldResult};
1957 use broker::database::PooledConnection;
1959 use super::schema::{Context, Payload};
1960 use crate::models::Event;
1964 #### `StdExternalCrate`:
1966 Discard existing import groups, and create three groups for:
1967 1. `std`, `core` and `alloc`,
1969 3. `self`, `super` and `crate` imports.
1972 use alloc::alloc::Layout;
1976 use broker::database::PooledConnection;
1978 use juniper::{FieldError, FieldResult};
1981 use super::schema::{Context, Payload};
1982 use super::update::convert_publish_payload;
1983 use crate::models::Event;
1986 ## `reorder_modules`
1988 Reorder `mod` declarations alphabetically in group.
1990 - **Default value**: `true`
1991 - **Possible values**: `true`, `false`
1994 #### `true` (default)
2018 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
2019 of the original source code.
2023 Report `FIXME` items in comments.
2025 - **Default value**: `"Never"`
2026 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2027 - **Stable**: No (tracking issue: #3394)
2029 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
2030 it contains a `#X` (with `X` being a number) in parentheses following the
2031 `FIXME`, `"Unnumbered"` will ignore it.
2033 See also [`report_todo`](#report_todo).
2038 Report `TODO` items in comments.
2040 - **Default value**: `"Never"`
2041 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2042 - **Stable**: No (tracking issue: #3393)
2044 Warns about any comments containing `TODO` in them when set to `"Always"`. If
2045 it contains a `#X` (with `X` being a number) in parentheses following the
2046 `TODO`, `"Unnumbered"` will ignore it.
2048 See also [`report_fixme`](#report_fixme).
2050 ## `required_version`
2052 Require a specific version of rustfmt. If you want to make sure that the
2053 specific version of rustfmt is used in your CI, use this option.
2055 - **Default value**: `CARGO_PKG_VERSION`
2056 - **Possible values**: any published version (e.g. `"0.3.8"`)
2057 - **Stable**: No (tracking issue: #3386)
2061 Don't reformat out of line modules
2063 - **Default value**: `false`
2064 - **Possible values**: `true`, `false`
2065 - **Stable**: No (tracking issue: #3389)
2067 ## `space_after_colon`
2069 Leave a space after the colon.
2071 - **Default value**: `true`
2072 - **Possible values**: `true`, `false`
2073 - **Stable**: No (tracking issue: #3366)
2075 #### `true` (default):
2078 fn lorem<T: Eq>(t: T) {
2079 let lorem: Dolor = Lorem {
2089 fn lorem<T:Eq>(t:T) {
2090 let lorem:Dolor = Lorem {
2097 See also: [`space_before_colon`](#space_before_colon).
2099 ## `space_before_colon`
2101 Leave a space before the colon.
2103 - **Default value**: `false`
2104 - **Possible values**: `true`, `false`
2105 - **Stable**: No (tracking issue: #3365)
2107 #### `false` (default):
2110 fn lorem<T: Eq>(t: T) {
2111 let lorem: Dolor = Lorem {
2121 fn lorem<T : Eq>(t : T) {
2122 let lorem : Dolor = Lorem {
2129 See also: [`space_after_colon`](#space_after_colon).
2131 ## `spaces_around_ranges`
2133 Put spaces around the .., ..=, and ... range operators
2135 - **Default value**: `false`
2136 - **Possible values**: `true`, `false`
2137 - **Stable**: No (tracking issue: #3367)
2139 #### `false` (default):
2167 let lorem = 0 .. 10;
2168 let ipsum = 0 ..= 10;
2187 ## `struct_field_align_threshold`
2189 The maximum diff of width between struct fields to be aligned with each other.
2191 - **Default value** : 0
2192 - **Possible values**: any non-negative integer
2193 - **Stable**: No (tracking issue: #3371)
2215 ## `struct_lit_single_line`
2217 Put small struct literals on a single line
2219 - **Default value**: `true`
2220 - **Possible values**: `true`, `false`
2221 - **Stable**: No (tracking issue: #3357)
2223 #### `true` (default):
2227 let lorem = Lorem { foo: bar, baz: ofo };
2242 See also: [`indent_style`](#indent_style).
2247 Number of spaces per tab
2249 - **Default value**: `4`
2250 - **Possible values**: any positive integer
2257 let ipsum = dolor();
2259 "amet consectetur adipiscing elit amet",
2260 "consectetur adipiscing elit amet consectetur.",
2269 let ipsum = dolor();
2271 "amet consectetur adipiscing elit amet",
2272 "consectetur adipiscing elit amet consectetur.",
2277 See also: [`hard_tabs`](#hard_tabs).
2282 How to handle trailing commas for lists
2284 - **Default value**: `"Vertical"`
2285 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
2286 - **Stable**: No (tracking issue: #3379)
2288 #### `"Vertical"` (default):
2292 let Lorem { ipsum, dolor, sit } = amet;
2308 let Lorem { ipsum, dolor, sit, } = amet;
2324 let Lorem { ipsum, dolor, sit } = amet;
2336 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2338 ## `trailing_semicolon`
2340 Add trailing semicolon after break, continue and return
2342 - **Default value**: `true`
2343 - **Possible values**: `true`, `false`
2344 - **Stable**: No (tracking issue: #3378)
2346 #### `true` (default):
2360 ## `type_punctuation_density`
2362 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2364 - **Default value**: `"Wide"`
2365 - **Possible values**: `"Compressed"`, `"Wide"`
2366 - **Stable**: No (tracking issue: #3364)
2368 #### `"Wide"` (default):
2371 fn lorem<Ipsum: Dolor + Sit = Amet>() {
2376 #### `"Compressed"`:
2379 fn lorem<Ipsum: Dolor+Sit=Amet>() {
2384 ## `unstable_features`
2386 Enable unstable features on the unstable channel.
2388 - **Default value**: `false`
2389 - **Possible values**: `true`, `false`
2390 - **Stable**: No (tracking issue: #3387)
2392 ## `use_field_init_shorthand`
2394 Use field initialize shorthand if possible.
2396 - **Default value**: `false`
2397 - **Possible values**: `true`, `false`
2400 #### `false` (default):
2413 let a = Foo { x: x, y: y, z: z };
2430 let a = Foo { x, y, z };
2434 ## `use_small_heuristics`
2436 Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2438 - **Default value**: `"Default"`
2439 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
2442 #### `Default` (default):
2448 Sit { amet: Consectetur, adipiscing: Elit },
2466 let lorem = Lorem { ipsum: dolor };
2468 let lorem = if ipsum { dolor } else { sit };
2485 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2492 let lorem = if ipsum {
2506 Sit { amet: Consectetur, adipiscing: Elit },
2510 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2512 let lorem = Lorem { ipsum: dolor, sit: amet };
2514 let lorem = if ipsum { dolor } else { sit };
2518 ## `use_try_shorthand`
2520 Replace uses of the try! macro by the ? shorthand
2522 - **Default value**: `false`
2523 - **Possible values**: `true`, `false`
2526 #### `false` (default):
2530 let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2538 let lorem = ipsum.map(|dolor| dolor.sit())?;
2544 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2545 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2548 - **Default value**: `One`
2549 - **Possible values**: `One`, `Two`
2550 - **Stable**: No (tracking issue: #3383)
2558 ## `where_single_line`
2560 Forces the `where` clause to be laid out on a single line.
2562 - **Default value**: `false`
2563 - **Possible values**: `true`, `false`
2564 - **Stable**: No (tracking issue: #3359)
2566 #### `false` (default):
2581 where Option<T>: Ipsum
2587 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2592 Break comments to fit on the line
2594 - **Default value**: `false`
2595 - **Possible values**: `true`, `false`
2596 - **Stable**: No (tracking issue: #3347)
2598 #### `false` (default):
2601 // 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.
2607 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2608 // sed do eiusmod tempor incididunt ut labore et dolore
2609 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2610 // exercitation ullamco laboris nisi ut aliquip ex ea
2611 // commodo consequat.
2622 Internal option, use `--backup`
2624 ## `print_misformatted_file_names`
2626 Internal option, use `-l` or `--files-with-diff`