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 Indent on expressions or items.
25 - **Default value**: `"Block"`
26 - **Possible values**: `"Block"`, `"Visual"`
27 - **Stable**: No (tracking issue: #3346)
31 #### `"Block"` (default):
51 let lorem = vec!["ipsum",
63 #### `"Block"` (default):
97 See also: [`control_brace_style`](#control_brace_style).
99 ### Function arguments
101 #### `"Block"` (default):
106 fn lorem(ipsum: usize) {}
126 fn lorem(ipsum: usize) {}
128 fn lorem(ipsum: usize,
141 #### `"Block"` (default):
175 #### `"Block"` (default):
183 Adipiscing: Eq = usize,
184 Consectetur: Eq = usize,
191 adipiscing: Adipiscing,
192 consectetur: Consectetur,
202 fn lorem<Ipsum: Eq = usize,
206 Adipiscing: Eq = usize,
207 Consectetur: Eq = usize,
213 adipiscing: Adipiscing,
214 consectetur: Consectetur,
223 #### `"Block"` (default):
238 let lorem = Lorem { ipsum: dolor,
243 See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
247 #### `"Block"` (default):
250 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
264 fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
274 ## `use_small_heuristics`
276 Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
278 - **Default value**: `"Default"`
279 - **Possible values**: `"Default"`, `"Off"`, `"Max"`
282 #### `Default` (default):
288 Sit { amet: Consectetur, adipiscing: Elit },
306 let lorem = Lorem { ipsum: dolor };
308 let lorem = if ipsum { dolor } else { sit };
325 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
332 let lorem = if ipsum {
346 Sit { amet: Consectetur, adipiscing: Elit },
350 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
352 let lorem = Lorem { ipsum: dolor, sit: amet };
354 let lorem = if ipsum { dolor } else { sit };
360 Where to put a binary operator when a binary expression goes multiline.
362 - **Default value**: `"Front"`
363 - **Possible values**: `"Front"`, `"Back"`
364 - **Stable**: No (tracking issue: #3368)
366 #### `"Front"` (default):
370 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
371 || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
373 let sum = 123456789012345678901234567890
374 + 123456789012345678901234567890
375 + 123456789012345678901234567890;
377 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
378 ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
386 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
387 barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
389 let sum = 123456789012345678901234567890 +
390 123456789012345678901234567890 +
391 123456789012345678901234567890;
393 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
394 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
398 ## `combine_control_expr`
400 Combine control expressions with function calls.
402 - **Default value**: `true`
403 - **Possible values**: `true`, `false`
404 - **Stable**: No (tracking issue: #3369)
406 #### `true` (default):
418 foo!(if let Some(..) = x {
431 foo!(while let Some(..) = x {
465 if let Some(..) = x {
482 while let Some(..) = x {
508 Maximum length of comments. No effect unless`wrap_comments = true`.
510 - **Default value**: `80`
511 - **Possible values**: any positive integer
512 - **Stable**: No (tracking issue: #3349)
514 **Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
516 #### `80` (default; comments shorter than `comment_width`):
518 // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
521 #### `60` (comments longer than `comment_width`):
523 // Lorem ipsum dolor sit amet,
524 // consectetur adipiscing elit.
527 See also [`wrap_comments`](#wrap_comments).
529 ## `condense_wildcard_suffixes`
531 Replace strings of _ wildcards by a single .. in tuple patterns
533 - **Default value**: `false`
534 - **Possible values**: `true`, `false`
535 - **Stable**: No (tracking issue: #3384)
537 #### `false` (default):
541 let (lorem, ipsum, _, _) = (1, 2, 3, 4);
542 let (lorem, ipsum, ..) = (1, 2, 3, 4);
550 let (lorem, ipsum, ..) = (1, 2, 3, 4);
554 ## `control_brace_style`
556 Brace style for control flow constructs
558 - **Default value**: `"AlwaysSameLine"`
559 - **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"`
560 - **Stable**: No (tracking issue: #3377)
562 #### `"AlwaysSameLine"` (default):
574 #### `"AlwaysNextLine"`:
589 #### `"ClosingNextLine"`:
602 ## `disable_all_formatting`
604 Don't reformat anything
606 - **Default value**: `false`
607 - **Possible values**: `true`, `false`
608 - **Stable**: No (tracking issue: #3388)
610 ## `error_on_line_overflow`
612 Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
613 literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
614 refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
615 using a shorter name.
617 - **Default value**: `false`
618 - **Possible values**: `true`, `false`
619 - **Stable**: No (tracking issue: #3391)
621 See also [`max_width`](#max_width).
623 ## `error_on_unformatted`
625 Error if unable to get comments or string literals within `max_width`, or they are left with
626 trailing whitespaces.
628 - **Default value**: `false`
629 - **Possible values**: `true`, `false`
630 - **Stable**: No (tracking issue: #3392)
634 Argument density in functions
636 - **Default value**: `"Tall"`
637 - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
638 - **Stable**: No (tracking issue: #3375)
640 #### `"Tall"` (default):
644 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
646 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
655 consectetur: Consectetur,
656 adipiscing: Adipiscing,
665 consectetur: Consectetur,
666 adipiscing: Adipiscing,
678 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
680 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
685 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
686 adipiscing: Adipiscing, elit: Elit,
690 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
691 adipiscing: Adipiscing, elit: Elit,
723 consectetur: Consectetur,
724 adipiscing: Adipiscing,
733 consectetur: Consectetur,
734 adipiscing: Adipiscing,
745 Brace style for items
747 - **Default value**: `"SameLineWhere"`
748 - **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"`
749 - **Stable**: No (tracking issue: #3376)
753 #### `"SameLineWhere"` (default):
760 fn lorem(ipsum: usize) {
764 fn lorem<T>(ipsum: T)
766 T: Add + Sub + Mul + Div,
772 #### `"AlwaysNextLine"`:
780 fn lorem(ipsum: usize)
785 fn lorem<T>(ipsum: T)
787 T: Add + Sub + Mul + Div,
793 #### `"PreferSameLine"`:
800 fn lorem(ipsum: usize) {
804 fn lorem<T>(ipsum: T)
806 T: Add + Sub + Mul + Div, {
811 ### Structs and enums
813 #### `"SameLineWhere"` (default):
828 #### `"AlwaysNextLine"`:
844 #### `"PreferSameLine"`:
859 ## `empty_item_single_line`
861 Put empty-body functions and impls on a single line
863 - **Default value**: `true`
864 - **Possible values**: `true`, `false`
865 - **Stable**: No (tracking issue: #3356)
867 #### `true` (default):
885 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
888 ## `enum_discrim_align_threshold`
890 The maximum length of enum variant having discriminant, that gets vertically aligned with others.
891 Variants without discriminants would be ignored for the purpose of alignment.
893 Note that this is not how much whitespace is inserted, but instead the longest variant name that
894 doesn't get ignored when aligning.
896 - **Default value** : 0
897 - **Possible values**: any positive integer
898 - **Stable**: No (tracking issue: #3372)
906 RandomLongVariantGoesHere = 10,
911 VeryLongVariantNameHereA = 0,
912 VeryLongVariantNameHereBb = 1,
913 VeryLongVariantNameHereCcc = 2,
923 RandomLongVariantGoesHere = 10,
928 VeryLongVariantNameHereA = 0,
929 VeryLongVariantNameHereBb = 1,
930 VeryLongVariantNameHereCcc = 2,
937 Put single-expression functions on a single line
939 - **Default value**: `false`
940 - **Possible values**: `true`, `false`
941 - **Stable**: No (tracking issue: #3358)
943 #### `false` (default):
946 fn lorem() -> usize {
950 fn lorem() -> usize {
959 fn lorem() -> usize { 42 }
961 fn lorem() -> usize {
967 See also [`control_brace_style`](#control_brace_style).
970 ## `where_single_line`
972 Forces the `where` clause to be laid out on a single line.
974 - **Default value**: `false`
975 - **Possible values**: `true`, `false`
976 - **Stable**: No (tracking issue: #3359)
978 #### `false` (default):
993 where Option<T>: Ipsum
999 See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
1002 ## `force_explicit_abi`
1004 Always print the abi for extern items
1006 - **Default value**: `true`
1007 - **Possible values**: `true`, `false`
1010 **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
1012 #### `true` (default):
1016 pub static lorem: c_int;
1024 pub static lorem: c_int;
1030 Format string literals where necessary
1032 - **Default value**: `false`
1033 - **Possible values**: `true`, `false`
1034 - **Stable**: No (tracking issue: #3353)
1036 #### `false` (default):
1040 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
1048 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
1049 consectetur adipiscing";
1053 See also [`max_width`](#max_width).
1055 ## `format_macro_matchers`
1057 Format the metavariable matching patterns in macros.
1059 - **Default value**: `false`
1060 - **Possible values**: `true`, `false`
1061 - **Stable**: No (tracking issue: #3354)
1063 #### `false` (default):
1067 ($a: ident : $b: ty) => {
1070 ($a: ident $b: ident $c: ident) => {
1080 ($a:ident : $b:ty) => {
1083 ($a:ident $b:ident $c:ident) => {
1089 See also [`format_macro_bodies`](#format_macro_bodies).
1092 ## `format_macro_bodies`
1094 Format the bodies of macros.
1096 - **Default value**: `true`
1097 - **Possible values**: `true`, `false`
1098 - **Stable**: No (tracking issue: #3355)
1100 #### `true` (default):
1104 ($a: ident : $b: ty) => {
1107 ($a: ident $b: ident $c: ident) => {
1117 ($a: ident : $b: ty) => { $a(42): $b; };
1118 ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
1122 See also [`format_macro_matchers`](#format_macro_matchers).
1127 Use tab characters for indentation, spaces for alignment
1129 - **Default value**: `false`
1130 - **Possible values**: `true`, `false`
1133 #### `false` (default):
1136 fn lorem() -> usize {
1137 42 // spaces before 42
1144 fn lorem() -> usize {
1145 42 // tabs before 42
1149 See also: [`tab_spaces`](#tab_spaces).
1154 Indent style of imports
1156 - **Default Value**: `"Block"`
1157 - **Possible values**: `"Block"`, `"Visual"`
1158 - **Stable**: No (tracking issue: #3360)
1160 #### `"Block"` (default):
1164 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1165 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
1172 use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
1173 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
1176 See also: [`imports_layout`](#imports_layout).
1180 Item layout inside a imports block
1182 - **Default value**: "Mixed"
1183 - **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
1184 - **Stable**: No (tracking issue: #3361)
1186 #### `"Mixed"` (default):
1189 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1192 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
1193 eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
1197 #### `"Horizontal"`:
1199 **Note**: This option forces all imports onto one line and may exceed `max_width`.
1202 use foo::{xxx, yyy, zzz};
1204 use foo::{aaa, bbb, ccc, ddd, eee, fff};
1207 #### `"HorizontalVertical"`:
1210 use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
1243 Merge multiple imports into a single nested import.
1245 - **Default value**: `false`
1246 - **Possible values**: `true`, `false`
1247 - **Stable**: No (tracking issue: #3362)
1249 #### `false` (default):
1260 use foo::{a, b, c, d, e, f, g};
1264 ## `match_block_trailing_comma`
1266 Put a trailing comma after a block based match arm (non-block arms are not affected)
1268 - **Default value**: `false`
1269 - **Possible values**: `true`, `false`
1270 - **Stable**: No (tracking issue: #3380)
1272 #### `false` (default):
1280 Lorem::Dolor => println!("dolor"),
1293 Lorem::Dolor => println!("dolor"),
1298 See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
1302 Maximum width of each line
1304 - **Default value**: `100`
1305 - **Possible values**: any positive integer
1308 See also [`error_on_line_overflow`](#error_on_line_overflow).
1312 Merge multiple derives into a single one.
1314 - **Default value**: `true`
1315 - **Possible values**: `true`, `false`
1318 #### `true` (default):
1321 #[derive(Eq, PartialEq, Debug, Copy, Clone)]
1328 #[derive(Eq, PartialEq)]
1330 #[derive(Copy, Clone)]
1334 ## `force_multiline_blocks`
1336 Force multiline closure and match arm bodies to be wrapped in a block
1338 - **Default value**: `false`
1339 - **Possible values**: `false`, `true`
1340 - **Stable**: No (tracking issue: #3374)
1342 #### `false` (default):
1346 result.and_then(|maybe_value| match maybe_value {
1348 Some(value) => bar(),
1353 println!("Hello World");
1355 Some(dolor) => foo(),
1364 result.and_then(|maybe_value| {
1367 Some(value) => bar(),
1374 println!("Hello World");
1377 Some(dolor) => foo(),
1385 Unix or Windows line endings
1387 - **Default value**: `"Auto"`
1388 - **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"`
1391 #### `Auto` (default):
1393 The newline style is detected automatically on a per-file basis. Files
1394 with mixed line endings will be converted to the first detected line
1399 Line endings will be converted to `\r\n` on Windows and `\n` on all
1404 Line endings will be converted to `\n`.
1408 Line endings will be converted to `\r\n`.
1410 ## `normalize_comments`
1412 Convert /* */ comments to // comments where possible
1414 - **Default value**: `false`
1415 - **Possible values**: `true`, `false`
1416 - **Stable**: No (tracking issue: #3350)
1418 #### `false` (default):
1422 fn dolor() -> usize {}
1425 fn adipiscing() -> usize {}
1432 fn dolor() -> usize {}
1435 fn adipiscing() -> usize {}
1438 ## `remove_nested_parens`
1440 Remove nested parens.
1442 - **Default value**: `true`,
1443 - **Possible values**: `true`, `false`
1447 #### `true` (default):
1462 ## `reorder_imports`
1464 Reorder import and extern crate statements alphabetically in groups (a group is
1465 separated by a newline).
1467 - **Default value**: `true`
1468 - **Possible values**: `true`, `false`
1471 #### `true` (default):
1490 ## `reorder_modules`
1492 Reorder `mod` declarations alphabetically in group.
1494 - **Default value**: `true`
1495 - **Possible values**: `true`, `false`
1498 #### `true` (default)
1522 **Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
1523 of the original source code.
1525 ## `reorder_impl_items`
1527 Reorder impl items. `type` and `const` are put first, then macros and methods.
1529 - **Default value**: `false`
1530 - **Possible values**: `true`, `false`
1531 - **Stable**: No (tracking issue: #3363)
1533 #### `false` (default)
1538 impl Iterator for Dummy {
1539 fn next(&mut self) -> Option<Self::Item> {
1552 impl Iterator for Dummy {
1555 fn next(&mut self) -> Option<Self::Item> {
1563 Report `TODO` items in comments.
1565 - **Default value**: `"Never"`
1566 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1567 - **Stable**: No (tracking issue: #3393)
1569 Warns about any comments containing `TODO` in them when set to `"Always"`. If
1570 it contains a `#X` (with `X` being a number) in parentheses following the
1571 `TODO`, `"Unnumbered"` will ignore it.
1573 See also [`report_fixme`](#report_fixme).
1577 Report `FIXME` items in comments.
1579 - **Default value**: `"Never"`
1580 - **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
1581 - **Stable**: No (tracking issue: #3394)
1583 Warns about any comments containing `FIXME` in them when set to `"Always"`. If
1584 it contains a `#X` (with `X` being a number) in parentheses following the
1585 `FIXME`, `"Unnumbered"` will ignore it.
1587 See also [`report_todo`](#report_todo).
1592 Don't reformat out of line modules
1594 - **Default value**: `false`
1595 - **Possible values**: `true`, `false`
1596 - **Stable**: No (tracking issue: #3389)
1598 ## `space_after_colon`
1600 Leave a space after the colon.
1602 - **Default value**: `true`
1603 - **Possible values**: `true`, `false`
1604 - **Stable**: No (tracking issue: #3366)
1606 #### `true` (default):
1609 fn lorem<T: Eq>(t: T) {
1610 let lorem: Dolor = Lorem {
1620 fn lorem<T:Eq>(t:T) {
1621 let lorem:Dolor = Lorem {
1628 See also: [`space_before_colon`](#space_before_colon).
1630 ## `space_before_colon`
1632 Leave a space before the colon.
1634 - **Default value**: `false`
1635 - **Possible values**: `true`, `false`
1636 - **Stable**: No (tracking issue: #3365)
1638 #### `false` (default):
1641 fn lorem<T: Eq>(t: T) {
1642 let lorem: Dolor = Lorem {
1652 fn lorem<T : Eq>(t : T) {
1653 let lorem : Dolor = Lorem {
1660 See also: [`space_after_colon`](#space_after_colon).
1662 ## `struct_field_align_threshold`
1664 The maximum diff of width between struct fields to be aligned with each other.
1666 - **Default value** : 0
1667 - **Possible values**: any positive integer
1668 - **Stable**: No (tracking issue: #3371)
1690 ## `spaces_around_ranges`
1692 Put spaces around the .., ..=, and ... range operators
1694 - **Default value**: `false`
1695 - **Possible values**: `true`, `false`
1696 - **Stable**: No (tracking issue: #3367)
1698 #### `false` (default):
1726 let lorem = 0 .. 10;
1727 let ipsum = 0 ..= 10;
1746 ## `struct_lit_single_line`
1748 Put small struct literals on a single line
1750 - **Default value**: `true`
1751 - **Possible values**: `true`, `false`
1752 - **Stable**: No (tracking issue: #3357)
1754 #### `true` (default):
1758 let lorem = Lorem { foo: bar, baz: ofo };
1773 See also: [`indent_style`](#indent_style).
1778 Number of spaces per tab
1780 - **Default value**: `4`
1781 - **Possible values**: any positive integer
1788 let ipsum = dolor();
1790 "amet consectetur adipiscing elit amet",
1791 "consectetur adipiscing elit amet consectetur.",
1800 let ipsum = dolor();
1802 "amet consectetur adipiscing elit amet",
1803 "consectetur adipiscing elit amet consectetur.",
1808 See also: [`hard_tabs`](#hard_tabs).
1813 How to handle trailing commas for lists
1815 - **Default value**: `"Vertical"`
1816 - **Possible values**: `"Always"`, `"Never"`, `"Vertical"`
1817 - **Stable**: No (tracking issue: #3379)
1819 #### `"Vertical"` (default):
1823 let Lorem { ipsum, dolor, sit } = amet;
1839 let Lorem { ipsum, dolor, sit, } = amet;
1855 let Lorem { ipsum, dolor, sit } = amet;
1867 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
1869 ## `trailing_semicolon`
1871 Add trailing semicolon after break, continue and return
1873 - **Default value**: `true`
1874 - **Possible values**: `true`, `false`
1875 - **Stable**: No (tracking issue: #3378)
1877 #### `true` (default):
1891 ## `type_punctuation_density`
1893 Determines if `+` or `=` are wrapped in spaces in the punctuation of types
1895 - **Default value**: `"Wide"`
1896 - **Possible values**: `"Compressed"`, `"Wide"`
1897 - **Stable**: No (tracking issue: #3364)
1899 #### `"Wide"` (default):
1902 fn lorem<Ipsum: Dolor + Sit = Amet>() {
1907 #### `"Compressed"`:
1910 fn lorem<Ipsum: Dolor+Sit=Amet>() {
1915 ## `use_field_init_shorthand`
1917 Use field initialize shorthand if possible.
1919 - **Default value**: `false`
1920 - **Possible values**: `true`, `false`
1923 #### `false` (default):
1936 let a = Foo { x: x, y: y, z: z };
1953 let a = Foo { x, y, z };
1957 ## `use_try_shorthand`
1959 Replace uses of the try! macro by the ? shorthand
1961 - **Default value**: `false`
1962 - **Possible values**: `true`, `false`
1965 #### `false` (default):
1969 let lorem = try!(ipsum.map(|dolor| dolor.sit()));
1977 let lorem = ipsum.map(|dolor| dolor.sit())?;
1981 ## `format_doc_comments`
1983 Format doc comments.
1985 - **Default value**: `false`
1986 - **Possible values**: `true`, `false`
1987 - **Stable**: No (tracking issue: #3348)
1989 #### `false` (default):
1992 /// Adds one to the number given.
2003 /// # fn add_one(x: i32) -> i32 {
2007 fn add_one(x: i32) -> i32 {
2015 /// Adds one to the number given.
2022 /// assert_eq!(6, add_one(5));
2023 /// # fn add_one(x: i32) -> i32 {
2027 fn add_one(x: i32) -> i32 {
2034 Break comments to fit on the line
2036 - **Default value**: `false`
2037 - **Possible values**: `true`, `false`
2038 - **Stable**: No (tracking issue: #3347)
2040 #### `false` (default):
2043 // 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.
2049 // Lorem ipsum dolor sit amet, consectetur adipiscing elit,
2050 // sed do eiusmod tempor incididunt ut labore et dolore
2051 // magna aliqua. Ut enim ad minim veniam, quis nostrud
2052 // exercitation ullamco laboris nisi ut aliquip ex ea
2053 // commodo consequat.
2056 ## `match_arm_blocks`
2058 Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
2060 - **Default value**: `true`
2061 - **Possible values**: `true`, `false`
2062 - **Stable**: No (tracking issue: #3373)
2064 #### `true` (default):
2070 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
2072 false => println!("{}", sit),
2083 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
2084 false => println!("{}", sit),
2089 See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
2091 ## `overflow_delimited_expr`
2093 When structs, slices, arrays, and block/array-like macros are used as the last
2094 argument in an expression list, allow them to overflow (like blocks/closures)
2095 instead of being indented on a new line.
2097 - **Default value**: `false`
2098 - **Possible values**: `true`, `false`
2099 - **Stable**: No (tracking issue: #3370)
2101 #### `false` (default):
2174 ## `blank_lines_upper_bound`
2176 Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
2177 lines are found, they are trimmed down to match this integer.
2179 - **Default value**: `1`
2180 - **Possible values**: *unsigned integer*
2181 - **Stable**: No (tracking issue: #3381)
2231 See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound)
2233 ## `blank_lines_lower_bound`
2235 Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
2236 them, additional blank lines are inserted.
2238 - **Default value**: `0`
2239 - **Possible values**: *unsigned integer*
2240 - **Stable**: No (tracking issue: #3382)
2243 Original Code (rustfmt will not change it with the default value of `0`):
2273 ## `required_version`
2275 Require a specific version of rustfmt. If you want to make sure that the
2276 specific version of rustfmt is used in your CI, use this option.
2278 - **Default value**: `CARGO_PKG_VERSION`
2279 - **Possible values**: any published version (e.g. `"0.3.8"`)
2280 - **Stable**: No (tracking issue: #3386)
2282 ## `hide_parse_errors`
2284 Do not show parse errors if the parser failed to parse files.
2286 - **Default value**: `false`
2287 - **Possible values**: `true`, `false`
2288 - **Stable**: No (tracking issue: #3390)
2292 Whether to use colored output or not.
2294 - **Default value**: `"Auto"`
2295 - **Possible values**: "Auto", "Always", "Never"
2296 - **Stable**: No (tracking issue: #3385)
2298 ## `unstable_features`
2300 Enable unstable features on the unstable channel.
2302 - **Default value**: `false`
2303 - **Possible values**: `true`, `false`
2304 - **Stable**: No (tracking issue: #3387)
2306 ## `license_template_path`
2308 Check whether beginnings of files match a license template.
2310 - **Default value**: `""`
2311 - **Possible values**: path to a license template file
2312 - **Stable**: No (tracking issue: #3352)
2314 A license template is a plain text file which is matched literally against the
2315 beginning of each source file, except for `{}`-delimited blocks, which are
2316 matched as regular expressions. The following license template therefore
2317 matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
2318 Copyright 2018 The Rust Project Developers.`, etc.:
2321 // Copyright {\d+} The Rust Project Developers.
2324 `\{`, `\}` and `\\` match literal braces / backslashes.
2328 Skip formatting the specified files and directories.
2330 - **Default value**: format every files
2331 - **Possible values**: See an example below
2332 - **Stable**: No (tracking issue: #3395)
2336 If you want to ignore specific files, put the following to your config file:
2345 If you want to ignore every file under `examples/`, put the following to your config file:
2355 Specifies which edition is used by the parser.
2357 - **Default value**: `2015`
2358 - **Possible values**: `2015`, `2018`
2363 If you want to format code that requires edition 2018, add the following to your config file:
2371 Which version of the formatting rules to use. `Version::One` is backwards-compatible
2372 with Rustfmt 1.0. Other versions are only backwards compatible within a major
2375 - **Default value**: `One`
2376 - **Possible values**: `One`, `Two`
2377 - **Stable**: No (tracking issue: #3383)
2385 ## `normalize_doc_attributes`
2387 Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
2389 - **Default value**: `false`
2390 - **Possible values**: `true`, `false`
2391 - **Stable**: No (tracking issue: #3351)
2393 #### `false` (default):
2396 #![doc = "Example documentation"]
2398 #[doc = "Example item documentation"]
2405 //! Example documentation
2407 /// Example item documentation
2417 Internal option, use `--backup`