1# Configuring Rustfmt 2 3Rustfmt 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/4.0.0/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well. 4 5A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this: 6 7```toml 8indent_style = "Block" 9reorder_imports = false 10``` 11 12Each configuration option is either stable or unstable. 13Stable options can always be used, while unstable options are only available on a nightly toolchain and must be opted into. 14To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or pass `--unstable-features` to rustfmt. 15 16# Configuration Options 17 18Below you find a detailed visual guide on all the supported configuration options of rustfmt: 19 20## `array_width` 21 22Maximum width of an array literal before falling back to vertical formatting. 23 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) 26- **Stable**: Yes 27 28By 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. 29 30See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 31 32## `attr_fn_like_width` 33 34Maximum width of the args of a function-like attributes before falling back to vertical formatting. 35 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) 38- **Stable**: Yes 39 40By 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. 41 42See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 43 44## `binop_separator` 45 46Where to put a binary operator when a binary expression goes multiline. 47 48- **Default value**: `"Front"` 49- **Possible values**: `"Front"`, `"Back"` 50- **Stable**: No (tracking issue: [#3368](https://github.com/rust-lang/rustfmt/issues/3368)) 51 52#### `"Front"` (default): 53 54```rust 55fn main() { 56 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo 57 || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar; 58 59 let sum = 123456789012345678901234567890 60 + 123456789012345678901234567890 61 + 123456789012345678901234567890; 62 63 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 64 ..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; 65} 66``` 67 68#### `"Back"`: 69 70```rust 71fn main() { 72 let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo || 73 barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar; 74 75 let sum = 123456789012345678901234567890 + 76 123456789012345678901234567890 + 77 123456789012345678901234567890; 78 79 let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 80 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; 81} 82``` 83 84## `blank_lines_lower_bound` 85 86Minimum number of blank lines which must be put between items. If two items have fewer blank lines between 87them, additional blank lines are inserted. 88 89- **Default value**: `0` 90- **Possible values**: *unsigned integer* 91- **Stable**: No (tracking issue: [#3382](https://github.com/rust-lang/rustfmt/issues/3382)) 92 93### Example 94Original Code (rustfmt will not change it with the default value of `0`): 95 96```rust 97#![rustfmt::skip] 98 99fn foo() { 100 println!("a"); 101} 102fn bar() { 103 println!("b"); 104 println!("c"); 105} 106``` 107 108#### `1` 109```rust 110fn foo() { 111 112 println!("a"); 113} 114 115fn bar() { 116 117 println!("b"); 118 119 println!("c"); 120} 121``` 122 123 124## `blank_lines_upper_bound` 125 126Maximum number of blank lines which can be put between items. If more than this number of consecutive empty 127lines are found, they are trimmed down to match this integer. 128 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)) 132 133### Example 134Original Code: 135 136```rust 137#![rustfmt::skip] 138 139fn foo() { 140 println!("a"); 141} 142 143 144 145fn bar() { 146 println!("b"); 147 148 149 println!("c"); 150} 151``` 152 153#### `1` (default): 154```rust 155fn foo() { 156 println!("a"); 157} 158 159fn bar() { 160 println!("b"); 161 162 println!("c"); 163} 164``` 165 166#### `2`: 167```rust 168fn foo() { 169 println!("a"); 170} 171 172 173fn bar() { 174 println!("b"); 175 176 177 println!("c"); 178} 179``` 180 181See also: [`blank_lines_lower_bound`](#blank_lines_lower_bound) 182 183## `brace_style` 184 185Brace style for items 186 187- **Default value**: `"SameLineWhere"` 188- **Possible values**: `"AlwaysNextLine"`, `"PreferSameLine"`, `"SameLineWhere"` 189- **Stable**: No (tracking issue: [#3376](https://github.com/rust-lang/rustfmt/issues/3376)) 190 191### Functions 192 193#### `"SameLineWhere"` (default): 194 195```rust 196fn lorem() { 197 // body 198} 199 200fn lorem(ipsum: usize) { 201 // body 202} 203 204fn lorem<T>(ipsum: T) 205where 206 T: Add + Sub + Mul + Div, 207{ 208 // body 209} 210``` 211 212#### `"AlwaysNextLine"`: 213 214```rust 215fn lorem() 216{ 217 // body 218} 219 220fn lorem(ipsum: usize) 221{ 222 // body 223} 224 225fn lorem<T>(ipsum: T) 226where 227 T: Add + Sub + Mul + Div, 228{ 229 // body 230} 231``` 232 233#### `"PreferSameLine"`: 234 235```rust 236fn lorem() { 237 // body 238} 239 240fn lorem(ipsum: usize) { 241 // body 242} 243 244fn lorem<T>(ipsum: T) 245where 246 T: Add + Sub + Mul + Div, { 247 // body 248} 249``` 250 251### Structs and enums 252 253#### `"SameLineWhere"` (default): 254 255```rust 256struct Lorem { 257 ipsum: bool, 258} 259 260struct Dolor<T> 261where 262 T: Eq, 263{ 264 sit: T, 265} 266``` 267 268#### `"AlwaysNextLine"`: 269 270```rust 271struct Lorem 272{ 273 ipsum: bool, 274} 275 276struct Dolor<T> 277where 278 T: Eq, 279{ 280 sit: T, 281} 282``` 283 284#### `"PreferSameLine"`: 285 286```rust 287struct Lorem { 288 ipsum: bool, 289} 290 291struct Dolor<T> 292where 293 T: Eq, { 294 sit: T, 295} 296``` 297 298## `chain_width` 299 300Maximum width of a chain to fit on one line. 301 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) 304- **Stable**: Yes 305 306By 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. 307 308See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 309 310## `color` 311 312Whether to use colored output or not. 313 314- **Default value**: `"Auto"` 315- **Possible values**: "Auto", "Always", "Never" 316- **Stable**: No (tracking issue: [#3385](https://github.com/rust-lang/rustfmt/issues/3385)) 317 318## `combine_control_expr` 319 320Combine control expressions with function calls. 321 322- **Default value**: `true` 323- **Possible values**: `true`, `false` 324- **Stable**: No (tracking issue: [#3369](https://github.com/rust-lang/rustfmt/issues/3369)) 325 326#### `true` (default): 327 328```rust 329fn example() { 330 // If 331 foo!(if x { 332 foo(); 333 } else { 334 bar(); 335 }); 336 337 // IfLet 338 foo!(if let Some(..) = x { 339 foo(); 340 } else { 341 bar(); 342 }); 343 344 // While 345 foo!(while x { 346 foo(); 347 bar(); 348 }); 349 350 // WhileLet 351 foo!(while let Some(..) = x { 352 foo(); 353 bar(); 354 }); 355 356 // ForLoop 357 foo!(for x in y { 358 foo(); 359 bar(); 360 }); 361 362 // Loop 363 foo!(loop { 364 foo(); 365 bar(); 366 }); 367} 368``` 369 370#### `false`: 371 372```rust 373fn example() { 374 // If 375 foo!( 376 if x { 377 foo(); 378 } else { 379 bar(); 380 } 381 ); 382 383 // IfLet 384 foo!( 385 if let Some(..) = x { 386 foo(); 387 } else { 388 bar(); 389 } 390 ); 391 392 // While 393 foo!( 394 while x { 395 foo(); 396 bar(); 397 } 398 ); 399 400 // WhileLet 401 foo!( 402 while let Some(..) = x { 403 foo(); 404 bar(); 405 } 406 ); 407 408 // ForLoop 409 foo!( 410 for x in y { 411 foo(); 412 bar(); 413 } 414 ); 415 416 // Loop 417 foo!( 418 loop { 419 foo(); 420 bar(); 421 } 422 ); 423} 424``` 425 426## `comment_width` 427 428Maximum length of comments. No effect unless `wrap_comments = true`. 429 430- **Default value**: `80` 431- **Possible values**: any positive integer 432- **Stable**: No (tracking issue: [#3349](https://github.com/rust-lang/rustfmt/issues/3349)) 433 434**Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width. 435 436#### `80` (default; comments shorter than `comment_width`): 437```rust 438// Lorem ipsum dolor sit amet, consectetur adipiscing elit. 439``` 440 441#### `60` (comments longer than `comment_width`): 442```rust 443// Lorem ipsum dolor sit amet, 444// consectetur adipiscing elit. 445``` 446 447See also [`wrap_comments`](#wrap_comments). 448 449## `condense_wildcard_suffixes` 450 451Replace strings of _ wildcards by a single .. in tuple patterns 452 453- **Default value**: `false` 454- **Possible values**: `true`, `false` 455- **Stable**: No (tracking issue: [#3384](https://github.com/rust-lang/rustfmt/issues/3384)) 456 457#### `false` (default): 458 459```rust 460fn main() { 461 let (lorem, ipsum, _, _) = (1, 2, 3, 4); 462 let (lorem, ipsum, ..) = (1, 2, 3, 4); 463} 464``` 465 466#### `true`: 467 468```rust 469fn main() { 470 let (lorem, ipsum, ..) = (1, 2, 3, 4); 471} 472``` 473 474## `control_brace_style` 475 476Brace style for control flow constructs 477 478- **Default value**: `"AlwaysSameLine"` 479- **Possible values**: `"AlwaysNextLine"`, `"AlwaysSameLine"`, `"ClosingNextLine"` 480- **Stable**: No (tracking issue: [#3377](https://github.com/rust-lang/rustfmt/issues/3377)) 481 482#### `"AlwaysSameLine"` (default): 483 484```rust 485fn main() { 486 if lorem { 487 println!("ipsum!"); 488 } else { 489 println!("dolor!"); 490 } 491} 492``` 493 494#### `"AlwaysNextLine"`: 495 496```rust 497fn main() { 498 if lorem 499 { 500 println!("ipsum!"); 501 } 502 else 503 { 504 println!("dolor!"); 505 } 506} 507``` 508 509#### `"ClosingNextLine"`: 510 511```rust 512fn main() { 513 if lorem { 514 println!("ipsum!"); 515 } 516 else { 517 println!("dolor!"); 518 } 519} 520``` 521 522## `disable_all_formatting` 523 524Don't reformat anything. 525 526Note 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. 527 528- **Default value**: `false` 529- **Possible values**: `true`, `false` 530- **Stable**: Yes 531 532## `edition` 533 534Specifies which edition is used by the parser. 535 536- **Default value**: `"2015"` 537- **Possible values**: `"2015"`, `"2018"`, `"2021"` 538- **Stable**: Yes 539 540Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed 541through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified 542in your config file: 543 544```toml 545edition = "2018" 546``` 547 548## `empty_item_single_line` 549 550Put empty-body functions and impls on a single line 551 552- **Default value**: `true` 553- **Possible values**: `true`, `false` 554- **Stable**: No (tracking issue: [#3356](https://github.com/rust-lang/rustfmt/issues/3356)) 555 556#### `true` (default): 557 558```rust 559fn lorem() {} 560 561impl Lorem {} 562``` 563 564#### `false`: 565 566```rust 567fn lorem() { 568} 569 570impl Lorem { 571} 572``` 573 574See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style). 575 576 577## `enum_discrim_align_threshold` 578 579The maximum length of enum variant having discriminant, that gets vertically aligned with others. 580Variants without discriminants would be ignored for the purpose of alignment. 581 582Note that this is not how much whitespace is inserted, but instead the longest variant name that 583doesn't get ignored when aligning. 584 585- **Default value** : 0 586- **Possible values**: any positive integer 587- **Stable**: No (tracking issue: [#3372](https://github.com/rust-lang/rustfmt/issues/3372)) 588 589#### `0` (default): 590 591```rust 592enum Foo { 593 A = 0, 594 Bb = 1, 595 RandomLongVariantGoesHere = 10, 596 Ccc = 71, 597} 598 599enum Bar { 600 VeryLongVariantNameHereA = 0, 601 VeryLongVariantNameHereBb = 1, 602 VeryLongVariantNameHereCcc = 2, 603} 604``` 605 606#### `20`: 607 608```rust 609enum Foo { 610 A = 0, 611 Bb = 1, 612 RandomLongVariantGoesHere = 10, 613 Ccc = 2, 614} 615 616enum Bar { 617 VeryLongVariantNameHereA = 0, 618 VeryLongVariantNameHereBb = 1, 619 VeryLongVariantNameHereCcc = 2, 620} 621``` 622 623 624## `error_on_line_overflow` 625 626Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string 627literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by 628refactoring your code to avoid long/complex expressions, usually by extracting a local variable or 629using a shorter name. 630 631- **Default value**: `false` 632- **Possible values**: `true`, `false` 633- **Stable**: No (tracking issue: [#3391](https://github.com/rust-lang/rustfmt/issues/3391)) 634 635See also [`max_width`](#max_width). 636 637## `error_on_unformatted` 638 639Error if unable to get comments or string literals within `max_width`, or they are left with 640trailing whitespaces. 641 642- **Default value**: `false` 643- **Possible values**: `true`, `false` 644- **Stable**: No (tracking issue: [#3392](https://github.com/rust-lang/rustfmt/issues/3392)) 645 646## `fn_args_layout` 647 648This option is deprecated and has been renamed to `fn_params_layout` to better communicate that 649it affects the layout of parameters in function signatures. 650 651- **Default value**: `"Tall"` 652- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"` 653- **Stable**: Yes 654 655#### `"Tall"` (default): 656 657```rust 658trait Lorem { 659 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); 660 661 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { 662 // body 663 } 664 665 fn lorem( 666 ipsum: Ipsum, 667 dolor: Dolor, 668 sit: Sit, 669 amet: Amet, 670 consectetur: Consectetur, 671 adipiscing: Adipiscing, 672 elit: Elit, 673 ); 674 675 fn lorem( 676 ipsum: Ipsum, 677 dolor: Dolor, 678 sit: Sit, 679 amet: Amet, 680 consectetur: Consectetur, 681 adipiscing: Adipiscing, 682 elit: Elit, 683 ) { 684 // body 685 } 686} 687``` 688 689#### `"Compressed"`: 690 691```rust 692trait Lorem { 693 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); 694 695 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { 696 // body 697 } 698 699 fn lorem( 700 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur, 701 adipiscing: Adipiscing, elit: Elit, 702 ); 703 704 fn lorem( 705 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur, 706 adipiscing: Adipiscing, elit: Elit, 707 ) { 708 // body 709 } 710} 711``` 712 713#### `"Vertical"`: 714 715```rust 716trait Lorem { 717 fn lorem( 718 ipsum: Ipsum, 719 dolor: Dolor, 720 sit: Sit, 721 amet: Amet, 722 ); 723 724 fn lorem( 725 ipsum: Ipsum, 726 dolor: Dolor, 727 sit: Sit, 728 amet: Amet, 729 ) { 730 // body 731 } 732 733 fn lorem( 734 ipsum: Ipsum, 735 dolor: Dolor, 736 sit: Sit, 737 amet: Amet, 738 consectetur: Consectetur, 739 adipiscing: Adipiscing, 740 elit: Elit, 741 ); 742 743 fn lorem( 744 ipsum: Ipsum, 745 dolor: Dolor, 746 sit: Sit, 747 amet: Amet, 748 consectetur: Consectetur, 749 adipiscing: Adipiscing, 750 elit: Elit, 751 ) { 752 // body 753 } 754} 755``` 756 757See also [`fn_params_layout`](#fn_params_layout) 758 759## `fn_call_width` 760 761Maximum width of the args of a function call before falling back to vertical formatting. 762 763- **Default value**: `60` 764- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 765- **Stable**: Yes 766 767By 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. 768 769See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 770 771## `fn_params_layout` 772 773Control the layout of parameters in function signatures. 774 775- **Default value**: `"Tall"` 776- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"` 777- **Stable**: Yes 778 779#### `"Tall"` (default): 780 781```rust 782trait Lorem { 783 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); 784 785 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { 786 // body 787 } 788 789 fn lorem( 790 ipsum: Ipsum, 791 dolor: Dolor, 792 sit: Sit, 793 amet: Amet, 794 consectetur: Consectetur, 795 adipiscing: Adipiscing, 796 elit: Elit, 797 ); 798 799 fn lorem( 800 ipsum: Ipsum, 801 dolor: Dolor, 802 sit: Sit, 803 amet: Amet, 804 consectetur: Consectetur, 805 adipiscing: Adipiscing, 806 elit: Elit, 807 ) { 808 // body 809 } 810} 811``` 812 813#### `"Compressed"`: 814 815```rust 816trait Lorem { 817 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); 818 819 fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { 820 // body 821 } 822 823 fn lorem( 824 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur, 825 adipiscing: Adipiscing, elit: Elit, 826 ); 827 828 fn lorem( 829 ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur, 830 adipiscing: Adipiscing, elit: Elit, 831 ) { 832 // body 833 } 834} 835``` 836 837#### `"Vertical"`: 838 839```rust 840trait Lorem { 841 fn lorem( 842 ipsum: Ipsum, 843 dolor: Dolor, 844 sit: Sit, 845 amet: Amet, 846 ); 847 848 fn lorem( 849 ipsum: Ipsum, 850 dolor: Dolor, 851 sit: Sit, 852 amet: Amet, 853 ) { 854 // body 855 } 856 857 fn lorem( 858 ipsum: Ipsum, 859 dolor: Dolor, 860 sit: Sit, 861 amet: Amet, 862 consectetur: Consectetur, 863 adipiscing: Adipiscing, 864 elit: Elit, 865 ); 866 867 fn lorem( 868 ipsum: Ipsum, 869 dolor: Dolor, 870 sit: Sit, 871 amet: Amet, 872 consectetur: Consectetur, 873 adipiscing: Adipiscing, 874 elit: Elit, 875 ) { 876 // body 877 } 878} 879``` 880 881 882## `fn_single_line` 883 884Put single-expression functions on a single line 885 886- **Default value**: `false` 887- **Possible values**: `true`, `false` 888- **Stable**: No (tracking issue: [#3358](https://github.com/rust-lang/rustfmt/issues/3358)) 889 890#### `false` (default): 891 892```rust 893fn lorem() -> usize { 894 42 895} 896 897fn lorem() -> usize { 898 let ipsum = 42; 899 ipsum 900} 901``` 902 903#### `true`: 904 905```rust 906fn lorem() -> usize { 42 } 907 908fn lorem() -> usize { 909 let ipsum = 42; 910 ipsum 911} 912``` 913 914See also [`control_brace_style`](#control_brace_style). 915 916 917## `force_explicit_abi` 918 919Always print the abi for extern items 920 921- **Default value**: `true` 922- **Possible values**: `true`, `false` 923- **Stable**: Yes 924 925**Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed. 926 927#### `true` (default): 928 929```rust 930extern "C" { 931 pub static lorem: c_int; 932} 933``` 934 935#### `false`: 936 937```rust 938extern { 939 pub static lorem: c_int; 940} 941``` 942 943## `force_multiline_blocks` 944 945Force multiline closure and match arm bodies to be wrapped in a block 946 947- **Default value**: `false` 948- **Possible values**: `false`, `true` 949- **Stable**: No (tracking issue: [#3374](https://github.com/rust-lang/rustfmt/issues/3374)) 950 951#### `false` (default): 952 953```rust 954fn main() { 955 result.and_then(|maybe_value| match maybe_value { 956 None => foo(), 957 Some(value) => bar(), 958 }); 959 960 match lorem { 961 None => |ipsum| { 962 println!("Hello World"); 963 }, 964 Some(dolor) => foo(), 965 } 966} 967``` 968 969#### `true`: 970 971```rust 972fn main() { 973 result.and_then(|maybe_value| { 974 match maybe_value { 975 None => foo(), 976 Some(value) => bar(), 977 } 978 }); 979 980 match lorem { 981 None => { 982 |ipsum| { 983 println!("Hello World"); 984 } 985 } 986 Some(dolor) => foo(), 987 } 988} 989``` 990 991 992## `format_code_in_doc_comments` 993 994Format code snippet included in doc comments. 995 996- **Default value**: `false` 997- **Possible values**: `true`, `false` 998- **Stable**: No (tracking issue: [#3348](https://github.com/rust-lang/rustfmt/issues/3348)) 999 1000#### `false` (default): 1001 1002```rust 1003/// Adds one to the number given. 1004/// 1005/// # Examples 1006/// 1007/// ```rust 1008/// let five=5; 1009/// 1010/// assert_eq!( 1011/// 6, 1012/// add_one(5) 1013/// ); 1014/// # fn add_one(x: i32) -> i32 { 1015/// # x + 1 1016/// # } 1017/// ``` 1018fn add_one(x: i32) -> i32 { 1019 x + 1 1020} 1021``` 1022 1023#### `true` 1024 1025```rust 1026/// Adds one to the number given. 1027/// 1028/// # Examples 1029/// 1030/// ```rust 1031/// let five = 5; 1032/// 1033/// assert_eq!(6, add_one(5)); 1034/// # fn add_one(x: i32) -> i32 { 1035/// # x + 1 1036/// # } 1037/// ``` 1038fn add_one(x: i32) -> i32 { 1039 x + 1 1040} 1041``` 1042 1043## `doc_comment_code_block_width` 1044 1045Max width for code snippets included in doc comments. Only used if [`format_code_in_doc_comments`](#format_code_in_doc_comments) is true. 1046 1047- **Default value**: `100` 1048- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 1049- **Stable**: No (tracking issue: [#5359](https://github.com/rust-lang/rustfmt/issues/5359)) 1050 1051## `format_generated_files` 1052 1053Format generated files. A file is considered generated 1054if any of the first five lines contain a `@generated` comment marker. 1055By default, generated files are reformatted, i. e. `@generated` marker is ignored. 1056This option is currently ignored for stdin (`@generated` in stdin is ignored.) 1057 1058- **Default value**: `true` 1059- **Possible values**: `true`, `false` 1060- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080)) 1061 1062## `format_macro_matchers` 1063 1064Format the metavariable matching patterns in macros. 1065 1066- **Default value**: `false` 1067- **Possible values**: `true`, `false` 1068- **Stable**: No (tracking issue: [#3354](https://github.com/rust-lang/rustfmt/issues/3354)) 1069 1070#### `false` (default): 1071 1072```rust 1073macro_rules! foo { 1074 ($a: ident : $b: ty) => { 1075 $a(42): $b; 1076 }; 1077 ($a: ident $b: ident $c: ident) => { 1078 $a = $b + $c; 1079 }; 1080} 1081``` 1082 1083#### `true`: 1084 1085```rust 1086macro_rules! foo { 1087 ($a:ident : $b:ty) => { 1088 $a(42): $b; 1089 }; 1090 ($a:ident $b:ident $c:ident) => { 1091 $a = $b + $c; 1092 }; 1093} 1094``` 1095 1096See also [`format_macro_bodies`](#format_macro_bodies). 1097 1098 1099## `format_macro_bodies` 1100 1101Format the bodies of macros. 1102 1103- **Default value**: `true` 1104- **Possible values**: `true`, `false` 1105- **Stable**: No (tracking issue: [#3355](https://github.com/rust-lang/rustfmt/issues/3355)) 1106 1107#### `true` (default): 1108 1109```rust 1110macro_rules! foo { 1111 ($a: ident : $b: ty) => { 1112 $a(42): $b; 1113 }; 1114 ($a: ident $b: ident $c: ident) => { 1115 $a = $b + $c; 1116 }; 1117} 1118``` 1119 1120#### `false`: 1121 1122```rust 1123macro_rules! foo { 1124 ($a: ident : $b: ty) => { $a(42): $b; }; 1125 ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; 1126} 1127``` 1128 1129See also [`format_macro_matchers`](#format_macro_matchers). 1130 1131## `skip_macro_invocations` 1132 1133Skip formatting the bodies of macro invocations with the following names. 1134 1135rustfmt will not format any macro invocation for macros with names set in this list. 1136Including the special value "*" will prevent any macro invocations from being formatted. 1137 1138Note: This option does not have any impact on how rustfmt formats macro definitions. 1139 1140- **Default value**: `[]` 1141- **Possible values**: a list of macro name idents, `["name_0", "name_1", ..., "*"]` 1142- **Stable**: No (tracking issue: [#5346](https://github.com/rust-lang/rustfmt/issues/5346)) 1143 1144#### `[]` (default): 1145 1146rustfmt will follow its standard approach to formatting macro invocations. 1147 1148No macro invocations will be skipped based on their name. More information about rustfmt's standard macro invocation formatting behavior can be found in [#5437](https://github.com/rust-lang/rustfmt/discussions/5437). 1149 1150```rust 1151lorem!( 1152 const _: u8 = 0; 1153); 1154 1155ipsum!( 1156 const _: u8 = 0; 1157); 1158``` 1159 1160#### `["lorem"]`: 1161 1162The named macro invocations will be skipped. 1163 1164```rust 1165lorem!( 1166 const _: u8 = 0; 1167); 1168 1169ipsum!( 1170 const _: u8 = 0; 1171); 1172``` 1173 1174#### `["*"]`: 1175 1176The special selector `*` will skip all macro invocations. 1177 1178```rust 1179lorem!( 1180 const _: u8 = 0; 1181); 1182 1183ipsum!( 1184 const _: u8 = 0; 1185); 1186``` 1187 1188## `format_strings` 1189 1190Format string literals where necessary 1191 1192- **Default value**: `false` 1193- **Possible values**: `true`, `false` 1194- **Stable**: No (tracking issue: [#3353](https://github.com/rust-lang/rustfmt/issues/3353)) 1195 1196#### `false` (default): 1197 1198```rust 1199fn main() { 1200 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing"; 1201} 1202``` 1203 1204#### `true`: 1205 1206```rust 1207fn main() { 1208 let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \ 1209 consectetur adipiscing"; 1210} 1211``` 1212 1213See also [`max_width`](#max_width). 1214 1215## `hard_tabs` 1216 1217Use tab characters for indentation, spaces for alignment 1218 1219- **Default value**: `false` 1220- **Possible values**: `true`, `false` 1221- **Stable**: Yes 1222 1223#### `false` (default): 1224 1225```rust 1226fn lorem() -> usize { 1227 42 // spaces before 42 1228} 1229``` 1230 1231#### `true`: 1232 1233```rust 1234fn lorem() -> usize { 1235 42 // tabs before 42 1236} 1237``` 1238 1239See also: [`tab_spaces`](#tab_spaces). 1240 1241## `hex_literal_case` 1242 1243Control the case of the letters in hexadecimal literal values 1244 1245- **Default value**: `Preserve` 1246- **Possible values**: `Preserve`, `Upper`, `Lower` 1247- **Stable**: No (tracking issue: [#5081](https://github.com/rust-lang/rustfmt/issues/5081)) 1248 1249## `hide_parse_errors` 1250 1251Do not show parse errors if the parser failed to parse files. 1252 1253- **Default value**: `false` 1254- **Possible values**: `true`, `false` 1255- **Stable**: No (tracking issue: [#3390](https://github.com/rust-lang/rustfmt/issues/3390)) 1256 1257## `ignore` 1258 1259Skip formatting files and directories that match the specified pattern. 1260The 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. 1261 1262- **Default value**: format every file 1263- **Possible values**: See an example below 1264- **Stable**: No (tracking issue: [#3395](https://github.com/rust-lang/rustfmt/issues/3395)) 1265 1266### Example 1267 1268If you want to ignore specific files, put the following to your config file: 1269 1270```toml 1271ignore = [ 1272 "src/types.rs", 1273 "src/foo/bar.rs", 1274] 1275``` 1276 1277If you want to ignore every file under `examples/`, put the following to your config file: 1278 1279```toml 1280ignore = [ 1281 "examples", 1282] 1283``` 1284 1285If you want to ignore every file under the directory where you put your rustfmt.toml: 1286 1287```toml 1288ignore = ["/"] 1289``` 1290 1291## `imports_indent` 1292 1293Indent style of imports 1294 1295- **Default Value**: `"Block"` 1296- **Possible values**: `"Block"`, `"Visual"` 1297- **Stable**: No (tracking issue: [#3360](https://github.com/rust-lang/rustfmt/issues/3360)) 1298 1299#### `"Block"` (default): 1300 1301```rust 1302use foo::{ 1303 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, 1304 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, 1305}; 1306``` 1307 1308#### `"Visual"`: 1309 1310```rust 1311use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, 1312 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}; 1313``` 1314 1315See also: [`imports_layout`](#imports_layout). 1316 1317## `imports_layout` 1318 1319Item layout inside a imports block 1320 1321- **Default value**: "Mixed" 1322- **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical" 1323- **Stable**: No (tracking issue: [#3361](https://github.com/rust-lang/rustfmt/issues/3361)) 1324 1325#### `"Mixed"` (default): 1326 1327```rust 1328use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; 1329 1330use foo::{ 1331 aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd, 1332 eeeeeeeeeeeeeeeeee, ffffffffffffffffff, 1333}; 1334``` 1335 1336#### `"Horizontal"`: 1337 1338**Note**: This option forces all imports onto one line and may exceed `max_width`. 1339 1340```rust 1341use foo::{xxx, yyy, zzz}; 1342 1343use foo::{aaa, bbb, ccc, ddd, eee, fff}; 1344``` 1345 1346#### `"HorizontalVertical"`: 1347 1348```rust 1349use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; 1350 1351use foo::{ 1352 aaaaaaaaaaaaaaaaaa, 1353 bbbbbbbbbbbbbbbbbb, 1354 cccccccccccccccccc, 1355 dddddddddddddddddd, 1356 eeeeeeeeeeeeeeeeee, 1357 ffffffffffffffffff, 1358}; 1359``` 1360 1361#### `"Vertical"`: 1362 1363```rust 1364use foo::{ 1365 xxx, 1366 yyy, 1367 zzz, 1368}; 1369 1370use foo::{ 1371 aaa, 1372 bbb, 1373 ccc, 1374 ddd, 1375 eee, 1376 fff, 1377}; 1378``` 1379 1380## `indent_style` 1381 1382Indent on expressions or items. 1383 1384- **Default value**: `"Block"` 1385- **Possible values**: `"Block"`, `"Visual"` 1386- **Stable**: No (tracking issue: [#3346](https://github.com/rust-lang/rustfmt/issues/3346)) 1387 1388### Array 1389 1390#### `"Block"` (default): 1391 1392```rust 1393fn main() { 1394 let lorem = vec![ 1395 "ipsum", 1396 "dolor", 1397 "sit", 1398 "amet", 1399 "consectetur", 1400 "adipiscing", 1401 "elit", 1402 ]; 1403} 1404``` 1405 1406#### `"Visual"`: 1407 1408```rust 1409fn main() { 1410 let lorem = vec!["ipsum", 1411 "dolor", 1412 "sit", 1413 "amet", 1414 "consectetur", 1415 "adipiscing", 1416 "elit"]; 1417} 1418``` 1419 1420### Control flow 1421 1422#### `"Block"` (default): 1423 1424```rust 1425fn main() { 1426 if lorem_ipsum 1427 && dolor_sit 1428 && amet_consectetur 1429 && lorem_sit 1430 && dolor_consectetur 1431 && amet_ipsum 1432 && lorem_consectetur 1433 { 1434 // ... 1435 } 1436} 1437``` 1438 1439#### `"Visual"`: 1440 1441```rust 1442fn main() { 1443 if lorem_ipsum 1444 && dolor_sit 1445 && amet_consectetur 1446 && lorem_sit 1447 && dolor_consectetur 1448 && amet_ipsum 1449 && lorem_consectetur 1450 { 1451 // ... 1452 } 1453} 1454``` 1455 1456See also: [`control_brace_style`](#control_brace_style). 1457 1458### Function arguments 1459 1460#### `"Block"` (default): 1461 1462```rust 1463fn lorem() {} 1464 1465fn lorem(ipsum: usize) {} 1466 1467fn lorem( 1468 ipsum: usize, 1469 dolor: usize, 1470 sit: usize, 1471 amet: usize, 1472 consectetur: usize, 1473 adipiscing: usize, 1474 elit: usize, 1475) { 1476 // body 1477} 1478``` 1479 1480#### `"Visual"`: 1481 1482```rust 1483fn lorem() {} 1484 1485fn lorem(ipsum: usize) {} 1486 1487fn lorem(ipsum: usize, 1488 dolor: usize, 1489 sit: usize, 1490 amet: usize, 1491 consectetur: usize, 1492 adipiscing: usize, 1493 elit: usize) { 1494 // body 1495} 1496``` 1497 1498### Function calls 1499 1500#### `"Block"` (default): 1501 1502```rust 1503fn main() { 1504 lorem( 1505 "lorem", 1506 "ipsum", 1507 "dolor", 1508 "sit", 1509 "amet", 1510 "consectetur", 1511 "adipiscing", 1512 "elit", 1513 ); 1514} 1515``` 1516 1517#### `"Visual"`: 1518 1519```rust 1520fn main() { 1521 lorem("lorem", 1522 "ipsum", 1523 "dolor", 1524 "sit", 1525 "amet", 1526 "consectetur", 1527 "adipiscing", 1528 "elit"); 1529} 1530``` 1531 1532### Generics 1533 1534#### `"Block"` (default): 1535 1536```rust 1537fn lorem< 1538 Ipsum: Eq = usize, 1539 Dolor: Eq = usize, 1540 Sit: Eq = usize, 1541 Amet: Eq = usize, 1542 Adipiscing: Eq = usize, 1543 Consectetur: Eq = usize, 1544 Elit: Eq = usize, 1545>( 1546 ipsum: Ipsum, 1547 dolor: Dolor, 1548 sit: Sit, 1549 amet: Amet, 1550 adipiscing: Adipiscing, 1551 consectetur: Consectetur, 1552 elit: Elit, 1553) -> T { 1554 // body 1555} 1556``` 1557 1558#### `"Visual"`: 1559 1560```rust 1561fn lorem<Ipsum: Eq = usize, 1562 Dolor: Eq = usize, 1563 Sit: Eq = usize, 1564 Amet: Eq = usize, 1565 Adipiscing: Eq = usize, 1566 Consectetur: Eq = usize, 1567 Elit: Eq = usize>( 1568 ipsum: Ipsum, 1569 dolor: Dolor, 1570 sit: Sit, 1571 amet: Amet, 1572 adipiscing: Adipiscing, 1573 consectetur: Consectetur, 1574 elit: Elit) 1575 -> T { 1576 // body 1577} 1578``` 1579 1580#### Struct 1581 1582#### `"Block"` (default): 1583 1584```rust 1585fn main() { 1586 let lorem = Lorem { 1587 ipsum: dolor, 1588 sit: amet, 1589 }; 1590} 1591``` 1592 1593#### `"Visual"`: 1594 1595```rust 1596fn main() { 1597 let lorem = Lorem { ipsum: dolor, 1598 sit: amet }; 1599} 1600``` 1601 1602See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style). 1603 1604### Where predicates 1605 1606#### `"Block"` (default): 1607 1608```rust 1609fn lorem<Ipsum, Dolor, Sit, Amet>() -> T 1610where 1611 Ipsum: Eq, 1612 Dolor: Eq, 1613 Sit: Eq, 1614 Amet: Eq, 1615{ 1616 // body 1617} 1618``` 1619 1620#### `"Visual"`: 1621 1622```rust 1623fn lorem<Ipsum, Dolor, Sit, Amet>() -> T 1624 where Ipsum: Eq, 1625 Dolor: Eq, 1626 Sit: Eq, 1627 Amet: Eq 1628{ 1629 // body 1630} 1631``` 1632 1633## `inline_attribute_width` 1634 1635Write an item and its attribute on the same line if their combined width is below a threshold 1636 1637- **Default value**: 0 1638- **Possible values**: any positive integer 1639- **Stable**: No (tracking issue: [#3343](https://github.com/rust-lang/rustfmt/issues/3343)) 1640 1641### Example 1642 1643#### `0` (default): 1644```rust 1645#[cfg(feature = "alloc")] 1646use core::slice; 1647``` 1648 1649#### `50`: 1650```rust 1651#[cfg(feature = "alloc")] use core::slice; 1652``` 1653 1654## `match_arm_blocks` 1655 1656Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator. 1657 1658The 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. 1659 1660- **Default value**: `true` 1661- **Possible values**: `true`, `false` 1662- **Stable**: No (tracking issue: [#3373](https://github.com/rust-lang/rustfmt/issues/3373)) 1663 1664#### `true` (default): 1665 1666```rust 1667fn main() { 1668 match lorem { 1669 ipsum => { 1670 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x) 1671 } 1672 dolor => println!("{}", sit), 1673 sit => foo( 1674 "foooooooooooooooooooooooo", 1675 "baaaaaaaaaaaaaaaaaaaaaaaarr", 1676 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz", 1677 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx", 1678 ), 1679 } 1680} 1681``` 1682 1683#### `false`: 1684 1685```rust 1686fn main() { 1687 match lorem { 1688 lorem => 1689 foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), 1690 ipsum => println!("{}", sit), 1691 sit => foo( 1692 "foooooooooooooooooooooooo", 1693 "baaaaaaaaaaaaaaaaaaaaaaaarr", 1694 "baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz", 1695 "qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx", 1696 ), 1697 } 1698} 1699``` 1700 1701See also: [`match_block_trailing_comma`](#match_block_trailing_comma). 1702 1703## `match_arm_leading_pipes` 1704 1705Controls whether to include a leading pipe on match arms 1706 1707- **Default value**: `Never` 1708- **Possible values**: `Always`, `Never`, `Preserve` 1709- **Stable**: Yes 1710 1711#### `Never` (default): 1712```rust 1713// Leading pipes are removed from this: 1714// fn foo() { 1715// match foo { 1716// | "foo" | "bar" => {} 1717// | "baz" 1718// | "something relatively long" 1719// | "something really really really realllllllllllllly long" => println!("x"), 1720// | "qux" => println!("y"), 1721// _ => {} 1722// } 1723// } 1724 1725// Becomes 1726fn foo() { 1727 match foo { 1728 "foo" | "bar" => {} 1729 "baz" 1730 | "something relatively long" 1731 | "something really really really realllllllllllllly long" => println!("x"), 1732 "qux" => println!("y"), 1733 _ => {} 1734 } 1735} 1736``` 1737 1738#### `Always`: 1739```rust 1740// Leading pipes are emitted on all arms of this: 1741// fn foo() { 1742// match foo { 1743// "foo" | "bar" => {} 1744// "baz" 1745// | "something relatively long" 1746// | "something really really really realllllllllllllly long" => println!("x"), 1747// "qux" => println!("y"), 1748// _ => {} 1749// } 1750// } 1751 1752// Becomes: 1753fn foo() { 1754 match foo { 1755 | "foo" | "bar" => {} 1756 | "baz" 1757 | "something relatively long" 1758 | "something really really really realllllllllllllly long" => println!("x"), 1759 | "qux" => println!("y"), 1760 | _ => {} 1761 } 1762} 1763``` 1764 1765#### `Preserve`: 1766```rust 1767fn foo() { 1768 match foo { 1769 | "foo" | "bar" => {} 1770 | "baz" 1771 | "something relatively long" 1772 | "something really really really realllllllllllllly long" => println!("x"), 1773 | "qux" => println!("y"), 1774 _ => {} 1775 } 1776 1777 match baz { 1778 "qux" => {} 1779 "foo" | "bar" => {} 1780 _ => {} 1781 } 1782} 1783``` 1784 1785## `match_block_trailing_comma` 1786 1787Put a trailing comma after a block based match arm (non-block arms are not affected) 1788 1789- **Default value**: `false` 1790- **Possible values**: `true`, `false` 1791- **Stable**: Yes 1792 1793#### `false` (default): 1794 1795```rust 1796fn main() { 1797 match lorem { 1798 Lorem::Ipsum => { 1799 println!("ipsum"); 1800 } 1801 Lorem::Dolor => println!("dolor"), 1802 } 1803} 1804``` 1805 1806#### `true`: 1807 1808```rust 1809fn main() { 1810 match lorem { 1811 Lorem::Ipsum => { 1812 println!("ipsum"); 1813 }, 1814 Lorem::Dolor => println!("dolor"), 1815 } 1816} 1817``` 1818 1819See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks). 1820 1821## `max_width` 1822 1823Maximum width of each line 1824 1825- **Default value**: `100` 1826- **Possible values**: any positive integer 1827- **Stable**: Yes 1828 1829See also [`error_on_line_overflow`](#error_on_line_overflow). 1830 1831## `merge_derives` 1832 1833Merge multiple derives into a single one. 1834 1835- **Default value**: `true` 1836- **Possible values**: `true`, `false` 1837- **Stable**: Yes 1838 1839#### `true` (default): 1840 1841```rust 1842#[derive(Eq, PartialEq, Debug, Copy, Clone)] 1843pub enum Foo {} 1844``` 1845 1846#### `false`: 1847 1848```rust 1849#[derive(Eq, PartialEq, Debug, Copy, Clone)] 1850pub enum Bar {} 1851 1852#[derive(Eq, PartialEq)] 1853#[derive(Debug)] 1854#[derive(Copy, Clone)] 1855pub enum Foo {} 1856``` 1857 1858## `imports_granularity` 1859 1860Controls how imports are structured in `use` statements. Imports will be merged or split to the configured level of granularity. 1861 1862Similar to other `import` related configuration options, this option operates within the bounds of user-defined groups of imports. See [`group_imports`](#group_imports) for more information on import groups. 1863 1864Note that rustfmt will not modify the granularity of imports containing comments if doing so could potentially lose or misplace said comments. 1865 1866- **Default value**: `Preserve` 1867- **Possible values**: `Preserve`, `Crate`, `Module`, `Item`, `One` 1868- **Stable**: No (tracking issue: [#4991](https://github.com/rust-lang/rustfmt/issues/4991)) 1869 1870 1871#### `Preserve` (default): 1872 1873Do not change the granularity of any imports and preserve the original structure written by the developer. 1874 1875```rust 1876use foo::b; 1877use foo::b::{f, g}; 1878use foo::{a, c, d::e}; 1879use qux::{h, i}; 1880``` 1881 1882#### `Crate`: 1883 1884Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements. 1885 1886```rust 1887use foo::{ 1888 a, b, 1889 b::{f, g}, 1890 c, 1891 d::e, 1892}; 1893use qux::{h, i}; 1894``` 1895 1896#### `Module`: 1897 1898Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements. 1899 1900```rust 1901use foo::b::{f, g}; 1902use foo::d::e; 1903use foo::{a, b, c}; 1904use qux::{h, i}; 1905``` 1906 1907#### `Item`: 1908 1909Flatten imports so that each has its own `use` statement. 1910 1911```rust 1912use foo::a; 1913use foo::b; 1914use foo::b::f; 1915use foo::b::g; 1916use foo::c; 1917use foo::d::e; 1918use qux::h; 1919use qux::i; 1920``` 1921 1922#### `One`: 1923 1924Merge all imports into a single `use` statement as long as they have the same visibility. 1925 1926```rust 1927pub use foo::{x, y}; 1928use { 1929 bar::{ 1930 a, 1931 b::{self, f, g}, 1932 c, 1933 d::e, 1934 }, 1935 qux::{h, i}, 1936}; 1937``` 1938 1939## `merge_imports` 1940 1941This option is deprecated. Use `imports_granularity = "Crate"` instead. 1942 1943- **Default value**: `false` 1944- **Possible values**: `true`, `false` 1945 1946#### `false` (default): 1947 1948```rust 1949use foo::{a, c, d}; 1950use foo::{b, g}; 1951use foo::{e, f}; 1952``` 1953 1954#### `true`: 1955 1956```rust 1957use foo::{a, b, c, d, e, f, g}; 1958``` 1959 1960 1961## `newline_style` 1962 1963Unix or Windows line endings 1964 1965- **Default value**: `"Auto"` 1966- **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"` 1967- **Stable**: Yes 1968 1969#### `Auto` (default): 1970 1971The newline style is detected automatically on a per-file basis. Files 1972with mixed line endings will be converted to the first detected line 1973ending style. 1974 1975#### `Native` 1976 1977Line endings will be converted to `\r\n` on Windows and `\n` on all 1978other platforms. 1979 1980#### `Unix` 1981 1982Line endings will be converted to `\n`. 1983 1984#### `Windows` 1985 1986Line endings will be converted to `\r\n`. 1987 1988## `normalize_comments` 1989 1990Convert /* */ comments to // comments where possible 1991 1992- **Default value**: `false` 1993- **Possible values**: `true`, `false` 1994- **Stable**: No (tracking issue: [#3350](https://github.com/rust-lang/rustfmt/issues/3350)) 1995 1996#### `false` (default): 1997 1998```rust 1999// Lorem ipsum: 2000fn dolor() -> usize {} 2001 2002/* sit amet: */ 2003fn adipiscing() -> usize {} 2004``` 2005 2006#### `true`: 2007 2008```rust 2009// Lorem ipsum: 2010fn dolor() -> usize {} 2011 2012// sit amet: 2013fn adipiscing() -> usize {} 2014``` 2015 2016## `normalize_doc_attributes` 2017 2018Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments. 2019 2020- **Default value**: `false` 2021- **Possible values**: `true`, `false` 2022- **Stable**: No (tracking issue: [#3351](https://github.com/rust-lang/rustfmt/issues/3351)) 2023 2024#### `false` (default): 2025 2026```rust 2027#![doc = "Example documentation"] 2028 2029#[doc = "Example item documentation"] 2030pub enum Bar {} 2031 2032/// Example item documentation 2033pub enum Foo {} 2034``` 2035 2036#### `true`: 2037 2038```rust 2039//! Example documentation 2040 2041/// Example item documentation 2042pub enum Foo {} 2043``` 2044 2045## `overflow_delimited_expr` 2046 2047When structs, slices, arrays, and block/array-like macros are used as the last 2048argument in an expression list, allow them to overflow (like blocks/closures) 2049instead of being indented on a new line. 2050 2051- **Default value**: `false` 2052- **Possible values**: `true`, `false` 2053- **Stable**: No (tracking issue: [#3370](https://github.com/rust-lang/rustfmt/issues/3370)) 2054 2055#### `false` (default): 2056 2057```rust 2058fn example() { 2059 foo(ctx, |param| { 2060 action(); 2061 foo(param) 2062 }); 2063 2064 foo( 2065 ctx, 2066 Bar { 2067 x: value, 2068 y: value2, 2069 }, 2070 ); 2071 2072 foo( 2073 ctx, 2074 &[ 2075 MAROON_TOMATOES, 2076 PURPLE_POTATOES, 2077 ORGANE_ORANGES, 2078 GREEN_PEARS, 2079 RED_APPLES, 2080 ], 2081 ); 2082 2083 foo( 2084 ctx, 2085 vec![ 2086 MAROON_TOMATOES, 2087 PURPLE_POTATOES, 2088 ORGANE_ORANGES, 2089 GREEN_PEARS, 2090 RED_APPLES, 2091 ], 2092 ); 2093} 2094``` 2095 2096#### `true`: 2097 2098```rust 2099fn example() { 2100 foo(ctx, |param| { 2101 action(); 2102 foo(param) 2103 }); 2104 2105 foo(ctx, Bar { 2106 x: value, 2107 y: value2, 2108 }); 2109 2110 foo(ctx, &[ 2111 MAROON_TOMATOES, 2112 PURPLE_POTATOES, 2113 ORGANE_ORANGES, 2114 GREEN_PEARS, 2115 RED_APPLES, 2116 ]); 2117 2118 foo(ctx, vec![ 2119 MAROON_TOMATOES, 2120 PURPLE_POTATOES, 2121 ORGANE_ORANGES, 2122 GREEN_PEARS, 2123 RED_APPLES, 2124 ]); 2125} 2126``` 2127 2128## `remove_nested_parens` 2129 2130Remove nested parens. 2131 2132- **Default value**: `true`, 2133- **Possible values**: `true`, `false` 2134- **Stable**: Yes 2135 2136 2137#### `true` (default): 2138```rust 2139fn main() { 2140 (foo()); 2141} 2142``` 2143 2144#### `false`: 2145```rust 2146fn main() { 2147 (foo()); 2148 2149 ((((foo())))); 2150} 2151``` 2152 2153 2154## `reorder_impl_items` 2155 2156Reorder impl items. `type` and `const` are put first, then macros and methods. 2157 2158- **Default value**: `false` 2159- **Possible values**: `true`, `false` 2160- **Stable**: No (tracking issue: [#3363](https://github.com/rust-lang/rustfmt/issues/3363)) 2161 2162#### `false` (default) 2163 2164```rust 2165struct Dummy; 2166 2167impl Iterator for Dummy { 2168 fn next(&mut self) -> Option<Self::Item> { 2169 None 2170 } 2171 2172 type Item = i32; 2173} 2174 2175impl Iterator for Dummy { 2176 type Item = i32; 2177 2178 fn next(&mut self) -> Option<Self::Item> { 2179 None 2180 } 2181} 2182``` 2183 2184#### `true` 2185 2186```rust 2187struct Dummy; 2188 2189impl Iterator for Dummy { 2190 type Item = i32; 2191 2192 fn next(&mut self) -> Option<Self::Item> { 2193 None 2194 } 2195} 2196``` 2197 2198## `reorder_imports` 2199 2200Reorder import and extern crate statements alphabetically in groups (a group is 2201separated by a newline). 2202 2203- **Default value**: `true` 2204- **Possible values**: `true`, `false` 2205- **Stable**: Yes 2206 2207#### `true` (default): 2208 2209```rust 2210use dolor; 2211use ipsum; 2212use lorem; 2213use sit; 2214``` 2215 2216#### `false`: 2217 2218```rust 2219use lorem; 2220use ipsum; 2221use dolor; 2222use sit; 2223``` 2224 2225## `group_imports` 2226 2227Controls the strategy for how consecutive imports are grouped together. 2228 2229Controls 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. 2230 2231- **Default value**: `Preserve` 2232- **Possible values**: `Preserve`, `StdExternalCrate`, `One` 2233- **Stable**: No (tracking issue: [#5083](https://github.com/rust-lang/rustfmt/issues/5083)) 2234 2235Each 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. 2236 2237#### `Preserve` (default): 2238 2239Preserve the source file's import groups. 2240 2241```rust 2242use super::update::convert_publish_payload; 2243use chrono::Utc; 2244 2245use alloc::alloc::Layout; 2246use juniper::{FieldError, FieldResult}; 2247use uuid::Uuid; 2248 2249use std::sync::Arc; 2250 2251use broker::database::PooledConnection; 2252 2253use super::schema::{Context, Payload}; 2254use crate::models::Event; 2255use core::f32; 2256``` 2257 2258#### `StdExternalCrate`: 2259 2260Discard existing import groups, and create three groups for: 22611. `std`, `core` and `alloc`, 22622. external crates, 22633. `self`, `super` and `crate` imports. 2264 2265```rust 2266use alloc::alloc::Layout; 2267use core::f32; 2268use std::sync::Arc; 2269 2270use broker::database::PooledConnection; 2271use chrono::Utc; 2272use juniper::{FieldError, FieldResult}; 2273use uuid::Uuid; 2274 2275use super::schema::{Context, Payload}; 2276use super::update::convert_publish_payload; 2277use crate::models::Event; 2278``` 2279 2280#### `One`: 2281 2282Discard existing import groups, and create a single group for everything 2283 2284```rust 2285use super::schema::{Context, Payload}; 2286use super::update::convert_publish_payload; 2287use crate::models::Event; 2288use alloc::alloc::Layout; 2289use broker::database::PooledConnection; 2290use chrono::Utc; 2291use core::f32; 2292use juniper::{FieldError, FieldResult}; 2293use std::sync::Arc; 2294use uuid::Uuid; 2295``` 2296 2297## `reorder_modules` 2298 2299Reorder `mod` declarations alphabetically in group. 2300 2301- **Default value**: `true` 2302- **Possible values**: `true`, `false` 2303- **Stable**: Yes 2304 2305#### `true` (default) 2306 2307```rust 2308mod a; 2309mod b; 2310 2311mod dolor; 2312mod ipsum; 2313mod lorem; 2314mod sit; 2315``` 2316 2317#### `false` 2318 2319```rust 2320mod b; 2321mod a; 2322 2323mod lorem; 2324mod ipsum; 2325mod dolor; 2326mod sit; 2327``` 2328 2329**Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics 2330of the original source code. 2331 2332## `required_version` 2333 2334Require a specific version of rustfmt. If you want to make sure that the 2335specific version of rustfmt is used in your CI, use this option. 2336 2337- **Default value**: `CARGO_PKG_VERSION` 2338- **Possible values**: any published version (e.g. `"0.3.8"`) 2339- **Stable**: No (tracking issue: [#3386](https://github.com/rust-lang/rustfmt/issues/3386)) 2340 2341## `short_array_element_width_threshold` 2342 2343The width threshold for an array element to be considered "short". 2344 2345The layout of an array is dependent on the length of each of its elements. 2346If 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. 2347 2348- **Default value**: `10` 2349- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 2350- **Stable**: Yes 2351 2352#### `10` (default): 2353```rust 2354fn main() { 2355 pub const FORMAT_TEST: [u64; 5] = [ 2356 0x0000000000000000, 2357 0xaaaaaaaaaaaaaaaa, 2358 0xbbbbbbbbbbbbbbbb, 2359 0xcccccccccccccccc, 2360 0xdddddddddddddddd, 2361 ]; 2362} 2363``` 2364#### `20`: 2365```rust 2366fn main() { 2367 pub const FORMAT_TEST: [u64; 5] = [ 2368 0x0000000000000000, 0xaaaaaaaaaaaaaaaa, 0xbbbbbbbbbbbbbbbb, 0xcccccccccccccccc, 2369 0xdddddddddddddddd, 2370 ]; 2371} 2372``` 2373See also [`max_width`](#max_width). 2374 2375## `skip_children` 2376 2377Don't reformat out of line modules 2378 2379- **Default value**: `false` 2380- **Possible values**: `true`, `false` 2381- **Stable**: No (tracking issue: [#3389](https://github.com/rust-lang/rustfmt/issues/3389)) 2382 2383## `single_line_if_else_max_width` 2384 2385Maximum 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`. 2386 2387- **Default value**: `50` 2388- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 2389- **Stable**: Yes 2390 2391By 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. 2392 2393See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 2394 2395## `single_line_let_else_max_width` 2396 2397Maximum line length for single line let-else statements. 2398See the [let-else statement section of the Rust Style Guide](https://github.com/rust-lang/rust/blob/master/src/doc/style-guide/src/statements.md#else-blocks-let-else-statements) for more details on when a let-else statement may be written on a single line. 2399A value of `0` (zero) means the divergent `else` block will always be formatted over multiple lines. 2400Note this occurs when `use_small_heuristics` is set to `Off`. 2401 2402By 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_let_else_max_width` will take precedence. 2403 2404- **Default value**: `50` 2405- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 2406- **Stable**: Yes 2407 2408#### `50` (default): 2409 2410```rust 2411fn main() { 2412 let Some(w) = opt else { return Ok(()) }; 2413 2414 let Some(x) = opt else { return }; 2415 2416 let Some(y) = opt else { 2417 return; 2418 }; 2419 2420 let Some(z) = some_very_very_very_very_long_name else { 2421 return; 2422 }; 2423} 2424``` 2425 2426#### `0`: 2427 2428```rust 2429fn main() { 2430 let Some(w) = opt else { 2431 return Ok(()); 2432 }; 2433 2434 let Some(x) = opt else { 2435 return; 2436 }; 2437 2438 let Some(y) = opt else { 2439 return; 2440 }; 2441 2442 let Some(z) = some_very_very_very_very_long_name else { 2443 return; 2444 }; 2445} 2446``` 2447 2448#### `100`: 2449 2450```rust 2451fn main() { 2452 let Some(w) = opt else { return Ok(()) }; 2453 2454 let Some(x) = opt else { return }; 2455 2456 let Some(y) = opt else { 2457 return; 2458 }; 2459 2460 let Some(z) = some_very_very_very_very_long_name else { return }; 2461} 2462``` 2463 2464See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 2465 2466 2467## `space_after_colon` 2468 2469Leave a space after the colon. 2470 2471- **Default value**: `true` 2472- **Possible values**: `true`, `false` 2473- **Stable**: No (tracking issue: [#3366](https://github.com/rust-lang/rustfmt/issues/3366)) 2474 2475#### `true` (default): 2476 2477```rust 2478fn lorem<T: Eq>(t: T) { 2479 let lorem: Dolor = Lorem { 2480 ipsum: dolor, 2481 sit: amet, 2482 }; 2483} 2484``` 2485 2486#### `false`: 2487 2488```rust 2489fn lorem<T:Eq>(t:T) { 2490 let lorem:Dolor = Lorem { 2491 ipsum:dolor, 2492 sit:amet, 2493 }; 2494} 2495``` 2496 2497See also: [`space_before_colon`](#space_before_colon). 2498 2499## `space_before_colon` 2500 2501Leave a space before the colon. 2502 2503- **Default value**: `false` 2504- **Possible values**: `true`, `false` 2505- **Stable**: No (tracking issue: [#3365](https://github.com/rust-lang/rustfmt/issues/3365)) 2506 2507#### `false` (default): 2508 2509```rust 2510fn lorem<T: Eq>(t: T) { 2511 let lorem: Dolor = Lorem { 2512 ipsum: dolor, 2513 sit: amet, 2514 }; 2515} 2516``` 2517 2518#### `true`: 2519 2520```rust 2521fn lorem<T : Eq>(t : T) { 2522 let lorem : Dolor = Lorem { 2523 ipsum : dolor, 2524 sit : amet, 2525 }; 2526} 2527``` 2528 2529See also: [`space_after_colon`](#space_after_colon). 2530 2531## `spaces_around_ranges` 2532 2533Put spaces around the .., ..=, and ... range operators 2534 2535- **Default value**: `false` 2536- **Possible values**: `true`, `false` 2537- **Stable**: No (tracking issue: [#3367](https://github.com/rust-lang/rustfmt/issues/3367)) 2538 2539#### `false` (default): 2540 2541```rust 2542fn main() { 2543 let lorem = 0..10; 2544 let ipsum = 0..=10; 2545 2546 match lorem { 2547 1..5 => foo(), 2548 _ => bar, 2549 } 2550 2551 match lorem { 2552 1..=5 => foo(), 2553 _ => bar, 2554 } 2555 2556 match lorem { 2557 1...5 => foo(), 2558 _ => bar, 2559 } 2560} 2561``` 2562 2563#### `true`: 2564 2565```rust 2566fn main() { 2567 let lorem = 0 .. 10; 2568 let ipsum = 0 ..= 10; 2569 2570 match lorem { 2571 1 .. 5 => foo(), 2572 _ => bar, 2573 } 2574 2575 match lorem { 2576 1 ..= 5 => foo(), 2577 _ => bar, 2578 } 2579 2580 match lorem { 2581 1 ... 5 => foo(), 2582 _ => bar, 2583 } 2584} 2585``` 2586 2587## `struct_field_align_threshold` 2588 2589The maximum diff of width between struct fields to be aligned with each other. 2590 2591- **Default value** : 0 2592- **Possible values**: any non-negative integer 2593- **Stable**: No (tracking issue: [#3371](https://github.com/rust-lang/rustfmt/issues/3371)) 2594 2595#### `0` (default): 2596 2597```rust 2598struct Foo { 2599 x: u32, 2600 yy: u32, 2601 zzz: u32, 2602} 2603``` 2604 2605#### `20`: 2606 2607```rust 2608struct Foo { 2609 x: u32, 2610 yy: u32, 2611 zzz: u32, 2612} 2613``` 2614 2615## `struct_lit_single_line` 2616 2617Put small struct literals on a single line 2618 2619- **Default value**: `true` 2620- **Possible values**: `true`, `false` 2621- **Stable**: No (tracking issue: [#3357](https://github.com/rust-lang/rustfmt/issues/3357)) 2622 2623#### `true` (default): 2624 2625```rust 2626fn main() { 2627 let lorem = Lorem { foo: bar, baz: ofo }; 2628} 2629``` 2630 2631#### `false`: 2632 2633```rust 2634fn main() { 2635 let lorem = Lorem { 2636 foo: bar, 2637 baz: ofo, 2638 }; 2639} 2640``` 2641 2642See also: [`indent_style`](#indent_style). 2643 2644## `struct_lit_width` 2645 2646Maximum 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`. 2647 2648- **Default value**: `18` 2649- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 2650- **Stable**: Yes 2651 2652By 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. 2653 2654See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line) 2655 2656## `struct_variant_width` 2657 2658Maximum 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`. 2659 2660- **Default value**: `35` 2661- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) 2662- **Stable**: Yes 2663 2664By 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. 2665 2666See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) 2667 2668## `tab_spaces` 2669 2670Number of spaces per tab 2671 2672- **Default value**: `4` 2673- **Possible values**: any positive integer 2674- **Stable**: Yes 2675 2676#### `4` (default): 2677 2678```rust 2679fn lorem() { 2680 let ipsum = dolor(); 2681 let sit = vec![ 2682 "amet consectetur adipiscing elit amet", 2683 "consectetur adipiscing elit amet consectetur.", 2684 ]; 2685} 2686``` 2687 2688#### `2`: 2689 2690```rust 2691fn lorem() { 2692 let ipsum = dolor(); 2693 let sit = vec![ 2694 "amet consectetur adipiscing elit amet", 2695 "consectetur adipiscing elit amet consectetur.", 2696 ]; 2697} 2698``` 2699 2700See also: [`hard_tabs`](#hard_tabs). 2701 2702 2703## `trailing_comma` 2704 2705How to handle trailing commas for lists 2706 2707- **Default value**: `"Vertical"` 2708- **Possible values**: `"Always"`, `"Never"`, `"Vertical"` 2709- **Stable**: No (tracking issue: [#3379](https://github.com/rust-lang/rustfmt/issues/3379)) 2710 2711#### `"Vertical"` (default): 2712 2713```rust 2714fn main() { 2715 let Lorem { ipsum, dolor, sit } = amet; 2716 let Lorem { 2717 ipsum, 2718 dolor, 2719 sit, 2720 amet, 2721 consectetur, 2722 adipiscing, 2723 } = elit; 2724} 2725``` 2726 2727#### `"Always"`: 2728 2729```rust 2730fn main() { 2731 let Lorem { ipsum, dolor, sit, } = amet; 2732 let Lorem { 2733 ipsum, 2734 dolor, 2735 sit, 2736 amet, 2737 consectetur, 2738 adipiscing, 2739 } = elit; 2740} 2741``` 2742 2743#### `"Never"`: 2744 2745```rust 2746fn main() { 2747 let Lorem { ipsum, dolor, sit } = amet; 2748 let Lorem { 2749 ipsum, 2750 dolor, 2751 sit, 2752 amet, 2753 consectetur, 2754 adipiscing 2755 } = elit; 2756} 2757``` 2758 2759See also: [`match_block_trailing_comma`](#match_block_trailing_comma). 2760 2761## `trailing_semicolon` 2762 2763Add trailing semicolon after break, continue and return 2764 2765- **Default value**: `true` 2766- **Possible values**: `true`, `false` 2767- **Stable**: No (tracking issue: [#3378](https://github.com/rust-lang/rustfmt/issues/3378)) 2768 2769#### `true` (default): 2770```rust 2771fn foo() -> usize { 2772 return 0; 2773} 2774``` 2775 2776#### `false`: 2777```rust 2778fn foo() -> usize { 2779 return 0 2780} 2781``` 2782 2783## `type_punctuation_density` 2784 2785Determines if `+` or `=` are wrapped in spaces in the punctuation of types 2786 2787- **Default value**: `"Wide"` 2788- **Possible values**: `"Compressed"`, `"Wide"` 2789- **Stable**: No (tracking issue: [#3364](https://github.com/rust-lang/rustfmt/issues/3364)) 2790 2791#### `"Wide"` (default): 2792 2793```rust 2794fn lorem<Ipsum: Dolor + Sit = Amet>() { 2795 // body 2796} 2797``` 2798 2799#### `"Compressed"`: 2800 2801```rust 2802fn lorem<Ipsum: Dolor+Sit=Amet>() { 2803 // body 2804} 2805``` 2806 2807## `unstable_features` 2808 2809Enable unstable features on the unstable channel. 2810 2811- **Default value**: `false` 2812- **Possible values**: `true`, `false` 2813- **Stable**: No (tracking issue: [#3387](https://github.com/rust-lang/rustfmt/issues/3387)) 2814 2815## `use_field_init_shorthand` 2816 2817Use field initialize shorthand if possible. 2818 2819- **Default value**: `false` 2820- **Possible values**: `true`, `false` 2821- **Stable**: Yes 2822 2823#### `false` (default): 2824 2825```rust 2826struct Foo { 2827 x: u32, 2828 y: u32, 2829 z: u32, 2830} 2831 2832fn main() { 2833 let x = 1; 2834 let y = 2; 2835 let z = 3; 2836 let a = Foo { x, y, z }; 2837 let b = Foo { x: x, y: y, z: z }; 2838} 2839``` 2840 2841#### `true`: 2842 2843```rust 2844struct Foo { 2845 x: u32, 2846 y: u32, 2847 z: u32, 2848} 2849 2850fn main() { 2851 let x = 1; 2852 let y = 2; 2853 let z = 3; 2854 let a = Foo { x, y, z }; 2855} 2856``` 2857 2858## `use_small_heuristics` 2859 2860This 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. 2861 2862Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`. 2863 2864- **Default value**: `"Default"` 2865- **Possible values**: `"Default"`, `"Off"`, `"Max"` 2866- **Stable**: Yes 2867 2868#### `Default` (default): 2869When `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`. 2870 2871The ratios are: 2872* [`fn_call_width`](#fn_call_width) - `60%` 2873* [`attr_fn_like_width`](#attr_fn_like_width) - `70%` 2874* [`struct_lit_width`](#struct_lit_width) - `18%` 2875* [`struct_variant_width`](#struct_variant_width) - `35%` 2876* [`array_width`](#array_width) - `60%` 2877* [`chain_width`](#chain_width) - `60%` 2878* [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%` 2879* [`single_line_let_else_max_width`](#single_line_let_else_max_width) - `50%` 2880 2881For example when `max_width` is set to `100`, the width settings are: 2882* `fn_call_width=60` 2883* `attr_fn_like_width=70` 2884* `struct_lit_width=18` 2885* `struct_variant_width=35` 2886* `array_width=60` 2887* `chain_width=60` 2888* `single_line_if_else_max_width=50` 2889* `single_line_let_else_max_width=50` 2890 2891and when `max_width` is set to `200`: 2892* `fn_call_width=120` 2893* `attr_fn_like_width=140` 2894* `struct_lit_width=36` 2895* `struct_variant_width=70` 2896* `array_width=120` 2897* `chain_width=120` 2898* `single_line_if_else_max_width=100` 2899* `single_line_let_else_max_width=100` 2900 2901```rust 2902enum Lorem { 2903 Ipsum, 2904 Dolor(bool), 2905 Sit { amet: Consectetur, adipiscing: Elit }, 2906} 2907 2908fn main() { 2909 lorem( 2910 "lorem", 2911 "ipsum", 2912 "dolor", 2913 "sit", 2914 "amet", 2915 "consectetur", 2916 "adipiscing", 2917 ); 2918 2919 let lorem = Lorem { 2920 ipsum: dolor, 2921 sit: amet, 2922 }; 2923 let lorem = Lorem { ipsum: dolor }; 2924 2925 let lorem = if ipsum { dolor } else { sit }; 2926} 2927``` 2928 2929#### `Off`: 2930When `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. 2931 2932```rust 2933enum Lorem { 2934 Ipsum, 2935 Dolor(bool), 2936 Sit { 2937 amet: Consectetur, 2938 adipiscing: Elit, 2939 }, 2940} 2941 2942fn main() { 2943 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing"); 2944 2945 let lorem = Lorem { 2946 ipsum: dolor, 2947 sit: amet, 2948 }; 2949 2950 let lorem = if ipsum { 2951 dolor 2952 } else { 2953 sit 2954 }; 2955} 2956``` 2957 2958#### `Max`: 2959When `use_small_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`. 2960 2961So if `max_width` is set to `200`, then all the width settings are also set to `200`. 2962* `fn_call_width=200` 2963* `attr_fn_like_width=200` 2964* `struct_lit_width=200` 2965* `struct_variant_width=200` 2966* `array_width=200` 2967* `chain_width=200` 2968* `single_line_if_else_max_width=200` 2969* `single_line_let_else_max_width=200` 2970 2971```rust 2972enum Lorem { 2973 Ipsum, 2974 Dolor(bool), 2975 Sit { amet: Consectetur, adipiscing: Elit }, 2976} 2977 2978fn main() { 2979 lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing"); 2980 2981 let lorem = Lorem { ipsum: dolor, sit: amet }; 2982 2983 let lorem = if ipsum { dolor } else { sit }; 2984} 2985``` 2986 2987 2988See also: 2989* [`max_width`](#max_width) 2990* [`fn_call_width`](#fn_call_width) 2991* [`attr_fn_like_width`](#attr_fn_like_width) 2992* [`struct_lit_width`](#struct_lit_width) 2993* [`struct_variant_width`](#struct_variant_width) 2994* [`array_width`](#array_width) 2995* [`chain_width`](#chain_width) 2996* [`single_line_if_else_max_width`](#single_line_if_else_max_width) 2997* [`single_line_let_else_max_width`](#single_line_let_else_max_width) 2998 2999## `use_try_shorthand` 3000 3001Replace uses of the try! macro by the ? shorthand 3002 3003- **Default value**: `false` 3004- **Possible values**: `true`, `false` 3005- **Stable**: Yes 3006 3007#### `false` (default): 3008 3009```rust 3010fn main() { 3011 let lorem = ipsum.map(|dolor| dolor.sit())?; 3012 3013 let lorem = try!(ipsum.map(|dolor| dolor.sit())); 3014} 3015``` 3016 3017#### `true`: 3018 3019```rust 3020fn main() { 3021 let lorem = ipsum.map(|dolor| dolor.sit())?; 3022} 3023``` 3024 3025## `version` 3026 3027Which version of the formatting rules to use. `Version::One` is backwards-compatible 3028with Rustfmt 1.0. Other versions are only backwards compatible within a major 3029version number. 3030 3031- **Default value**: `One` 3032- **Possible values**: `One`, `Two` 3033- **Stable**: No (tracking issue: [#3383](https://github.com/rust-lang/rustfmt/issues/3383)) 3034 3035### Example 3036 3037```toml 3038version = "Two" 3039``` 3040 3041## `where_single_line` 3042 3043Forces the `where` clause to be laid out on a single line. 3044 3045- **Default value**: `false` 3046- **Possible values**: `true`, `false` 3047- **Stable**: No (tracking issue: [#3359](https://github.com/rust-lang/rustfmt/issues/3359)) 3048 3049#### `false` (default): 3050 3051```rust 3052impl<T> Lorem for T 3053where 3054 Option<T>: Ipsum, 3055{ 3056 // body 3057} 3058``` 3059 3060#### `true`: 3061 3062```rust 3063impl<T> Lorem for T 3064where Option<T>: Ipsum 3065{ 3066 // body 3067} 3068``` 3069 3070See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style). 3071 3072 3073## `wrap_comments` 3074 3075Break comments to fit on the line 3076 3077Note that no wrapping will happen if: 30781. The comment is the start of a markdown header doc comment 30792. An URL was found in the comment 3080 3081- **Default value**: `false` 3082- **Possible values**: `true`, `false` 3083- **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347)) 3084 3085#### `false` (default): 3086 3087```rust 3088// Lorem ipsum dolor sit amet, consectetur adipiscing elit, 3089// sed do eiusmod tempor incididunt ut labore et dolore 3090// magna aliqua. Ut enim ad minim veniam, quis nostrud 3091// exercitation ullamco laboris nisi ut aliquip ex ea 3092// commodo consequat. 3093 3094// 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. 3095 3096// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. 3097 3098/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it. 3099struct Foo {} 3100``` 3101 3102#### `true`: 3103 3104```rust 3105// Lorem ipsum dolor sit amet, consectetur adipiscing elit, 3106// sed do eiusmod tempor incididunt ut labore et dolore 3107// magna aliqua. Ut enim ad minim veniam, quis nostrud 3108// exercitation ullamco laboris nisi ut aliquip ex ea 3109// commodo consequat. 3110 3111// Lorem ipsum dolor sit amet, consectetur adipiscing elit, 3112// sed do eiusmod tempor incididunt ut labore et dolore 3113// magna aliqua. Ut enim ad minim veniam, quis nostrud 3114// exercitation ullamco laboris nisi ut aliquip ex ea 3115// commodo consequat. 3116 3117// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. 3118 3119/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it. 3120struct Foo {} 3121``` 3122 3123# Internal Options 3124 3125## `emit_mode` 3126 3127Internal option 3128 3129## `make_backup` 3130 3131Internal option, use `--backup` 3132 3133## `print_misformatted_file_names` 3134 3135Internal option, use `-l` or `--files-with-diff` 3136