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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/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](https://github.com/rust-lang/rustfmt/issues/3377))
482 #### `"AlwaysSameLine"` (default):
494 #### `"AlwaysNextLine"`:
509 #### `"ClosingNextLine"`:
522 ## `disable_all_formatting`
524 Don't reformat anything.
526 Note that this option may be soft-deprecated in the future once the [ignore](#ignore) option is stabilized. Nightly toolchain users are encouraged to use [ignore](#ignore) instead when possible.
528 - **Default value**: `false`
529 - **Possible values**: `true`, `false`
534 Specifies which edition is used by the parser.
536 - **Default value**: `"2015"`
537 - **Possible values**: `"2015"`, `"2018"`, `"2021"`
540 Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
541 through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
548 ## `empty_item_single_line`
550 Put empty-body functions and impls on a single line
552 - **Default value**: `true`
553 - **Possible values**: `true`, `false`
554 - **Stable**: No (tracking issue: [#3356](https://github.com/rust-lang/rustfmt/issues/3356))
556 #### `true` (default):
574 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
577 ## `enum_discrim_align_threshold`
579 The maximum length of enum variant having discriminant, that gets vertically aligned with others.
580 Variants without discriminants would be ignored for the purpose of alignment.
582 Note that this is not how much whitespace is inserted, but instead the longest variant name that
583 doesn't get ignored when aligning.
585 - **Default value** : 0
586 - **Possible values**: any positive integer
587 - **Stable**: No (tracking issue: [#3372](https://github.com/rust-lang/rustfmt/issues/3372))
595 RandomLongVariantGoesHere = 10,
600 VeryLongVariantNameHereA = 0,
601 VeryLongVariantNameHereBb = 1,
602 VeryLongVariantNameHereCcc = 2,
612 RandomLongVariantGoesHere = 10,
617 VeryLongVariantNameHereA = 0,
618 VeryLongVariantNameHereBb = 1,
619 VeryLongVariantNameHereCcc = 2,
624 ## `error_on_line_overflow`
626 Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
627 literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
628 refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
629 using a shorter name.
631 - **Default value**: `false`
632 - **Possible values**: `true`, `false`
633 - **Stable**: No (tracking issue: [#3391](https://github.com/rust-lang/rustfmt/issues/3391))
635 See also [`max_width`](#max_width).
637 ## `error_on_unformatted`
639 Error if unable to get comments or string literals within `max_width`, or they are left with
640 trailing whitespaces.
642 - **Default value**: `false`
643 - **Possible values**: `true`, `false`
644 - **Stable**: No (tracking issue: [#3392](https://github.com/rust-lang/rustfmt/issues/3392))
648 Control the layout of arguments in a function
650 - **Default value**: `"Tall"`
651 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
654 #### `"Tall"` (default):
658 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
660 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
669 consectetur: Consectetur,
670 adipiscing: Adipiscing,
679 consectetur: Consectetur,
680 adipiscing: Adipiscing,
692 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
694 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
699 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
700 adipiscing: Adipiscing, elit: Elit,
704 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
705 adipiscing: Adipiscing, elit: Elit,
737 consectetur: Consectetur,
738 adipiscing: Adipiscing,
747 consectetur: Consectetur,
748 adipiscing: Adipiscing,
758 Maximum width of the args of a function call before falling back to vertical formatting.
760 - **Default value**: `60`
761 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
764 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.
766 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
770 Put single-expression functions on a single line
772 - **Default value**: `false`
773 - **Possible values**: `true`, `false`
774 - **Stable**: No (tracking issue: [#3358](https://github.com/rust-lang/rustfmt/issues/3358))
776 #### `false` (default):
779 fn lorem() -> usize {
783 fn lorem() -> usize {
792 fn lorem() -> usize { 42 }
794 fn lorem() -> usize {
800 See also [`control_brace_style`](#control_brace_style).
803 ## `force_explicit_abi`
805 Always print the abi for extern items
807 - **Default value**: `true`
808 - **Possible values**: `true`, `false`
811 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
813 #### `true` (default):
817 pub static lorem: c_int;
825 pub static lorem: c_int;
829 ## `force_multiline_blocks`
831 Force multiline closure and match arm bodies to be wrapped in a block
833 - **Default value**: `false`
834 - **Possible values**: `false`, `true`
835 - **Stable**: No (tracking issue: [#3374](https://github.com/rust-lang/rustfmt/issues/3374))
837 #### `false` (default):
841 result.and_then(|maybe_value| match maybe_value {
843 Some(value) => bar(),
848 println!("Hello World");
850 Some(dolor) => foo(),
859 result.and_then(|maybe_value| {
862 Some(value) => bar(),
869 println!("Hello World");
872 Some(dolor) => foo(),
878 ## `format_code_in_doc_comments`
880 Format code snippet included in doc comments.
882 - **Default value**: `false`
883 - **Possible values**: `true`, `false`
884 - **Stable**: No (tracking issue: [#3348](https://github.com/rust-lang/rustfmt/issues/3348))
886 #### `false` (default):
889 /// Adds one to the number given.
900 /// # fn add_one(x: i32) -> i32 {
904 fn add_one(x: i32) -> i32 {
912 /// Adds one to the number given.
919 /// assert_eq!(6, add_one(5));
920 /// # fn add_one(x: i32) -> i32 {
924 fn add_one(x: i32) -> i32 {
929 ## `format_generated_files`
931 Format generated files. A file is considered generated
932 if any of the first five lines contain a `@generated` comment marker.
933 By default, generated files are reformatted, i. e. `@generated` marker is ignored.
934 This option is currently ignored for stdin (`@generated` in stdin is ignored.)
936 - **Default value**: `true`
937 - **Possible values**: `true`, `false`
938 - **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))
940 ## `format_macro_matchers`
942 Format the metavariable matching patterns in macros.
944 - **Default value**: `false`
945 - **Possible values**: `true`, `false`
946 - **Stable**: No (tracking issue: [#3354](https://github.com/rust-lang/rustfmt/issues/3354))
948 #### `false` (default):
952 ($a: ident : $b: ty) => {
955 ($a: ident $b: ident $c: ident) => {
965 ($a:ident : $b:ty) => {
968 ($a:ident $b:ident $c:ident) => {
974 See also [`format_macro_bodies`](#format_macro_bodies).
977 ## `format_macro_bodies`
979 Format the bodies of macros.
981 - **Default value**: `true`
982 - **Possible values**: `true`, `false`
983 - **Stable**: No (tracking issue: [#3355](https://github.com/rust-lang/rustfmt/issues/3355))
985 #### `true` (default):
989 ($a: ident : $b: ty) => {
992 ($a: ident $b: ident $c: ident) => {
1002 ($a: ident : $b: ty) => { $a(42): $b; };
1003 ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
1007 See also [`format_macro_matchers`](#format_macro_matchers).
1012 Format string literals where necessary
1014 - **Default value**: `false`
1015 - **Possible values**: `true`, `false`
1016 - **Stable**: No (tracking issue: [#3353](https://github.com/rust-lang/rustfmt/issues/3353))
1018 #### `false` (default):
1022 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
1030 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
1031 consectetur adipiscing";
1035 See also [`max_width`](#max_width).
1039 Use tab characters for indentation, spaces for alignment
1041 - **Default value**: `false`
1042 - **Possible values**: `true`, `false`
1045 #### `false` (default):
1048 fn lorem() -> usize {
1049 42 // spaces before 42
1056 fn lorem() -> usize {
1057 42 // tabs before 42
1061 See also: [`tab_spaces`](#tab_spaces).
1063 ## `hex_literal_case`
1065 Control the case of the letters in hexadecimal literal values
1067 - **Default value**: `Preserve`
1068 - **Possible values**: `Upper`, `Lower`
1069 - **Stable**: No (tracking issue: [#5081](https://github.com/rust-lang/rustfmt/issues/5081))
1071 ## `hide_parse_errors`
1073 Do not show parse errors if the parser failed to parse files.
1075 - **Default value**: `false`
1076 - **Possible values**: `true`, `false`
1077 - **Stable**: No (tracking issue: [#3390](https://github.com/rust-lang/rustfmt/issues/3390))
1081 Skip formatting files and directories that match the specified pattern.
1082 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.
1084 - **Default value**: format every file
1085 - **Possible values**: See an example below
1086 - **Stable**: No (tracking issue: [#3395](https://github.com/rust-lang/rustfmt/issues/3395))
1090 If you want to ignore specific files, put the following to your config file:
1099 If you want to ignore every file under `examples/`, put the following to your config file:
1107 If you want to ignore every file under the directory where you put your rustfmt.toml:
1115 Indent style of imports
1117 - **Default Value**: `"Block"`
1118 - **Possible values**: `"Block"`, `"Visual"`
1119 - **Stable**: No (tracking issue: [#3360](https://github.com/rust-lang/rustfmt/issues/3360))
1121 #### `"Block"` (default):
1125 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1126 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1133 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1134 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1137 See also: [`imports_layout`](#imports_layout).
1141 Item layout inside a imports block
1143 - **Default value**: "Mixed"
1144 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1145 - **Stable**: No (tracking issue: [#3361](https://github.com/rust-lang/rustfmt/issues/3361))
1147 #### `"Mixed"` (default):
1150 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1153 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1154 eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1158 #### `"Horizontal"`:
1160 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1163 use foo::{xxx, yyy, zzz};
1165 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1168 #### `"HorizontalVertical"`:
1171 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1204 Indent on expressions or items.
1206 - **Default value**: `"Block"`
1207 - **Possible values**: `"Block"`, `"Visual"`
1208 - **Stable**: No (tracking issue: [#3346](https://github.com/rust-lang/rustfmt/issues/3346))
1212 #### `"Block"` (default):
1232 let lorem = vec!["ipsum",
1244 #### `"Block"` (default):
1252 && dolor_consectetur
1254 && lorem_consectetur
1269 && dolor_consectetur
1271 && lorem_consectetur
1278 See also: [`control_brace_style`](#control_brace_style).
1280 ### Function arguments
1282 #### `"Block"` (default):
1287 fn lorem(ipsum: usize) {}
1307 fn lorem(ipsum: usize) {}
1309 fn lorem(ipsum: usize,
1322 #### `"Block"` (default):
1356 #### `"Block"` (default):
1364 Adipiscing: Eq = usize,
1365 Consectetur: Eq = usize,
1372 adipiscing: Adipiscing,
1373 consectetur: Consectetur,
1383 fn lorem<Ipsum: Eq = usize,
1387 Adipiscing: Eq = usize,
1388 Consectetur: Eq = usize,
1394 adipiscing: Adipiscing,
1395 consectetur: Consectetur,
1404 #### `"Block"` (default):
1419 let lorem = Lorem { ipsum: dolor,
1424 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
1426 ### Where predicates
1428 #### `"Block"` (default):
1431 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1445 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
1455 ## `inline_attribute_width`
1457 Write an item and its attribute on the same line if their combined width is below a threshold
1459 - **Default value**: 0
1460 - **Possible values**: any positive integer
1461 - **Stable**: No (tracking issue: [#3343](https://github.com/rust-lang/rustfmt/issues/3343))
1467 #[cfg(feature = "alloc")]
1473 #[cfg(feature = "alloc")] use core::slice;
1476 ## `license_template_path`
1478 Check whether beginnings of files match a license template.
1480 - **Default value**: `""`
1481 - **Possible values**: path to a license template file
1482 - **Stable**: No (tracking issue: [#3352](https://github.com/rust-lang/rustfmt/issues/3352))
1484 A license template is a plain text file which is matched literally against the
1485 beginning of each source file, except for `{}`-delimited blocks, which are
1486 matched as regular expressions. The following license template therefore
1487 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
1488 Copyright 2018 The Rust Project Developers.`, etc.:
1491 // Copyright {\d+} The Rust Project Developers.
1494 `\{`, `\}` and `\\` match literal braces / backslashes.
1496 ## `match_arm_blocks`
1498 Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.
1500 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.
1502 - **Default value**: `true`
1503 - **Possible values**: `true`, `false`
1504 - **Stable**: No (tracking issue: [#3373](https://github.com/rust-lang/rustfmt/issues/3373))
1506 #### `true` (default):
1512 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1514 dolor => println!("{}", sit),
1516 "foooooooooooooooooooooooo",
1517 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1518 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1519 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1531 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1532 ipsum => println!("{}", sit),
1534 "foooooooooooooooooooooooo",
1535 "baaaaaaaaaaaaaaaaaaaaaaaarr",
1536 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
1537 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
1543 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1545 ## `match_arm_leading_pipes`
1547 Controls whether to include a leading pipe on match arms
1549 - **Default value**: `Never`
1550 - **Possible values**: `Always`, `Never`, `Preserve`
1553 #### `Never` (default):
1555 // Leading pipes are removed from this:
1558 // | "foo" | "bar" => {}
1560 // | "something relatively long"
1561 // | "something really really really realllllllllllllly long" => println!("x"),
1562 // | "qux" => println!("y"),
1572 | "something relatively long"
1573 | "something really really really realllllllllllllly long" => println!("x"),
1574 "qux" => println!("y"),
1582 // Leading pipes are emitted on all arms of this:
1585 // "foo" | "bar" => {}
1587 // | "something relatively long"
1588 // | "something really really really realllllllllllllly long" => println!("x"),
1589 // "qux" => println!("y"),
1597 | "foo" | "bar" => {}
1599 | "something relatively long"
1600 | "something really really really realllllllllllllly long" => println!("x"),
1601 | "qux" => println!("y"),
1611 | "foo" | "bar" => {}
1613 | "something relatively long"
1614 | "something really really really realllllllllllllly long" => println!("x"),
1615 | "qux" => println!("y"),
1627 ## `match_block_trailing_comma`
1629 Put a trailing comma after a block based match arm (non-block arms are not affected)
1631 - **Default value**: `false`
1632 - **Possible values**: `true`, `false`
1635 #### `false` (default):
1643 Lorem::Dolor => println!("dolor"),
1656 Lorem::Dolor => println!("dolor"),
1661 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1665 Maximum width of each line
1667 - **Default value**: `100`
1668 - **Possible values**: any positive integer
1671 See also [`error_on_line_overflow`](#error_on_line_overflow).
1675 Merge multiple derives into a single one.
1677 - **Default value**: `true`
1678 - **Possible values**: `true`, `false`
1681 #### `true` (default):
1684 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1691 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1694 #[derive(Eq, PartialEq)]
1696 #[derive(Copy, Clone)]
1700 ## `imports_granularity`
1702 How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
1704 - **Default value**: `Preserve`
1705 - **Possible values**: `Preserve`, `Crate`, `Module`, `Item`, `One`
1706 - **Stable**: No (tracking issue: [#4991](https://github.com/rust-lang/rustfmt/issues/4991))
1708 #### `Preserve` (default):
1710 Do not change the granularity of any imports and preserve the original structure written by the developer.
1715 use foo::{a, c, d::e};
1721 Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements.
1735 Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements.
1746 Flatten imports so that each has its own `use` statement.
1761 Merge all imports into a single `use` statement as long as they have the same visibility.
1764 pub use foo::{x, y};
1778 This option is deprecated. Use `imports_granularity = "Crate"` instead.
1780 - **Default value**: `false`
1781 - **Possible values**: `true`, `false`
1783 #### `false` (default):
1794 use foo::{a, b, c, d, e, f, g};
1800 Unix or Windows line endings
1802 - **Default value**: `"Auto"`
1803 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1806 #### `Auto` (default):
1808 The newline style is detected automatically on a per-file basis. Files
1809 with mixed line endings will be converted to the first detected line
1814 Line endings will be converted to `\r\n` on Windows and `\n` on all
1819 Line endings will be converted to `\n`.
1823 Line endings will be converted to `\r\n`.
1825 ## `normalize_comments`
1827 Convert /* */ comments to // comments where possible
1829 - **Default value**: `false`
1830 - **Possible values**: `true`, `false`
1831 - **Stable**: No (tracking issue: [#3350](https://github.com/rust-lang/rustfmt/issues/3350))
1833 #### `false` (default):
1837 fn dolor() -> usize {}
1840 fn adipiscing() -> usize {}
1847 fn dolor() -> usize {}
1850 fn adipiscing() -> usize {}
1853 ## `normalize_doc_attributes`
1855 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
1857 - **Default value**: `false`
1858 - **Possible values**: `true`, `false`
1859 - **Stable**: No (tracking issue: [#3351](https://github.com/rust-lang/rustfmt/issues/3351))
1861 #### `false` (default):
1864 #![doc = "Example documentation"]
1866 #[doc = "Example item documentation"]
1869 /// Example item documentation
1876 //! Example documentation
1878 /// Example item documentation
1882 ## `overflow_delimited_expr`
1884 When structs, slices, arrays, and block/array-like macros are used as the last
1885 argument in an expression list, allow them to overflow (like blocks/closures)
1886 instead of being indented on a new line.
1888 - **Default value**: `false`
1889 - **Possible values**: `true`, `false`
1890 - **Stable**: No (tracking issue: [#3370](https://github.com/rust-lang/rustfmt/issues/3370))
1892 #### `false` (default):
1965 ## `remove_nested_parens`
1967 Remove nested parens.
1969 - **Default value**: `true`,
1970 - **Possible values**: `true`, `false`
1974 #### `true` (default):
1991 ## `reorder_impl_items`
1993 Reorder impl items. `type` and `const` are put first, then macros and methods.
1995 - **Default value**: `false`
1996 - **Possible values**: `true`, `false`
1997 - **Stable**: No (tracking issue: [#3363](https://github.com/rust-lang/rustfmt/issues/3363))
1999 #### `false` (default)
2004 impl Iterator for Dummy {
2005 fn next(&mut self) -> Option<Self::Item> {
2012 impl Iterator for Dummy {
2015 fn next(&mut self) -> Option<Self::Item> {
2026 impl Iterator for Dummy {
2029 fn next(&mut self) -> Option<Self::Item> {
2035 ## `reorder_imports`
2037 Reorder import and extern crate statements alphabetically in groups (a group is
2038 separated by a newline).
2040 - **Default value**: `true`
2041 - **Possible values**: `true`, `false`
2044 #### `true` (default):
2064 Controls the strategy for how consecutive imports are grouped together.
2066 Controls the strategy for grouping sets of consecutive imports. Imports may contain newlines between imports and still be grouped together as a single set, but other statements between imports will result in different grouping sets.
2068 - **Default value**: `Preserve`
2069 - **Possible values**: `Preserve`, `StdExternalCrate`, `One`
2070 - **Stable**: No (tracking issue: [#5083](https://github.com/rust-lang/rustfmt/issues/5083))
2072 Each set of imports (one or more `use` statements, optionally separated by newlines) will be formatted independently. Other statements such as `mod ...` or `extern crate ...` will cause imports to not be grouped together.
2074 #### `Preserve` (default):
2076 Preserve the source file's import groups.
2079 use super::update::convert_publish_payload;
2082 use alloc::alloc::Layout;
2083 use juniper::{FieldError, FieldResult};
2088 use broker::database::PooledConnection;
2090 use super::schema::{Context, Payload};
2091 use crate::models::Event;
2095 #### `StdExternalCrate`:
2097 Discard existing import groups, and create three groups for:
2098 1. `std`, `core` and `alloc`,
2100 3. `self`, `super` and `crate` imports.
2103 use alloc::alloc::Layout;
2107 use broker::database::PooledConnection;
2109 use juniper::{FieldError, FieldResult};
2112 use super::schema::{Context, Payload};
2113 use super::update::convert_publish_payload;
2114 use crate::models::Event;
2119 Discard existing import groups, and create a single group for everything
2122 use super::schema::{Context, Payload};
2123 use super::update::convert_publish_payload;
2124 use crate::models::Event;
2125 use alloc::alloc::Layout;
2126 use broker::database::PooledConnection;
2129 use juniper::{FieldError, FieldResult};
2134 ## `reorder_modules`
2136 Reorder `mod` declarations alphabetically in group.
2138 - **Default value**: `true`
2139 - **Possible values**: `true`, `false`
2142 #### `true` (default)
2166 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
2167 of the original source code.
2171 Report `FIXME` items in comments.
2173 - **Default value**: `"Never"`
2174 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2175 - **Stable**: No (tracking issue: [#3394](https://github.com/rust-lang/rustfmt/issues/3394))
2177 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
2178 it contains a `#X` (with `X` being a number) in parentheses following the
2179 `FIXME`, `"Unnumbered"` will ignore it.
2181 See also [`report_todo`](#report_todo).
2186 Report `TODO` items in comments.
2188 - **Default value**: `"Never"`
2189 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
2190 - **Stable**: No (tracking issue: [#3393](https://github.com/rust-lang/rustfmt/issues/3393))
2192 Warns about any comments containing `TODO` in them when set to `"Always"`. If
2193 it contains a `#X` (with `X` being a number) in parentheses following the
2194 `TODO`, `"Unnumbered"` will ignore it.
2196 See also [`report_fixme`](#report_fixme).
2198 ## `required_version`
2200 Require a specific version of rustfmt. If you want to make sure that the
2201 specific version of rustfmt is used in your CI, use this option.
2203 - **Default value**: `CARGO_PKG_VERSION`
2204 - **Possible values**: any published version (e.g. `"0.3.8"`)
2205 - **Stable**: No (tracking issue: [#3386](https://github.com/rust-lang/rustfmt/issues/3386))
2207 ## `short_array_element_width_threshold`
2209 The width threshold for an array element to be considered "short".
2211 The layout of an array is dependent on the length of each of its elements.
2212 If the length of every element in an array is below this threshold (all elements are "short") then the array can be formatted in the mixed/compressed style, but if any one element has a length that exceeds this threshold then the array elements will have to be formatted vertically.
2214 - **Default value**: `10`
2215 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2218 #### `10` (default):
2221 pub const FORMAT_TEST: [u64; 5] = [
2233 pub const FORMAT_TEST: [u64; 5] = [
2234 0x0000000000000000, 0xaaaaaaaaaaaaaaaa, 0xbbbbbbbbbbbbbbbb, 0xcccccccccccccccc,
2239 See also [`max_width`](#max_width).
2243 Don't reformat out of line modules
2245 - **Default value**: `false`
2246 - **Possible values**: `true`, `false`
2247 - **Stable**: No (tracking issue: [#3389](https://github.com/rust-lang/rustfmt/issues/3389))
2249 ## `single_line_if_else_max_width`
2251 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`.
2253 - **Default value**: `50`
2254 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2257 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.
2259 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2261 ## `space_after_colon`
2263 Leave a space after the colon.
2265 - **Default value**: `true`
2266 - **Possible values**: `true`, `false`
2267 - **Stable**: No (tracking issue: [#3366](https://github.com/rust-lang/rustfmt/issues/3366))
2269 #### `true` (default):
2272 fn lorem<T: Eq>(t: T) {
2273 let lorem: Dolor = Lorem {
2283 fn lorem<T:Eq>(t:T) {
2284 let lorem:Dolor = Lorem {
2291 See also: [`space_before_colon`](#space_before_colon).
2293 ## `space_before_colon`
2295 Leave a space before the colon.
2297 - **Default value**: `false`
2298 - **Possible values**: `true`, `false`
2299 - **Stable**: No (tracking issue: [#3365](https://github.com/rust-lang/rustfmt/issues/3365))
2301 #### `false` (default):
2304 fn lorem<T: Eq>(t: T) {
2305 let lorem: Dolor = Lorem {
2315 fn lorem<T : Eq>(t : T) {
2316 let lorem : Dolor = Lorem {
2323 See also: [`space_after_colon`](#space_after_colon).
2325 ## `spaces_around_ranges`
2327 Put spaces around the .., ..=, and ... range operators
2329 - **Default value**: `false`
2330 - **Possible values**: `true`, `false`
2331 - **Stable**: No (tracking issue: [#3367](https://github.com/rust-lang/rustfmt/issues/3367))
2333 #### `false` (default):
2361 let lorem = 0 .. 10;
2362 let ipsum = 0 ..= 10;
2381 ## `struct_field_align_threshold`
2383 The maximum diff of width between struct fields to be aligned with each other.
2385 - **Default value** : 0
2386 - **Possible values**: any non-negative integer
2387 - **Stable**: No (tracking issue: [#3371](https://github.com/rust-lang/rustfmt/issues/3371))
2409 ## `struct_lit_single_line`
2411 Put small struct literals on a single line
2413 - **Default value**: `true`
2414 - **Possible values**: `true`, `false`
2415 - **Stable**: No (tracking issue: [#3357](https://github.com/rust-lang/rustfmt/issues/3357))
2417 #### `true` (default):
2421 let lorem = Lorem { foo: bar, baz: ofo };
2436 See also: [`indent_style`](#indent_style).
2438 ## `struct_lit_width`
2440 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`.
2442 - **Default value**: `18`
2443 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2446 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.
2448 See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2450 ## `struct_variant_width`
2452 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`.
2454 - **Default value**: `35`
2455 - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2458 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.
2460 See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
2464 Number of spaces per tab
2466 - **Default value**: `4`
2467 - **Possible values**: any positive integer
2474 let ipsum = dolor();
2476 "amet consectetur adipiscing elit amet",
2477 "consectetur adipiscing elit amet consectetur.",
2486 let ipsum = dolor();
2488 "amet consectetur adipiscing elit amet",
2489 "consectetur adipiscing elit amet consectetur.",
2494 See also: [`hard_tabs`](#hard_tabs).
2499 How to handle trailing commas for lists
2501 - **Default value**: `"Vertical"`
2502 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
2503 - **Stable**: No (tracking issue: [#3379](https://github.com/rust-lang/rustfmt/issues/3379))
2505 #### `"Vertical"` (default):
2509 let Lorem { ipsum, dolor, sit } = amet;
2525 let Lorem { ipsum, dolor, sit, } = amet;
2541 let Lorem { ipsum, dolor, sit } = amet;
2553 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2555 ## `trailing_semicolon`
2557 Add trailing semicolon after break, continue and return
2559 - **Default value**: `true`
2560 - **Possible values**: `true`, `false`
2561 - **Stable**: No (tracking issue: [#3378](https://github.com/rust-lang/rustfmt/issues/3378))
2563 #### `true` (default):
2577 ## `type_punctuation_density`
2579 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2581 - **Default value**: `"Wide"`
2582 - **Possible values**: `"Compressed"`, `"Wide"`
2583 - **Stable**: No (tracking issue: [#3364](https://github.com/rust-lang/rustfmt/issues/3364))
2585 #### `"Wide"` (default):
2588 fn lorem<Ipsum: Dolor + Sit = Amet>() {
2593 #### `"Compressed"`:
2596 fn lorem<Ipsum: Dolor+Sit=Amet>() {
2601 ## `unstable_features`
2603 Enable unstable features on the unstable channel.
2605 - **Default value**: `false`
2606 - **Possible values**: `true`, `false`
2607 - **Stable**: No (tracking issue: [#3387](https://github.com/rust-lang/rustfmt/issues/3387))
2609 ## `use_field_init_shorthand`
2611 Use field initialize shorthand if possible.
2613 - **Default value**: `false`
2614 - **Possible values**: `true`, `false`
2617 #### `false` (default):
2630 let a = Foo { x, y, z };
2631 let b = Foo { x: x, y: y, z: z };
2648 let a = Foo { x, y, z };
2652 ## `use_small_heuristics`
2654 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.
2656 Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
2658 - **Default value**: `"Default"`
2659 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
2662 #### `Default` (default):
2663 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`.
2666 * [`fn_call_width`](#fn_call_width) - `60%`
2667 * [`attr_fn_like_width`](#attr_fn_like_width) - `70%`
2668 * [`struct_lit_width`](#struct_lit_width) - `18%`
2669 * [`struct_variant_width`](#struct_variant_width) - `35%`
2670 * [`array_width`](#array_width) - `60%`
2671 * [`chain_width`](#chain_width) - `60%`
2672 * [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%`
2674 For example when `max_width` is set to `100`, the width settings are:
2675 * `fn_call_width=60`
2676 * `attr_fn_like_width=70`
2677 * `struct_lit_width=18`
2678 * `struct_variant_width=35`
2681 * `single_line_if_else_max_width=50`
2683 and when `max_width` is set to `200`:
2684 * `fn_call_width=120`
2685 * `attr_fn_like_width=140`
2686 * `struct_lit_width=36`
2687 * `struct_variant_width=70`
2690 * `single_line_if_else_max_width=100`
2696 Sit { amet: Consectetur, adipiscing: Elit },
2714 let lorem = Lorem { ipsum: dolor };
2716 let lorem = if ipsum { dolor } else { sit };
2721 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.
2734 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2741 let lorem = if ipsum {
2750 When `use_small_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2752 So if `max_width` is set to `200`, then all the width settings are also set to `200`.
2753 * `fn_call_width=200`
2754 * `attr_fn_like_width=200`
2755 * `struct_lit_width=200`
2756 * `struct_variant_width=200`
2759 * `single_line_if_else_max_width=200`
2765 Sit { amet: Consectetur, adipiscing: Elit },
2769 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2771 let lorem = Lorem { ipsum: dolor, sit: amet };
2773 let lorem = if ipsum { dolor } else { sit };
2779 * [`max_width`](#max_width)
2780 * [`fn_call_width`](#fn_call_width)
2781 * [`attr_fn_like_width`](#attr_fn_like_width)
2782 * [`struct_lit_width`](#struct_lit_width)
2783 * [`struct_variant_width`](#struct_variant_width)
2784 * [`array_width`](#array_width)
2785 * [`chain_width`](#chain_width)
2786 * [`single_line_if_else_max_width`](#single_line_if_else_max_width)
2788 ## `use_try_shorthand`
2790 Replace uses of the try! macro by the ? shorthand
2792 - **Default value**: `false`
2793 - **Possible values**: `true`, `false`
2796 #### `false` (default):
2800 let lorem = ipsum.map(|dolor| dolor.sit())?;
2802 let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2810 let lorem = ipsum.map(|dolor| dolor.sit())?;
2816 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2817 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2820 - **Default value**: `One`
2821 - **Possible values**: `One`, `Two`
2822 - **Stable**: No (tracking issue: [#3383](https://github.com/rust-lang/rustfmt/issues/3383))
2830 ## `where_single_line`
2832 Forces the `where` clause to be laid out on a single line.
2834 - **Default value**: `false`
2835 - **Possible values**: `true`, `false`
2836 - **Stable**: No (tracking issue: [#3359](https://github.com/rust-lang/rustfmt/issues/3359))
2838 #### `false` (default):
2853 where Option<T>: Ipsum
2859 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
2864 Break comments to fit on the line
2866 - **Default value**: `false`
2867 - **Possible values**: `true`, `false`
2868 - **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347))
2870 #### `false` (default):
2873 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2874 // sed do eiusmod tempor incididunt ut labore et dolore
2875 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2876 // exercitation ullamco laboris nisi ut aliquip ex ea
2877 // commodo consequat.
2879 // 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.
2885 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2886 // sed do eiusmod tempor incididunt ut labore et dolore
2887 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2888 // exercitation ullamco laboris nisi ut aliquip ex ea
2889 // commodo consequat.
2900 Internal option, use `--backup`
2902 ## `print_misformatted_file_names`
2904 Internal option, use `-l` or `--files-with-diff`