X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=Configurations.md;h=9b59b19acc5f18f5a90ce0d78cef7cd9941f67c6;hb=70fe8ee3904ff0858f2cb2c379ecd2276e6f3893;hp=8ace886a98f7dd7a38d15906b5dadae8e769b425;hpb=911395a45198fa18708da6622b11c4c16a5e52a2;p=rust.git diff --git a/Configurations.md b/Configurations.md index 8ace886a98f..9b59b19acc5 100644 --- a/Configurations.md +++ b/Configurations.md @@ -64,7 +64,12 @@ fn main() { ```rust fn main() { - if lorem_ipsum && dolor_sit && amet_consectetur && lorem_sit && dolor_consectetur && amet_ipsum + if lorem_ipsum + && dolor_sit + && amet_consectetur + && lorem_sit + && dolor_consectetur + && amet_ipsum && lorem_consectetur { // ... @@ -76,7 +81,12 @@ fn main() { ```rust fn main() { - if lorem_ipsum && dolor_sit && amet_consectetur && lorem_sit && dolor_consectetur && amet_ipsum + if lorem_ipsum + && dolor_sit + && amet_consectetur + && lorem_sit + && dolor_consectetur + && amet_ipsum && lorem_consectetur { // ... @@ -226,7 +236,7 @@ fn main() { ```rust fn main() { let lorem = Lorem { ipsum: dolor, - sit: amet, }; + sit: amet }; } ``` @@ -265,11 +275,11 @@ fn lorem() -> T Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'. -- **Default value**: `true` -- **Possible values**: `true`, `false` -- **Stable**: No +- **Default value**: `Default` +- **Possible values**: `Default`, `Off`, `Max` +- **Stable**: Yes -#### `true` (default): +#### `Default` (default): ```rust enum Lorem { @@ -299,7 +309,7 @@ fn main() { } ``` -#### `false`: +#### `Off`: ```rust enum Lorem { @@ -327,6 +337,24 @@ fn main() { } ``` +#### `Max`: + +```rust +enum Lorem { + Ipsum, + Dolor(bool), + Sit { amet: Consectetur, adipiscing: Elit }, +} + +fn main() { + lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing"); + + let lorem = Lorem { ipsum: dolor, sit: amet }; + + let lorem = if ipsum { dolor } else { sit }; +} +``` + ## `binop_separator` Where to put a binary operator when a binary expression goes multiline. @@ -342,7 +370,8 @@ fn main() { let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar; - let sum = 123456789012345678901234567890 + 123456789012345678901234567890 + let sum = 123456789012345678901234567890 + + 123456789012345678901234567890 + 123456789012345678901234567890; let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa @@ -357,7 +386,8 @@ fn main() { let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo || barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar; - let sum = 123456789012345678901234567890 + 123456789012345678901234567890 + + let sum = 123456789012345678901234567890 + + 123456789012345678901234567890 + 123456789012345678901234567890; let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. @@ -855,6 +885,53 @@ impl Lorem { See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style). +## `enum_discrim_align_threshold` + +The maximum length of enum variant having discriminant, that gets vertically aligned with others. +Variants without discriminants would be ignored for the purpose of alignment. + +Note that this is not how much whitespace is inserted, but instead the longest variant name that +doesn't get ignored when aligning. + +- **Default value** : 0 +- **Possible values**: any positive integer +- **Stable**: No + +#### `0` (default): + +```rust +enum Bar { + A = 0, + Bb = 1, + RandomLongVariantGoesHere = 10, + Ccc = 71, +} + +enum Bar { + VeryLongVariantNameHereA = 0, + VeryLongVariantNameHereBb = 1, + VeryLongVariantNameHereCcc = 2, +} +``` + +#### `20`: + +```rust +enum Foo { + A = 0, + Bb = 1, + RandomLongVariantGoesHere = 10, + Ccc = 2, +} + +enum Bar { + VeryLongVariantNameHereA = 0, + VeryLongVariantNameHereBb = 1, + VeryLongVariantNameHereCcc = 2, +} +``` + + ## `fn_single_line` Put single-expression functions on a single line @@ -976,6 +1053,76 @@ fn main() { See also [`max_width`](#max_width). +## `format_macro_matchers` + +Format the metavariable matching patterns in macros. + +- **Default value**: `false` +- **Possible values**: `true`, `false` +- **Stable**: No + +#### `false` (default): + +```rust +macro_rules! foo { + ($a: ident : $b: ty) => { + $a(42): $b; + }; + ($a: ident $b: ident $c: ident) => { + $a = $b + $c; + }; +} +``` + +#### `true`: + +```rust +macro_rules! foo { + ($a:ident : $b:ty) => { + $a(42): $b; + }; + ($a:ident $b:ident $c:ident) => { + $a = $b + $c; + }; +} +``` + +See also [`format_macro_bodies`](#format_macro_bodies). + + +## `format_macro_bodies` + +Format the bodies of macros. + +- **Default value**: `true` +- **Possible values**: `true`, `false` +- **Stable**: No + +#### `true` (default): + +```rust +macro_rules! foo { + ($a: ident : $b: ty) => { + $a(42): $b; + }; + ($a: ident $b: ident $c: ident) => { + $a = $b + $c; + }; +} +``` + +#### `false`: + +```rust +macro_rules! foo { + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; +} +``` + +See also [`format_macro_matchers`](#format_macro_matchers). + + ## `hard_tabs` Use tab characters for indentation, spaces for alignment @@ -1007,18 +1154,11 @@ See also: [`tab_spaces`](#tab_spaces). Indent style of imports -- **Default Value**: `"Visual"` +- **Default Value**: `"Block"` - **Possible values**: `"Block"`, `"Visual"` - **Stable**: No -#### `"Visual"` (default): - -```rust -use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, - zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}; -``` - -#### `"Block"`: +#### `"Block"` (default): ```rust use foo::{ @@ -1027,6 +1167,13 @@ use foo::{ }; ``` +#### `"Visual"`: + +```rust +use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, + zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}; +``` + See also: [`imports_layout`](#imports_layout). ## `imports_layout` @@ -1042,8 +1189,10 @@ Item layout inside a imports block ```rust use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; -use foo::{aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd, - eeeeeeeeeeeeeeeeee, ffffffffffffffffff}; +use foo::{ + aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd, + eeeeeeeeeeeeeeeeee, ffffffffffffffffff, +}; ``` #### `"Horizontal"`: @@ -1061,27 +1210,55 @@ use foo::{aaa, bbb, ccc, ddd, eee, fff}; ```rust use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; -use foo::{aaaaaaaaaaaaaaaaaa, - bbbbbbbbbbbbbbbbbb, - cccccccccccccccccc, - dddddddddddddddddd, - eeeeeeeeeeeeeeeeee, - ffffffffffffffffff}; +use foo::{ + aaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbb, + cccccccccccccccccc, + dddddddddddddddddd, + eeeeeeeeeeeeeeeeee, + ffffffffffffffffff, +}; ``` #### `"Vertical"`: ```rust -use foo::{xxx, - yyy, - zzz}; +use foo::{ + xxx, + yyy, + zzz, +}; -use foo::{aaa, - bbb, - ccc, - ddd, - eee, - fff}; +use foo::{ + aaa, + bbb, + ccc, + ddd, + eee, + fff, +}; +``` + +## `merge_imports` + +Merge multiple imports into a single nested import. + +- **Default value**: `false` +- **Possible values**: `true`, `false` +- **Stable**: No + +#### `false` (default): + +```rust +use foo::{a, c, d}; +use foo::{b, g}; +use foo::{e, f}; +``` + +#### `true`: + +```rust +use foo::{a, b, c, d, e, f, g}; ``` @@ -1173,7 +1350,7 @@ fn main() { }); match lorem { - None => if ipsum { + None => |ipsum| { println!("Hello World"); }, Some(dolor) => foo(), @@ -1194,7 +1371,7 @@ fn main() { match lorem { None => { - if ipsum { + |ipsum| { println!("Hello World"); } } @@ -1208,17 +1385,36 @@ fn main() { Unix or Windows line endings -- **Default value**: `"Unix"` -- **Possible values**: `"Native"`, `"Unix"`, `"Windows"` +- **Default value**: `"Auto"` +- **Possible values**: `"Auto"`, `"Native"`, `"Unix"`, `"Windows"` - **Stable**: Yes +#### `Auto` (default): + +The newline style is detected automatically on a per-file basis. Files +with mixed line endings will be converted to the first detected line +ending style. + +#### `Native` + +Line endings will be converted to `\r\n` on Windows and `\n` on all +other platforms. + +#### `Unix` + +Line endings will be converted to `\n`. + +#### `Windows` + +Line endings will be converted to `\r\n`. + ## `normalize_comments` Convert /* */ comments to // comments where possible - **Default value**: `false` - **Possible values**: `true`, `false` -- **Stable**: Yes +- **Stable**: No #### `false` (default): @@ -1240,30 +1436,54 @@ fn dolor() -> usize {} fn adipiscing() -> usize {} ``` +## `remove_nested_parens` + +Remove nested parens. + +- **Default value**: `true`, +- **Possible values**: `true`, `false` +- **Stable**: Yes + + +#### `true` (default): +```rust +fn main() { + (foo()); +} +``` + +#### `false`: +```rust +fn main() { + ((((foo())))); +} +``` + ## `reorder_imports` -Reorder import and extern crate statements alphabetically +Reorder import and extern crate statements alphabetically in groups (a group is +separated by a newline). -- **Default value**: `false` +- **Default value**: `true` - **Possible values**: `true`, `false` -- **Stable**: No +- **Stable**: Yes -#### `false` (default): +#### `true` (default): ```rust -use lorem; -use ipsum; use dolor; +use ipsum; +use lorem; use sit; ``` -#### `true`: +#### `false`: ```rust -use dolor; -use ipsum; use lorem; +use ipsum; +use dolor; use sit; ``` @@ -1274,7 +1494,7 @@ Reorder `mod` declarations alphabetically in group. - **Default value**: `true` - **Possible values**: `true`, `false` -- **Stable**: No +- **Stable**: Yes #### `true` (default) @@ -1524,52 +1744,6 @@ fn main() { } ``` -## `spaces_within_parens_and_brackets` - -Put spaces within non-empty generic arguments, parentheses, and square brackets - -- **Default value**: `false` -- **Possible values**: `true`, `false` -- **Stable**: No - -#### `false` (default): - -```rust -// generic arguments -fn lorem(t: T) { - // body -} - -// non-empty parentheses -fn lorem(t: T) { - let lorem = (ipsum, dolor); -} - -// non-empty square brackets -fn lorem(t: T) { - let lorem: [usize; 2] = [ipsum, dolor]; -} -``` - -#### `true`: - -```rust -// generic arguments -fn lorem< T: Eq >( t: T ) { - // body -} - -// non-empty parentheses -fn lorem< T: Eq >( t: T ) { - let lorem = ( ipsum, dolor ); -} - -// non-empty square brackets -fn lorem< T: Eq >( t: T ) { - let lorem: [ usize; 2 ] = [ ipsum, dolor ]; -} -``` - ## `struct_lit_single_line` Put small struct literals on a single line @@ -1745,7 +1919,7 @@ Use field initialize shorthand if possible. - **Default value**: `false` - **Possible values**: `true`, `false` -- **Stable**: No +- **Stable**: Yes #### `false` (default): @@ -1787,7 +1961,7 @@ Replace uses of the try! macro by the ? shorthand - **Default value**: `false` - **Possible values**: `true`, `false` -- **Stable**: No +- **Stable**: Yes #### `false` (default): @@ -1805,6 +1979,56 @@ fn main() { } ``` +## `format_doc_comments` + +Format doc comments. + +- **Default value**: `false` +- **Possible values**: `true`, `false` +- **Stable**: No + +#### `false` (default): + +```rust +/// Adds one to the number given. +/// +/// # Examples +/// +/// ```rust +/// let five=5; +/// +/// assert_eq!( +/// 6, +/// add_one(5) +/// ); +/// # fn add_one(x: i32) -> i32 { +/// # x + 1 +/// # } +/// ``` +fn add_one(x: i32) -> i32 { + x + 1 +} +``` + +#### `true` + +```rust +/// Adds one to the number given. +/// +/// # Examples +/// +/// ```rust +/// let five = 5; +/// +/// assert_eq!(6, add_one(5)); +/// # fn add_one(x: i32) -> i32 { +/// # x + 1 +/// # } +/// ``` +fn add_one(x: i32) -> i32 { + x + 1 +} +``` ## `wrap_comments` @@ -1812,7 +2036,7 @@ Break comments to fit on the line - **Default value**: `false` - **Possible values**: `true`, `false` -- **Stable**: Yes +- **Stable**: No #### `false` (default): @@ -1865,14 +2089,89 @@ fn main() { See also: [`match_block_trailing_comma`](#match_block_trailing_comma). -## `write_mode` +## `overflow_delimited_expr` -What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage +When structs, slices, arrays, and block/array-like macros are used as the last +argument in an expression list, allow them to overflow (like blocks/closures) +instead of being indented on a new line. -- **Default value**: `"Overwrite"` -- **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"` +- **Default value**: `false` +- **Possible values**: `true`, `false` - **Stable**: No +#### `false` (default): + +```rust +fn example() { + foo(ctx, |param| { + action(); + foo(param) + }); + + foo( + ctx, + Bar { + x: value, + y: value2, + }, + ); + + foo( + ctx, + &[ + MAROON_TOMATOES, + PURPLE_POTATOES, + ORGANE_ORANGES, + GREEN_PEARS, + RED_APPLES, + ], + ); + + foo( + ctx, + vec![ + MAROON_TOMATOES, + PURPLE_POTATOES, + ORGANE_ORANGES, + GREEN_PEARS, + RED_APPLES, + ], + ); +} +``` + +#### `true`: + +```rust +fn example() { + foo(ctx, |param| { + action(); + foo(param) + }); + + foo(ctx, Bar { + x: value, + y: value2, + }); + + foo(ctx, &[ + MAROON_TOMATOES, + PURPLE_POTATOES, + ORGANE_ORANGES, + GREEN_PEARS, + RED_APPLES, + ]); + + foo(ctx, vec![ + MAROON_TOMATOES, + PURPLE_POTATOES, + ORGANE_ORANGES, + GREEN_PEARS, + RED_APPLES, + ]); +} +``` + ## `blank_lines_upper_bound` Maximum number of blank lines which can be put between items. If more than this number of consecutive empty @@ -1886,7 +2185,7 @@ lines are found, they are trimmed down to match this integer. Original Code: ```rust -#![rustfmt_skip] +#![rustfmt::skip] fn foo() { println!("a"); @@ -1915,7 +2214,7 @@ fn bar() { } ``` -#### `2` (default): +#### `2`: ```rust fn foo() { println!("a"); @@ -1945,7 +2244,7 @@ them, additional blank lines are inserted. Original Code (rustfmt will not change it with the default value of `0`): ```rust -#![rustfmt_skip] +#![rustfmt::skip] fn foo() { println!("a"); @@ -1971,49 +2270,10 @@ fn bar() { } ``` -## `remove_blank_lines_at_start_or_end_of_block` - -Remove blank lines at the start or the end of a block. - -- **Default value**: `true` -- **Possible values**: `true`, `false` -- **Stable**: No - -#### `true` - -```rust -fn foo() { - let msg = { - let mut str = String::new(); - str.push_str("hello, "); - str.push_str("world!"); - str - }; - println!("{}", msg); -} -``` - -#### `false` - -```rust -fn foo() { - - let msg = { - - let mut str = String::new(); - str.push_str("hello, "); - str.push_str("world!"); - str - - }; - println!("{}", msg); - -} -``` ## `required_version` -Require a specific version of rustfmt. If you want to make sure that the +Require a specific version of rustfmt. If you want to make sure that the specific version of rustfmt is used in your CI, use this option. - **Default value**: `CARGO_PKG_VERSION` @@ -2042,7 +2302,7 @@ Enable unstable features on stable channel. - **Default value**: `false` - **Possible values**: `true`, `false` -- **Stable**: Yes +- **Stable**: No ## `license_template_path` @@ -2086,7 +2346,73 @@ ignore = [ If you want to ignore every file under `examples/`, put the following to your config file: ```toml -ignore [ +ignore = [ "examples", ] ``` + +## `edition` + +Specifies which edition is used by the parser. + +- **Default value**: `2015` +- **Possible values**: `2015`, `2018` +- **Stable**: Yes + +### Example + +If you want to format code that requires edition 2018, add the following to your config file: + +```toml +edition = "2018" +``` + +## `version` + +Which version of the formatting rules to use. `Version::One` is backwards-compatible +with Rustfmt 1.0. Other versions are only backwards compatible within a major +version number. + +- **Default value**: `One` +- **Possible values**: `One`, `Two` +- **Stable**: No + +### Example + +```toml +version = "Two" +``` + +## `normalize_doc_attributes` + +Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments. + +- **Default value**: `false` +- **Possible values**: `true`, `false` +- **Stable**: No + +#### `false` (default): + +```rust +#![doc = "Example documentation"] + +#[doc = "Example item documentation"] +pub enum Foo {} +``` + +#### `true`: + +```rust +//! Example documentation + +/// Example item documentation +pub enum Foo {} +``` + +## `emit_mode` + +Internal option + +## `make_backup` + +Internal option, use `--backup`