2017-04-26 10:36:10 -05:00
# Configuring Rustfmt
2019-01-14 04:20:46 -06:00
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.
2017-04-26 10:36:10 -05:00
A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
```toml
2017-11-13 01:52:40 -06:00
indent_style = "Block"
2018-03-11 23:24:04 -05:00
reorder_imports = false
2017-04-26 10:36:10 -05:00
```
2017-12-02 19:52:48 -06:00
Each configuration option is either stable or unstable.
2022-05-23 04:07:19 -05:00
Stable options can always be used, while unstable options are only available on a nightly toolchain and must be opted into.
2018-02-12 23:48:57 -06:00
To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or pass `--unstable-features` to rustfmt.
2017-12-02 19:52:48 -06:00
2017-04-26 10:36:10 -05:00
# Configuration Options
Below you find a detailed visual guide on all the supported configuration options of rustfmt:
2021-06-21 04:11:37 -05:00
## `array_width`
2020-02-22 22:01:48 -06:00
Maximum width of an array literal before falling back to vertical formatting.
- **Default value**: `60`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `array_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ) and [`use_small_heuristics` ](#use_small_heuristics )
2021-06-21 04:11:37 -05:00
## `attr_fn_like_width`
2020-02-22 22:01:48 -06:00
Maximum width of the args of a function-like attributes before falling back to vertical formatting.
- **Default value**: `70`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `attr_fn_like_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ) and [`use_small_heuristics` ](#use_small_heuristics )
2017-07-05 08:51:52 -05:00
2019-08-05 21:07:12 -05:00
## `binop_separator`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Where to put a binary operator when a binary expression goes multiline.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"Front"`
- **Possible values**: `"Front"` , `"Back"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3368 ](https://github.com/rust-lang/rustfmt/issues/3368 ))
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
#### `"Front"` (default):
2017-04-26 10:36:10 -05:00
```rust
2018-01-10 20:27:43 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
|| barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
let sum = 123456789012345678901234567890
+ 123456789012345678901234567890
+ 123456789012345678901234567890;
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
2018-01-10 20:30:17 -06:00
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `"Back"`:
2017-11-13 01:52:40 -06:00
```rust
2018-02-11 16:48:45 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
let sum = 123456789012345678901234567890 +
123456789012345678901234567890 +
123456789012345678901234567890;
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
2017-11-13 01:52:40 -06:00
}
```
2019-08-05 21:07:12 -05:00
## `blank_lines_lower_bound`
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
Minimum number of blank lines which must be put between items. If two items have fewer blank lines between
them, additional blank lines are inserted.
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `0`
- **Possible values**: *unsigned integer*
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3382 ](https://github.com/rust-lang/rustfmt/issues/3382 ))
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
### Example
Original Code (rustfmt will not change it with the default value of `0` ):
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
```rust
#![rustfmt::skip]
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
fn foo() {
println!("a");
}
fn bar() {
println!("b");
println!("c");
2017-11-13 01:52:40 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `1`
2017-11-13 01:52:40 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn foo() {
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
println!("a");
2017-11-13 01:52:40 -06:00
}
2019-08-05 21:07:12 -05:00
fn bar() {
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
println!("b");
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
println!("c");
2018-01-13 20:56:35 -06:00
}
2017-11-13 01:52:40 -06:00
```
2019-08-05 21:07:12 -05:00
## `blank_lines_upper_bound`
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
Maximum number of blank lines which can be put between items. If more than this number of consecutive empty
lines are found, they are trimmed down to match this integer.
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `1`
- **Possible values**: any non-negative integer
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3381 ](https://github.com/rust-lang/rustfmt/issues/3381 ))
2019-08-05 21:07:12 -05:00
### Example
Original Code:
2017-11-13 01:52:40 -06:00
```rust
2019-08-05 21:07:12 -05:00
#![rustfmt::skip]
fn foo() {
println!("a");
2017-11-13 01:52:40 -06:00
}
2019-08-05 21:07:12 -05:00
fn bar() {
println!("b");
println!("c");
2017-11-13 01:52:40 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `1` (default):
```rust
fn foo() {
println!("a");
}
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
fn bar() {
println!("b");
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
println!("c");
2018-01-13 21:44:03 -06:00
}
2017-11-13 01:52:40 -06:00
```
2019-08-05 21:07:12 -05:00
#### `2`:
2017-11-13 01:52:40 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn foo() {
println!("a");
2018-01-13 21:45:31 -06:00
}
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
fn bar() {
println!("b");
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
println!("c");
2017-11-13 01:52:40 -06:00
}
```
2019-08-05 21:07:12 -05:00
See also: [`blank_lines_lower_bound` ](#blank_lines_lower_bound )
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
## `brace_style`
2017-11-13 01:52:40 -06:00
2019-08-05 21:07:12 -05:00
Brace style for items
2017-11-24 01:17:06 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"SameLineWhere"`
- **Possible values**: `"AlwaysNextLine"` , `"PreferSameLine"` , `"SameLineWhere"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3376 ](https://github.com/rust-lang/rustfmt/issues/3376 ))
2017-11-24 01:17:06 -06:00
2019-08-05 21:07:12 -05:00
### Functions
2017-11-24 01:17:06 -06:00
2019-08-05 21:07:12 -05:00
#### `"SameLineWhere"` (default):
2017-11-24 01:17:06 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() {
// body
2017-11-24 01:17:06 -06:00
}
2019-08-05 21:07:12 -05:00
fn lorem(ipsum: usize) {
// body
}
2017-11-24 01:17:06 -06:00
2019-08-05 21:07:12 -05:00
fn lorem< T > (ipsum: T)
where
T: Add + Sub + Mul + Div,
{
// body
2017-11-24 01:17:06 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `"AlwaysNextLine"`:
2017-11-24 01:17:06 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem()
{
// body
2017-11-24 01:17:06 -06:00
}
2019-08-05 21:07:12 -05:00
fn lorem(ipsum: usize)
{
// body
}
2017-11-24 01:17:06 -06:00
2019-08-05 21:07:12 -05:00
fn lorem< T > (ipsum: T)
where
T: Add + Sub + Mul + Div,
{
// body
2017-11-24 01:17:06 -06:00
}
```
2017-11-23 19:29:44 -06:00
2019-08-05 21:07:12 -05:00
#### `"PreferSameLine"`:
2018-07-17 12:17:04 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() {
// body
2018-07-17 12:17:04 -05:00
}
2019-08-05 21:07:12 -05:00
fn lorem(ipsum: usize) {
// body
}
2018-07-17 12:17:04 -05:00
2019-08-05 21:07:12 -05:00
fn lorem< T > (ipsum: T)
where
T: Add + Sub + Mul + Div, {
// body
2018-07-17 12:17:04 -05:00
}
```
2019-08-05 21:07:12 -05:00
### Structs and enums
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
#### `"SameLineWhere"` (default):
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
```rust
struct Lorem {
ipsum: bool,
}
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
struct Dolor< T >
where
T: Eq,
{
sit: T,
}
```
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
#### `"AlwaysNextLine"`:
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
```rust
struct Lorem
{
ipsum: bool,
}
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
struct Dolor< T >
where
T: Eq,
{
sit: T,
2018-01-13 23:10:57 -06:00
}
2017-09-15 01:10:34 -05:00
```
2019-08-05 21:07:12 -05:00
#### `"PreferSameLine"`:
2017-09-15 01:10:34 -05:00
```rust
2019-08-05 21:07:12 -05:00
struct Lorem {
ipsum: bool,
}
2017-09-15 01:10:34 -05:00
2019-08-05 21:07:12 -05:00
struct Dolor< T >
where
T: Eq, {
sit: T,
2018-01-14 14:26:26 -06:00
}
2017-09-15 01:10:34 -05:00
```
2021-06-21 04:11:37 -05:00
## `chain_width`
2020-02-22 22:01:48 -06:00
Maximum width of a chain to fit on one line.
- **Default value**: `60`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `chain_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ) and [`use_small_heuristics` ](#use_small_heuristics )
2019-08-05 21:07:12 -05:00
## `color`
Whether to use colored output or not.
- **Default value**: `"Auto"`
- **Possible values**: "Auto", "Always", "Never"
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3385 ](https://github.com/rust-lang/rustfmt/issues/3385 ))
2019-08-05 21:07:12 -05:00
2019-02-18 13:35:22 -06:00
## `combine_control_expr`
2017-06-03 08:50:13 -05:00
Combine control expressions with function calls.
- **Default value**: `true`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3369 ](https://github.com/rust-lang/rustfmt/issues/3369 ))
2017-06-03 08:50:13 -05:00
2017-09-18 20:28:51 -05:00
#### `true` (default):
2017-06-03 08:50:13 -05:00
```rust
fn example() {
// If
foo!(if x {
foo();
} else {
bar();
});
// IfLet
foo!(if let Some(..) = x {
foo();
} else {
bar();
});
// While
foo!(while x {
foo();
bar();
});
// WhileLet
foo!(while let Some(..) = x {
foo();
bar();
});
// ForLoop
foo!(for x in y {
foo();
bar();
});
// Loop
foo!(loop {
foo();
bar();
});
}
```
2017-09-18 20:28:51 -05:00
#### `false`:
2017-06-03 08:50:13 -05:00
```rust
2017-11-12 12:14:00 -06:00
fn example() {
// If
foo!(
if x {
foo();
} else {
bar();
}
);
// IfLet
foo!(
if let Some(..) = x {
foo();
} else {
bar();
}
);
// While
foo!(
while x {
foo();
bar();
}
);
// WhileLet
foo!(
while let Some(..) = x {
foo();
bar();
}
);
// ForLoop
foo!(
for x in y {
foo();
bar();
}
);
// Loop
foo!(
loop {
foo();
bar();
}
);
}
2017-06-03 08:50:13 -05:00
```
2019-02-18 13:35:22 -06:00
## `comment_width`
2017-04-26 10:36:10 -05:00
Maximum length of comments. No effect unless`wrap_comments = true`.
- **Default value**: `80`
- **Possible values**: any positive integer
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3349 ](https://github.com/rust-lang/rustfmt/issues/3349 ))
2017-04-26 10:36:10 -05:00
**Note:** A value of `0` results in [`wrap_comments` ](#wrap_comments ) being applied regardless of a line's width.
2017-12-13 02:40:07 -06:00
#### `80` (default; comments shorter than `comment_width`):
2017-04-26 10:36:10 -05:00
```rust
// Lorem ipsum dolor sit amet, consectetur adipiscing elit.
```
2017-12-13 02:40:07 -06:00
#### `60` (comments longer than `comment_width`):
2017-04-26 10:36:10 -05:00
```rust
// Lorem ipsum dolor sit amet,
// consectetur adipiscing elit.
```
See also [`wrap_comments` ](#wrap_comments ).
2019-02-18 13:35:22 -06:00
## `condense_wildcard_suffixes`
2017-04-26 10:36:10 -05:00
Replace strings of _ wildcards by a single .. in tuple patterns
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3384 ](https://github.com/rust-lang/rustfmt/issues/3384 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2018-01-14 18:45:10 -06:00
fn main() {
let (lorem, ipsum, _, _ ) = (1, 2, 3, 4);
let (lorem, ipsum, ..) = (1, 2, 3, 4);
}
2017-04-26 10:36:10 -05:00
```
#### `true`:
```rust
2018-01-14 18:45:38 -06:00
fn main() {
let (lorem, ipsum, ..) = (1, 2, 3, 4);
}
2017-04-26 10:36:10 -05:00
```
2019-02-18 13:35:22 -06:00
## `control_brace_style`
2017-04-26 10:36:10 -05:00
Brace style for control flow constructs
- **Default value**: `"AlwaysSameLine"`
- **Possible values**: `"AlwaysNextLine"` , `"AlwaysSameLine"` , `"ClosingNextLine"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3377 ](https://github.com/rust-lang/rustfmt/issues/3377 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `"AlwaysSameLine"` (default):
2017-04-26 10:36:10 -05:00
```rust
2018-01-14 18:47:17 -06:00
fn main() {
if lorem {
println!("ipsum!");
} else {
println!("dolor!");
}
2017-04-26 10:36:10 -05:00
}
```
2017-09-18 20:28:51 -05:00
#### `"AlwaysNextLine"`:
2017-04-26 10:36:10 -05:00
```rust
2018-01-14 18:49:30 -06:00
fn main() {
if lorem
{
println!("ipsum!");
}
else
{
println!("dolor!");
}
2017-04-26 10:36:10 -05:00
}
```
#### `"ClosingNextLine"`:
```rust
2018-01-14 18:51:31 -06:00
fn main() {
if lorem {
println!("ipsum!");
}
else {
println!("dolor!");
}
2017-04-26 10:36:10 -05:00
}
```
2019-02-18 13:35:22 -06:00
## `disable_all_formatting`
2017-04-26 10:36:10 -05:00
2021-10-20 00:11:59 -05:00
Don't reformat anything.
Note that this option may be soft-deprecated in the future once the [ignore ](#ignore ) option is stabilized. Nightly toolchain users are encouraged to use [ignore ](#ignore ) instead when possible.
2017-04-26 10:36:10 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-10-20 00:11:59 -05:00
- **Stable**: Yes
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `edition`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Specifies which edition is used by the parser.
2017-04-26 10:36:10 -05:00
2021-01-01 10:00:40 -06:00
- **Default value**: `"2015"`
- **Possible values**: `"2015"` , `"2018"` , `"2021"`
2019-08-05 21:07:12 -05:00
- **Stable**: Yes
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
through the Cargo's formatting tool `cargo fmt` . Otherwise, the edition needs to be specified
in your config file:
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
```toml
edition = "2018"
```
2017-11-09 13:10:37 -06:00
2019-08-05 21:07:12 -05:00
## `empty_item_single_line`
2017-11-09 13:10:37 -06:00
2019-08-05 21:07:12 -05:00
Put empty-body functions and impls on a single line
- **Default value**: `true`
2017-11-09 13:10:37 -06:00
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3356 ](https://github.com/rust-lang/rustfmt/issues/3356 ))
2017-11-09 13:10:37 -06:00
2019-08-05 21:07:12 -05:00
#### `true` (default):
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem() {}
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
impl Lorem {}
```
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `false`:
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() {
}
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
impl Lorem {
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
See also [`brace_style` ](#brace_style ), [`control_brace_style` ](#control_brace_style ).
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `enum_discrim_align_threshold`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
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
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3372 ](https://github.com/rust-lang/rustfmt/issues/3372 ))
2019-08-05 21:07:12 -05:00
#### `0` (default):
```rust
2022-07-15 23:13:19 -05:00
enum Foo {
2019-08-05 21:07:12 -05:00
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,
}
```
## `error_on_line_overflow`
Error if Rustfmt is unable to get all lines within `max_width` , except for comments and string
literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
using a shorter name.
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3391 ](https://github.com/rust-lang/rustfmt/issues/3391 ))
2019-08-05 21:07:12 -05:00
See also [`max_width` ](#max_width ).
## `error_on_unformatted`
Error if unable to get comments or string literals within `max_width` , or they are left with
trailing whitespaces.
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3392 ](https://github.com/rust-lang/rustfmt/issues/3392 ))
2019-08-05 21:07:12 -05:00
## `fn_args_layout`
2022-06-15 21:43:51 -05:00
This option is deprecated and has been renamed to `fn_params_layout` to better communicate that
it affects the layout of parameters in function signatures.
2019-08-05 21:07:12 -05:00
- **Default value**: `"Tall"`
- **Possible values**: `"Compressed"` , `"Tall"` , `"Vertical"`
- **Stable**: Yes
#### `"Tall"` (default):
```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```
#### `"Compressed"`:
```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}
fn lorem(
2017-08-15 08:10:55 -05:00
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
);
fn lorem(
2017-09-18 20:28:51 -05:00
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
2017-08-15 08:10:55 -05:00
) {
2017-04-26 10:36:10 -05:00
// body
}
}
```
#### `"Vertical"`:
```rust
trait Lorem {
2018-01-14 18:59:49 -06:00
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
);
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
) {
2017-04-26 10:36:10 -05:00
// body
}
2018-01-14 18:59:49 -06:00
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
2017-04-26 10:36:10 -05:00
// body
}
}
```
2022-06-15 21:43:51 -05:00
See also [`fn_params_layout` ](#fn_params_layout )
2021-06-21 04:11:37 -05:00
## `fn_call_width`
2020-02-22 22:01:48 -06:00
Maximum width of the args of a function call before falling back to vertical formatting.
- **Default value**: `60`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `fn_call_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ) and [`use_small_heuristics` ](#use_small_heuristics )
2017-04-26 10:36:10 -05:00
2022-06-15 21:43:51 -05:00
## `fn_params_layout`
Control the layout of parameters in function signatures.
- **Default value**: `"Tall"`
- **Possible values**: `"Compressed"` , `"Tall"` , `"Vertical"`
- **Stable**: Yes
#### `"Tall"` (default):
```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```
#### `"Compressed"`:
```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}
fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
);
fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
) {
// body
}
}
```
#### `"Vertical"`:
```rust
trait Lorem {
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
);
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
) {
// body
}
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```
2019-08-05 21:07:12 -05:00
## `fn_single_line`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Put single-expression functions on a single line
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3358 ](https://github.com/rust-lang/rustfmt/issues/3358 ))
2017-11-13 19:49:18 -06:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() -> usize {
42
2017-04-26 10:36:10 -05:00
}
2019-08-05 21:07:12 -05:00
fn lorem() -> usize {
let ipsum = 42;
ipsum
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
#### `true`:
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() -> usize { 42 }
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
fn lorem() -> usize {
let ipsum = 42;
ipsum
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
See also [`control_brace_style` ](#control_brace_style ).
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `force_explicit_abi`
2017-11-13 19:49:18 -06:00
2019-08-05 21:07:12 -05:00
Always print the abi for extern items
2017-11-13 19:49:18 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
- **Stable**: Yes
2017-11-13 19:49:18 -06:00
2019-08-05 21:07:12 -05:00
**Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed.
2017-11-13 19:49:18 -06:00
2019-08-05 21:07:12 -05:00
#### `true` (default):
2017-11-13 19:49:18 -06:00
```rust
2019-08-05 21:07:12 -05:00
extern "C" {
pub static lorem: c_int;
2017-11-13 19:49:18 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `false`:
2017-11-13 19:49:18 -06:00
```rust
2019-08-05 21:07:12 -05:00
extern {
pub static lorem: c_int;
2017-11-13 19:49:18 -06:00
}
```
2019-08-05 21:07:12 -05:00
## `force_multiline_blocks`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Force multiline closure and match arm bodies to be wrapped in a block
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `false` , `true`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3374 ](https://github.com/rust-lang/rustfmt/issues/3374 ))
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
result.and_then(|maybe_value| match maybe_value {
None => foo(),
Some(value) => bar(),
});
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
match lorem {
None => |ipsum| {
println!("Hello World");
},
Some(dolor) => foo(),
}
2017-11-30 06:01:41 -06:00
}
```
#### `true`:
```rust
2019-08-05 21:07:12 -05:00
fn main() {
result.and_then(|maybe_value| {
match maybe_value {
None => foo(),
Some(value) => bar(),
}
});
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
match lorem {
None => {
|ipsum| {
println!("Hello World");
}
}
Some(dolor) => foo(),
}
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
## `format_code_in_doc_comments`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Format code snippet included in doc comments.
2017-04-26 10:36:10 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3348 ](https://github.com/rust-lang/rustfmt/issues/3348 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
/// 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
2018-01-14 19:30:14 -06:00
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `true`
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
/// 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
2018-01-14 19:30:41 -06:00
}
2017-04-26 10:36:10 -05:00
```
2022-06-16 22:15:16 -05:00
## `doc_comment_code_block_width`
Max width for code snippets included in doc comments. Only used if [`format_code_in_doc_comments` ](#format_code_in_doc_comments ) is true.
- **Default value**: `100`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: No (tracking issue: [#5359 ](https://github.com/rust-lang/rustfmt/issues/5359 ))
2021-10-20 00:11:59 -05:00
## `format_generated_files`
Format generated files. A file is considered generated
2022-01-14 18:18:37 -06:00
if any of the first five lines contain a `@generated` comment marker.
2022-02-06 22:39:53 -06:00
By default, generated files are reformatted, i. e. `@generated` marker is ignored.
This option is currently ignored for stdin (`@generated` in stdin is ignored.)
2021-10-20 00:11:59 -05:00
2022-01-14 18:18:37 -06:00
- **Default value**: `true`
2021-10-20 00:11:59 -05:00
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#5080 ](https://github.com/rust-lang/rustfmt/issues/5080 ))
2021-10-20 00:11:59 -05:00
2019-02-18 13:35:22 -06:00
## `format_macro_matchers`
2018-07-17 19:03:59 -05:00
Format the metavariable matching patterns in macros.
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3354 ](https://github.com/rust-lang/rustfmt/issues/3354 ))
2018-07-17 19:03:59 -05:00
#### `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 ).
2019-02-18 13:35:22 -06:00
## `format_macro_bodies`
2018-07-17 19:03:59 -05:00
Format the bodies of macros.
- **Default value**: `true`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3355 ](https://github.com/rust-lang/rustfmt/issues/3355 ))
2018-07-17 19:03:59 -05:00
#### `true` (default):
```rust
macro_rules! foo {
2018-07-17 19:09:50 -05:00
($a: ident : $b: ty) => {
2018-07-17 19:03:59 -05:00
$a(42): $b;
};
2018-07-17 19:09:50 -05:00
($a: ident $b: ident $c: ident) => {
2018-07-17 19:03:59 -05:00
$a = $b + $c;
};
}
```
#### `false`:
```rust
macro_rules! foo {
2018-07-17 19:09:50 -05:00
($a: ident : $b: ty) => { $a(42): $b; };
($a: ident $b: ident $c: ident) => { $a=$b+$c; };
2018-07-17 19:03:59 -05:00
}
```
See also [`format_macro_matchers` ](#format_macro_matchers ).
2022-07-12 19:31:19 -05:00
## `skip_macro_invocations`
Skip formatting the bodies of macro invocations with the following names.
rustfmt will not format any macro invocation for macros with names set in this list.
Including the special value "*" will prevent any macro invocations from being formatted.
Note: This option does not have any impact on how rustfmt formats macro definitions.
- **Default value**: `[]`
- **Possible values**: a list of macro name idents, `["name_0", "name_1", ..., "*"]`
- **Stable**: No (tracking issue: [#5346 ](https://github.com/rust-lang/rustfmt/issues/5346 ))
#### `[]` (default):
rustfmt will follow its standard approach to formatting macro invocations.
No 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 ).
```rust
lorem!(
const _: u8 = 0;
);
ipsum!(
const _: u8 = 0;
);
```
#### `["lorem"]`:
The named macro invocations will be skipped.
```rust
lorem!(
const _: u8 = 0;
);
ipsum!(
const _: u8 = 0;
);
```
#### `["*"]`:
The special selector `*` will skip all macro invocations.
```rust
lorem!(
const _: u8 = 0;
);
ipsum!(
const _: u8 = 0;
);
```
2018-07-17 19:03:59 -05:00
2019-08-05 21:07:12 -05:00
## `format_strings`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Format string literals where necessary
2017-04-26 10:36:10 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3353 ](https://github.com/rust-lang/rustfmt/issues/3353 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
2017-04-26 10:36:10 -05:00
}
```
#### `true`:
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet \
consectetur adipiscing";
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
See also [`max_width` ](#max_width ).
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `hard_tabs`
2017-07-13 06:40:49 -05:00
2019-08-05 21:07:12 -05:00
Use tab characters for indentation, spaces for alignment
2017-07-13 06:40:49 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
- **Stable**: Yes
2017-07-13 06:40:49 -05:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2017-07-13 06:40:49 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() -> usize {
42 // spaces before 42
}
2017-07-13 06:40:49 -05:00
```
2019-08-05 21:07:12 -05:00
#### `true`:
2018-07-16 17:45:30 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() -> usize {
42 // tabs before 42
}
2018-07-16 17:45:30 -05:00
```
2019-08-05 21:07:12 -05:00
See also: [`tab_spaces` ](#tab_spaces ).
2017-07-13 06:40:49 -05:00
2021-10-20 00:11:59 -05:00
## `hex_literal_case`
Control the case of the letters in hexadecimal literal values
- **Default value**: `Preserve`
2022-05-09 19:10:53 -05:00
- **Possible values**: `Preserve` , `Upper` , `Lower`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#5081 ](https://github.com/rust-lang/rustfmt/issues/5081 ))
2017-07-13 06:40:49 -05:00
2019-08-05 21:07:12 -05:00
## `hide_parse_errors`
Do not show parse errors if the parser failed to parse files.
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3390 ](https://github.com/rust-lang/rustfmt/issues/3390 ))
2019-08-05 21:07:12 -05:00
## `ignore`
Skip formatting files and directories that match the specified pattern.
The pattern format is the same as [.gitignore ](https://git-scm.com/docs/gitignore#_pattern_format ). Be sure to use Unix/forwardslash `/` style paths. This path style will work on all platforms. Windows style paths with backslashes `\` are not supported.
- **Default value**: format every file
- **Possible values**: See an example below
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3395 ](https://github.com/rust-lang/rustfmt/issues/3395 ))
2019-08-05 21:07:12 -05:00
### Example
If you want to ignore specific files, put the following to your config file:
```toml
ignore = [
"src/types.rs",
"src/foo/bar.rs",
]
```
If you want to ignore every file under `examples/` , put the following to your config file:
```toml
ignore = [
"examples",
]
```
If you want to ignore every file under the directory where you put your rustfmt.toml:
```toml
ignore = ["/"]
```
## `imports_indent`
Indent style of imports
- **Default Value**: `"Block"`
- **Possible values**: `"Block"` , `"Visual"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3360 ](https://github.com/rust-lang/rustfmt/issues/3360 ))
2019-08-05 21:07:12 -05:00
#### `"Block"` (default):
```rust
use foo::{
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
};
```
#### `"Visual"`:
```rust
use foo::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};
```
See also: [`imports_layout` ](#imports_layout ).
## `imports_layout`
Item layout inside a imports block
2017-07-13 06:40:49 -05:00
- **Default value**: "Mixed"
- **Possible values**: "Horizontal", "HorizontalVertical", "Mixed", "Vertical"
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3361 ](https://github.com/rust-lang/rustfmt/issues/3361 ))
2017-07-13 06:40:49 -05:00
2017-09-18 20:28:51 -05:00
#### `"Mixed"` (default):
2017-07-13 06:40:49 -05:00
```rust
2018-01-15 23:12:49 -06:00
use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
2017-07-13 06:40:49 -05:00
2018-04-29 07:22:48 -05:00
use foo::{
aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
};
2017-07-13 06:40:49 -05:00
```
2017-09-18 20:28:51 -05:00
#### `"Horizontal"`:
2017-07-13 06:40:49 -05:00
2018-01-15 03:41:11 -06:00
**Note**: This option forces all imports onto one line and may exceed `max_width` .
2017-07-13 06:40:49 -05:00
```rust
use foo::{xxx, yyy, zzz};
use foo::{aaa, bbb, ccc, ddd, eee, fff};
```
2017-11-09 13:10:37 -06:00
#### `"HorizontalVertical"`:
2017-07-13 06:40:49 -05:00
```rust
2018-01-16 00:36:15 -06:00
use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
2017-07-13 06:40:49 -05:00
2018-04-29 07:22:48 -05:00
use foo::{
aaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbb,
cccccccccccccccccc,
dddddddddddddddddd,
eeeeeeeeeeeeeeeeee,
ffffffffffffffffff,
};
2017-07-13 06:40:49 -05:00
```
2017-11-09 13:10:37 -06:00
#### `"Vertical"`:
2017-07-13 06:40:49 -05:00
```rust
2018-04-29 07:22:48 -05:00
use foo::{
xxx,
yyy,
zzz,
};
2017-07-13 06:40:49 -05:00
2018-04-29 07:22:48 -05:00
use foo::{
aaa,
bbb,
ccc,
ddd,
eee,
fff,
};
2017-07-13 06:40:49 -05:00
```
2019-08-05 21:07:12 -05:00
## `indent_style`
2018-04-06 08:34:41 -05:00
2019-08-05 21:07:12 -05:00
Indent on expressions or items.
2018-04-06 08:34:41 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"Block"`
- **Possible values**: `"Block"` , `"Visual"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3346 ](https://github.com/rust-lang/rustfmt/issues/3346 ))
2018-04-06 08:34:41 -05:00
2019-08-05 21:07:12 -05:00
### Array
#### `"Block"` (default):
2018-04-06 08:34:41 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let lorem = vec![
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit",
];
}
2018-04-06 08:34:41 -05:00
```
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2018-04-06 08:34:41 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let lorem = vec!["ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit"];
}
2018-04-06 08:34:41 -05:00
```
2019-08-05 21:07:12 -05:00
### Control flow
2017-10-27 00:25:14 -05:00
2019-08-05 21:07:12 -05:00
#### `"Block"` (default):
2017-04-26 10:36:10 -05:00
```rust
2018-01-16 00:41:29 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
if lorem_ipsum
& & dolor_sit
& & amet_consectetur
& & lorem_sit
& & dolor_consectetur
& & amet_ipsum
& & lorem_consectetur
{
// ...
2017-04-26 10:36:10 -05:00
}
}
```
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2017-04-26 10:36:10 -05:00
```rust
2018-01-16 00:42:59 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
if lorem_ipsum
& & dolor_sit
& & amet_consectetur
& & lorem_sit
& & dolor_consectetur
& & amet_ipsum
& & lorem_consectetur
{
// ...
2018-01-16 00:42:59 -06:00
}
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
See also: [`control_brace_style` ](#control_brace_style ).
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
### Function arguments
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `"Block"` (default):
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem() {}
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
fn lorem(ipsum: usize) {}
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
fn lorem(
ipsum: usize,
dolor: usize,
sit: usize,
amet: usize,
consectetur: usize,
adipiscing: usize,
elit: usize,
) {
// body
}
```
2017-08-18 18:50:39 -05:00
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2017-08-18 18:50:39 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem() {}
2017-08-23 09:20:32 -05:00
2019-08-05 21:07:12 -05:00
fn lorem(ipsum: usize) {}
2017-08-23 09:20:32 -05:00
2019-08-05 21:07:12 -05:00
fn lorem(ipsum: usize,
dolor: usize,
sit: usize,
amet: usize,
consectetur: usize,
adipiscing: usize,
elit: usize) {
// body
}
2017-08-23 09:20:32 -05:00
```
2017-08-18 18:50:39 -05:00
2019-08-05 21:07:12 -05:00
### Function calls
#### `"Block"` (default):
2017-08-18 18:50:39 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
lorem(
"lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit",
);
}
2017-08-18 18:50:39 -05:00
```
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2017-08-23 09:20:32 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn main() {
lorem("lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit");
}
```
2017-08-23 09:20:32 -05:00
2019-08-05 21:07:12 -05:00
### Generics
2017-08-23 09:20:32 -05:00
2019-08-05 21:07:12 -05:00
#### `"Block"` (default):
2017-09-18 20:28:51 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem<
Ipsum: Eq = usize,
Dolor: Eq = usize,
Sit: Eq = usize,
Amet: Eq = usize,
Adipiscing: Eq = usize,
Consectetur: Eq = usize,
Elit: Eq = usize,
>(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
adipiscing: Adipiscing,
consectetur: Consectetur,
elit: Elit,
) -> T {
// body
2017-11-26 22:01:49 -06:00
}
2017-09-18 20:28:51 -05:00
```
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2017-08-18 18:50:39 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem< Ipsum: Eq = usize,
Dolor: Eq = usize,
Sit: Eq = usize,
Amet: Eq = usize,
Adipiscing: Eq = usize,
Consectetur: Eq = usize,
Elit: Eq = usize>(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
adipiscing: Adipiscing,
consectetur: Consectetur,
elit: Elit)
-> T {
// body
2017-08-18 18:50:39 -05:00
}
```
2019-08-05 21:07:12 -05:00
#### Struct
2017-11-26 22:01:49 -06:00
2019-08-05 21:07:12 -05:00
#### `"Block"` (default):
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn main() {
let lorem = Lorem {
ipsum: dolor,
sit: amet,
};
}
```
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn main() {
let lorem = Lorem { ipsum: dolor,
sit: amet };
}
```
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
See also: [`struct_lit_single_line` ](#struct_lit_single_line ), [`indent_style` ](#indent_style ).
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
### Where predicates
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
#### `"Block"` (default):
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem< Ipsum , Dolor , Sit , Amet > () -> T
where
Ipsum: Eq,
Dolor: Eq,
Sit: Eq,
Amet: Eq,
{
// body
}
```
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
#### `"Visual"`:
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem< Ipsum , Dolor , Sit , Amet > () -> T
where Ipsum: Eq,
Dolor: Eq,
Sit: Eq,
Amet: Eq
{
// body
}
```
2018-07-29 16:02:32 -05:00
2019-08-05 21:07:12 -05:00
## `inline_attribute_width`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Write an item and its attribute on the same line if their combined width is below a threshold
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: 0
- **Possible values**: any positive integer
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3343 ](https://github.com/rust-lang/rustfmt/issues/3343 ))
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
### Example
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `0` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
#[cfg(feature = "alloc")]
use core::slice;
```
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `50`:
```rust
#[cfg(feature = "alloc")] use core::slice;
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
## `match_arm_blocks`
2018-05-05 10:13:49 -05:00
2021-07-25 22:57:19 -05:00
Controls whether arm bodies are wrapped in cases where the first line of the body cannot fit on the same line as the `=>` operator.
The Style Guide requires that bodies are block wrapped by default if a line break is required after the `=>` , but this option can be used to disable that behavior to prevent wrapping arm bodies in that event, so long as the body does not contain multiple statements nor line comments.
2018-05-05 10:13:49 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3373 ](https://github.com/rust-lang/rustfmt/issues/3373 ))
2018-05-17 23:41:21 -05:00
#### `true` (default):
2019-08-05 21:07:12 -05:00
2018-05-05 10:13:49 -05:00
```rust
fn main() {
2019-08-05 21:07:12 -05:00
match lorem {
2021-07-25 22:57:19 -05:00
ipsum => {
2019-08-05 21:07:12 -05:00
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
}
2021-07-25 22:57:19 -05:00
dolor => println!("{}", sit),
sit => foo(
"foooooooooooooooooooooooo",
"baaaaaaaaaaaaaaaaaaaaaaaarr",
"baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
"qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
),
2019-08-05 21:07:12 -05:00
}
2018-05-05 10:13:49 -05:00
}
```
2018-05-17 23:41:21 -05:00
#### `false`:
2019-08-05 21:07:12 -05:00
2018-05-05 10:13:49 -05:00
```rust
fn main() {
2019-08-05 21:07:12 -05:00
match lorem {
2021-07-25 22:57:19 -05:00
lorem =>
2019-08-05 21:07:12 -05:00
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
2021-07-25 22:57:19 -05:00
ipsum => println!("{}", sit),
sit => foo(
"foooooooooooooooooooooooo",
"baaaaaaaaaaaaaaaaaaaaaaaarr",
"baaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzz",
"qqqqqqqqquuuuuuuuuuuuuuuuuuuuuuuuuuxxx",
),
2019-08-05 21:07:12 -05:00
}
2018-05-05 10:13:49 -05:00
}
```
2019-08-05 21:07:12 -05:00
See also: [`match_block_trailing_comma` ](#match_block_trailing_comma ).
2017-04-26 10:36:10 -05:00
2020-09-23 22:05:56 -05:00
## `match_arm_leading_pipes`
Controls whether to include a leading pipe on match arms
- **Default value**: `Never`
- **Possible values**: `Always` , `Never` , `Preserve`
- **Stable**: Yes
#### `Never` (default):
```rust
// Leading pipes are removed from this:
// fn foo() {
// match foo {
// | "foo" | "bar" => {}
// | "baz"
// | "something relatively long"
// | "something really really really realllllllllllllly long" => println!("x"),
// | "qux" => println!("y"),
// _ => {}
// }
// }
// Becomes
fn foo() {
match foo {
"foo" | "bar" => {}
"baz"
| "something relatively long"
| "something really really really realllllllllllllly long" => println!("x"),
"qux" => println!("y"),
_ => {}
}
}
```
#### `Always`:
```rust
// Leading pipes are emitted on all arms of this:
// fn foo() {
// match foo {
// "foo" | "bar" => {}
// "baz"
// | "something relatively long"
// | "something really really really realllllllllllllly long" => println!("x"),
// "qux" => println!("y"),
// _ => {}
// }
// }
// Becomes:
fn foo() {
match foo {
| "foo" | "bar" => {}
| "baz"
| "something relatively long"
| "something really really really realllllllllllllly long" => println!("x"),
| "qux" => println!("y"),
| _ => {}
}
}
```
#### `Preserve`:
```rust
fn foo() {
match foo {
| "foo" | "bar" => {}
| "baz"
| "something relatively long"
| "something really really really realllllllllllllly long" => println!("x"),
| "qux" => println!("y"),
_ => {}
}
match baz {
"qux" => {}
"foo" | "bar" => {}
_ => {}
}
}
```
2019-08-05 21:07:12 -05:00
## `match_block_trailing_comma`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Put a trailing comma after a block based match arm (non-block arms are not affected)
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
2017-04-26 10:36:10 -05:00
- **Possible values**: `true` , `false`
2021-10-20 00:11:59 -05:00
- **Stable**: Yes
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
match lorem {
Lorem::Ipsum => {
println!("ipsum");
}
Lorem::Dolor => println!("dolor"),
}
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `true`:
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
match lorem {
Lorem::Ipsum => {
println!("ipsum");
},
Lorem::Dolor => println!("dolor"),
}
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
See also: [`trailing_comma` ](#trailing_comma ), [`match_arm_blocks` ](#match_arm_blocks ).
## `max_width`
2017-11-09 13:10:37 -06:00
2019-08-05 21:07:12 -05:00
Maximum width of each line
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `100`
- **Possible values**: any positive integer
- **Stable**: Yes
See also [`error_on_line_overflow` ](#error_on_line_overflow ).
## `merge_derives`
Merge multiple derives into a single one.
2018-02-23 06:55:16 -06:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
2018-05-17 23:41:21 -05:00
- **Stable**: Yes
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
#### `true` (default):
2018-02-23 06:55:16 -06:00
```rust
2019-08-05 21:07:12 -05:00
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum Foo {}
2018-02-23 06:55:16 -06:00
```
2019-08-05 21:07:12 -05:00
#### `false`:
2018-02-23 06:55:16 -06:00
```rust
2021-10-20 00:11:59 -05:00
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum Bar {}
2019-08-05 21:07:12 -05:00
#[derive(Eq, PartialEq)]
#[derive(Debug)]
#[derive(Copy, Clone)]
pub enum Foo {}
2018-02-23 06:55:16 -06:00
```
2020-12-15 19:19:54 -06:00
## `imports_granularity`
2021-01-12 19:30:26 -06:00
How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
2020-12-15 19:19:54 -06:00
- **Default value**: `Preserve`
2021-10-20 00:11:59 -05:00
- **Possible values**: `Preserve` , `Crate` , `Module` , `Item` , `One`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#4991 ](https://github.com/rust-lang/rustfmt/issues/4991 ))
2020-12-15 19:19:54 -06:00
2022-05-26 21:56:35 -05:00
Note that rustfmt will not modify the granularity of imports containing comments if doing so could potentially lose or misplace said comments.
2020-12-15 19:19:54 -06:00
#### `Preserve` (default):
2021-01-12 19:30:26 -06:00
Do not change the granularity of any imports and preserve the original structure written by the developer.
2020-12-15 19:19:54 -06:00
```rust
use foo::b;
use foo::b::{f, g};
use foo::{a, c, d::e};
use qux::{h, i};
```
#### `Crate`:
Merge imports from the same crate into a single `use` statement. Conversely, imports from different crates are split into separate statements.
```rust
use foo::{
a, b,
b::{f, g},
c,
d::e,
};
use qux::{h, i};
```
#### `Module`:
Merge imports from the same module into a single `use` statement. Conversely, imports from different modules are split into separate statements.
```rust
use foo::b::{f, g};
use foo::d::e;
use foo::{a, b, c};
use qux::{h, i};
```
2021-01-12 13:29:11 -06:00
#### `Item`:
Flatten imports so that each has its own `use` statement.
```rust
use foo::a;
use foo::b;
use foo::b::f;
use foo::b::g;
use foo::c;
use foo::d::e;
use qux::h;
use qux::i;
```
2021-10-20 00:11:59 -05:00
#### `One`:
Merge all imports into a single `use` statement as long as they have the same visibility.
```rust
pub use foo::{x, y};
use {
bar::{
a,
b::{self, f, g},
c,
d::e,
},
qux::{h, i},
};
```
2019-08-05 21:07:12 -05:00
## `merge_imports`
2018-04-04 00:57:30 -05:00
2020-12-15 19:19:54 -06:00
This option is deprecated. Use `imports_granularity = "Crate"` instead.
2018-04-04 00:57:30 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2019-08-05 21:07:12 -05:00
#### `false` (default):
2018-04-04 00:57:30 -05:00
```rust
2019-08-05 21:07:12 -05:00
use foo::{a, c, d};
use foo::{b, g};
use foo::{e, f};
2018-04-04 00:57:30 -05:00
```
2019-08-05 21:07:12 -05:00
#### `true`:
2018-04-04 00:57:30 -05:00
```rust
2019-08-05 21:07:12 -05:00
use foo::{a, b, c, d, e, f, g};
2018-04-04 00:57:30 -05:00
```
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `newline_style`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Unix or Windows line endings
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"Auto"`
- **Possible values**: `"Auto"` , `"Native"` , `"Unix"` , `"Windows"`
- **Stable**: Yes
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `Auto` (default):
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
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.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `Native`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Line endings will be converted to `\r\n` on Windows and `\n` on all
other platforms.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `Unix`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Line endings will be converted to `\n` .
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `Windows`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Line endings will be converted to `\r\n` .
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `normalize_comments`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Convert /* */ comments to // comments where possible
2017-04-26 10:36:10 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3350 ](https://github.com/rust-lang/rustfmt/issues/3350 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `false` (default):
2019-08-05 21:07:12 -05:00
```rust
// Lorem ipsum:
fn dolor() -> usize {}
/* sit amet: */
fn adipiscing() -> usize {}
2017-04-26 10:36:10 -05:00
```
#### `true`:
```rust
2019-08-05 21:07:12 -05:00
// Lorem ipsum:
fn dolor() -> usize {}
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
// sit amet:
fn adipiscing() -> usize {}
```
2017-06-05 20:11:17 -05:00
2019-08-05 21:07:12 -05:00
## `normalize_doc_attributes`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3351 ](https://github.com/rust-lang/rustfmt/issues/3351 ))
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
#![doc = "Example documentation"]
#[doc = "Example item documentation"]
2021-10-20 00:11:59 -05:00
pub enum Bar {}
/// Example item documentation
2019-08-05 21:07:12 -05:00
pub enum Foo {}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `true`:
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
//! Example documentation
/// Example item documentation
pub enum Foo {}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
## `overflow_delimited_expr`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
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.
2017-04-26 10:36:10 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3370 ](https://github.com/rust-lang/rustfmt/issues/3370 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn example() {
foo(ctx, |param| {
action();
foo(param)
});
2018-01-21 18:25:24 -06:00
2019-08-05 21:07:12 -05:00
foo(
ctx,
Bar {
x: value,
y: value2,
},
);
2018-01-21 18:25:24 -06:00
2019-08-05 21:07:12 -05:00
foo(
ctx,
& [
MAROON_TOMATOES,
PURPLE_POTATOES,
ORGANE_ORANGES,
GREEN_PEARS,
RED_APPLES,
],
);
2018-01-21 18:25:24 -06:00
2019-08-05 21:07:12 -05:00
foo(
ctx,
vec![
MAROON_TOMATOES,
PURPLE_POTATOES,
ORGANE_ORANGES,
GREEN_PEARS,
RED_APPLES,
],
);
2018-01-21 18:25:24 -06:00
}
2017-04-26 10:36:10 -05:00
```
#### `true`:
```rust
2019-08-05 21:07:12 -05:00
fn example() {
foo(ctx, |param| {
action();
foo(param)
});
2018-01-21 18:25:24 -06:00
2019-08-05 21:07:12 -05:00
foo(ctx, Bar {
x: value,
y: value2,
});
2018-01-21 18:25:24 -06:00
2019-08-05 21:07:12 -05:00
foo(ctx, & [
MAROON_TOMATOES,
PURPLE_POTATOES,
ORGANE_ORANGES,
GREEN_PEARS,
RED_APPLES,
]);
2018-01-21 18:25:24 -06:00
2019-08-05 21:07:12 -05:00
foo(ctx, vec![
MAROON_TOMATOES,
PURPLE_POTATOES,
ORGANE_ORANGES,
GREEN_PEARS,
RED_APPLES,
]);
2018-01-21 18:25:24 -06:00
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
## `remove_nested_parens`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Remove nested parens.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `true` ,
2017-11-23 19:45:18 -06:00
- **Possible values**: `true` , `false`
2019-08-05 21:07:12 -05:00
- **Stable**: Yes
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
2019-08-05 21:07:12 -05:00
#### `true` (default):
2017-09-18 20:28:51 -05:00
```rust
2018-02-19 01:17:36 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
(foo());
2018-02-19 01:17:36 -06:00
}
2017-09-18 20:28:51 -05:00
```
2017-11-23 19:45:18 -06:00
#### `false`:
2017-04-26 10:36:10 -05:00
```rust
2018-01-21 00:20:56 -06:00
fn main() {
2021-10-20 00:11:59 -05:00
(foo());
2019-08-05 21:07:12 -05:00
((((foo()))));
2018-01-21 00:20:56 -06:00
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
## `reorder_impl_items`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Reorder impl items. `type` and `const` are put first, then macros and methods.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3363 ](https://github.com/rust-lang/rustfmt/issues/3363 ))
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `false` (default)
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
struct Dummy;
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
impl Iterator for Dummy {
fn next(& mut self) -> Option< Self::Item > {
None
}
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
type Item = i32;
2018-01-21 00:36:12 -06:00
}
2021-10-20 00:11:59 -05:00
impl Iterator for Dummy {
type Item = i32;
fn next(& mut self) -> Option< Self::Item > {
None
}
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `true`
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
struct Dummy;
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
impl Iterator for Dummy {
type Item = i32;
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
fn next(& mut self) -> Option< Self::Item > {
None
}
2018-01-21 00:39:27 -06:00
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
## `reorder_imports`
2017-07-11 08:41:38 -05:00
2019-08-05 21:07:12 -05:00
Reorder import and extern crate statements alphabetically in groups (a group is
separated by a newline).
2017-07-11 08:41:38 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
2019-08-05 21:07:12 -05:00
- **Stable**: Yes
2017-07-11 08:41:38 -05:00
2017-09-18 20:28:51 -05:00
#### `true` (default):
2019-08-05 21:07:12 -05:00
2017-07-11 08:41:38 -05:00
```rust
2019-08-05 21:07:12 -05:00
use dolor;
use ipsum;
use lorem;
use sit;
2017-07-11 08:41:38 -05:00
```
#### `false`:
2019-08-05 21:07:12 -05:00
2017-07-11 08:41:38 -05:00
```rust
2019-08-05 21:07:12 -05:00
use lorem;
use ipsum;
use dolor;
use sit;
2017-07-11 08:41:38 -05:00
```
2020-11-16 17:24:03 -06:00
## `group_imports`
2022-03-05 17:01:43 -06:00
Controls the strategy for how consecutive imports are grouped together.
Controls the strategy for grouping sets of consecutive imports. Imports may contain newlines between imports and still be grouped together as a single set, but other statements between imports will result in different grouping sets.
2020-11-16 17:24:03 -06:00
- **Default value**: `Preserve`
2021-11-07 20:37:34 -06:00
- **Possible values**: `Preserve` , `StdExternalCrate` , `One`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#5083 ](https://github.com/rust-lang/rustfmt/issues/5083 ))
2020-11-16 17:24:03 -06:00
2022-03-05 17:01:43 -06:00
Each set of imports (one or more `use` statements, optionally separated by newlines) will be formatted independently. Other statements such as `mod ...` or `extern crate ...` will cause imports to not be grouped together.
2020-11-16 17:24:03 -06:00
#### `Preserve` (default):
Preserve the source file's import groups.
```rust
use super::update::convert_publish_payload;
use chrono::Utc;
use alloc::alloc::Layout;
use juniper::{FieldError, FieldResult};
use uuid::Uuid;
use std::sync::Arc;
use broker::database::PooledConnection;
use super::schema::{Context, Payload};
use crate::models::Event;
use core::f32;
```
#### `StdExternalCrate`:
Discard existing import groups, and create three groups for:
1. `std` , `core` and `alloc` ,
2. external crates,
3. `self` , `super` and `crate` imports.
```rust
use alloc::alloc::Layout;
use core::f32;
use std::sync::Arc;
use broker::database::PooledConnection;
use chrono::Utc;
use juniper::{FieldError, FieldResult};
use uuid::Uuid;
use super::schema::{Context, Payload};
use super::update::convert_publish_payload;
use crate::models::Event;
```
2017-04-26 10:36:10 -05:00
2021-11-07 20:37:34 -06:00
#### `One`:
Discard existing import groups, and create a single group for everything
```rust
use super::schema::{Context, Payload};
use super::update::convert_publish_payload;
use crate::models::Event;
use alloc::alloc::Layout;
use broker::database::PooledConnection;
use chrono::Utc;
use core::f32;
use juniper::{FieldError, FieldResult};
use std::sync::Arc;
use uuid::Uuid;
```
2019-08-05 21:07:12 -05:00
## `reorder_modules`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Reorder `mod` declarations alphabetically in group.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
- **Stable**: Yes
#### `true` (default)
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
mod a;
mod b;
mod dolor;
mod ipsum;
mod lorem;
mod sit;
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `false`
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
mod b;
mod a;
mod lorem;
mod ipsum;
mod dolor;
mod sit;
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
**Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
of the original source code.
2018-01-29 07:14:25 -06:00
2019-08-05 21:07:12 -05:00
## `required_version`
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`
- **Possible values**: any published version (e.g. `"0.3.8"` )
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3386 ](https://github.com/rust-lang/rustfmt/issues/3386 ))
2019-08-05 21:07:12 -05:00
2022-02-13 06:24:09 -06:00
## `short_array_element_width_threshold`
The width threshold for an array element to be considered "short".
The layout of an array is dependent on the length of each of its elements.
If the length of every element in an array is below this threshold (all elements are "short") then the array can be formatted in the mixed/compressed style, but if any one element has a length that exceeds this threshold then the array elements will have to be formatted vertically.
- **Default value**: `10`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
#### `10` (default):
```rust
fn main() {
pub const FORMAT_TEST: [u64; 5] = [
0x0000000000000000,
0xaaaaaaaaaaaaaaaa,
0xbbbbbbbbbbbbbbbb,
0xcccccccccccccccc,
0xdddddddddddddddd,
];
}
```
#### `20`:
```rust
fn main() {
pub const FORMAT_TEST: [u64; 5] = [
0x0000000000000000, 0xaaaaaaaaaaaaaaaa, 0xbbbbbbbbbbbbbbbb, 0xcccccccccccccccc,
0xdddddddddddddddd,
];
}
```
See also [`max_width` ](#max_width ).
2019-08-05 21:07:12 -05:00
## `skip_children`
Don't reformat out of line modules
2018-01-29 07:14:25 -06:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2022-03-12 00:14:38 -06:00
- **Stable**: No (tracking issue: [#3389 ](https://github.com/rust-lang/rustfmt/issues/3389 ))
2018-01-29 07:14:25 -06:00
2021-06-21 04:11:37 -05:00
## `single_line_if_else_max_width`
2020-02-22 22:01:48 -06:00
Maximum line length for single line if-else expressions. A value of `0` (zero) results in if-else expressions always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off` .
- **Default value**: `50`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `single_line_if_else_max_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ) and [`use_small_heuristics` ](#use_small_heuristics )
2019-08-05 21:07:12 -05:00
## `space_after_colon`
2018-01-29 07:14:25 -06:00
2019-08-05 21:07:12 -05:00
Leave a space after the colon.
2018-01-29 07:14:25 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3366 ](https://github.com/rust-lang/rustfmt/issues/3366 ))
2018-01-29 07:14:25 -06:00
2019-08-05 21:07:12 -05:00
#### `true` (default):
2018-01-29 07:14:25 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem< T: Eq > (t: T) {
let lorem: Dolor = Lorem {
ipsum: dolor,
sit: amet,
};
2018-01-29 07:14:25 -06:00
}
2019-08-05 21:07:12 -05:00
```
2018-01-29 07:14:25 -06:00
2019-08-05 21:07:12 -05:00
#### `false`:
```rust
fn lorem< T:Eq > (t:T) {
let lorem:Dolor = Lorem {
ipsum:dolor,
sit:amet,
};
2018-01-29 07:14:25 -06:00
}
```
2019-08-05 21:07:12 -05:00
See also: [`space_before_colon` ](#space_before_colon ).
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `space_before_colon`
Leave a space before the colon.
2017-04-26 10:36:10 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3365 ](https://github.com/rust-lang/rustfmt/issues/3365 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `false` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem< T: Eq > (t: T) {
let lorem: Dolor = Lorem {
ipsum: dolor,
sit: amet,
};
2018-01-21 00:49:54 -06:00
}
2017-04-26 10:36:10 -05:00
```
#### `true`:
```rust
2019-08-05 21:07:12 -05:00
fn lorem< T : Eq > (t : T) {
let lorem : Dolor = Lorem {
ipsum : dolor,
sit : amet,
};
2018-01-21 00:51:51 -06:00
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
See also: [`space_after_colon` ](#space_after_colon ).
2018-10-11 09:10:57 -05:00
2019-08-05 21:07:12 -05:00
## `spaces_around_ranges`
Put spaces around the .., ..=, and ... range operators
2018-10-11 09:10:57 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3367 ](https://github.com/rust-lang/rustfmt/issues/3367 ))
2018-10-11 09:10:57 -05:00
#### `false` (default):
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let lorem = 0..10;
let ipsum = 0..=10;
match lorem {
1..5 => foo(),
_ => bar,
}
match lorem {
1..=5 => foo(),
_ => bar,
}
match lorem {
1...5 => foo(),
_ => bar,
}
2018-10-11 09:10:57 -05:00
}
```
2019-08-05 21:07:12 -05:00
#### `true`:
2018-10-11 09:10:57 -05:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let lorem = 0 .. 10;
let ipsum = 0 ..= 10;
match lorem {
1 .. 5 => foo(),
_ => bar,
}
match lorem {
1 ..= 5 => foo(),
_ => bar,
}
match lorem {
1 ... 5 => foo(),
_ => bar,
}
2018-10-11 09:10:57 -05:00
}
```
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
## `struct_field_align_threshold`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
The maximum diff of width between struct fields to be aligned with each other.
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
- **Default value** : 0
- **Possible values**: any non-negative integer
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3371 ](https://github.com/rust-lang/rustfmt/issues/3371 ))
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
#### `0` (default):
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
struct Foo {
x: u32,
yy: u32,
zzz: u32,
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
#### `20`:
2017-04-26 10:36:10 -05:00
```rust
2019-08-05 21:07:12 -05:00
struct Foo {
x: u32,
yy: u32,
zzz: u32,
}
2017-04-26 10:36:10 -05:00
```
2019-08-05 21:07:12 -05:00
## `struct_lit_single_line`
2017-04-26 10:36:10 -05:00
2019-08-05 21:07:12 -05:00
Put small struct literals on a single line
2017-04-26 10:36:10 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3357 ](https://github.com/rust-lang/rustfmt/issues/3357 ))
2017-04-26 10:36:10 -05:00
2017-09-18 20:28:51 -05:00
#### `true` (default):
2017-04-26 10:36:10 -05:00
```rust
2018-01-21 00:56:14 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
let lorem = Lorem { foo: bar, baz: ofo };
2017-04-26 10:36:10 -05:00
}
```
2017-09-18 20:28:51 -05:00
#### `false`:
2017-04-26 10:36:10 -05:00
```rust
2018-01-21 00:57:53 -06:00
fn main() {
2019-08-05 21:07:12 -05:00
let lorem = Lorem {
foo: bar,
baz: ofo,
};
2017-04-26 10:36:10 -05:00
}
```
2019-08-05 21:07:12 -05:00
See also: [`indent_style` ](#indent_style ).
2018-11-05 22:50:54 -06:00
2021-06-21 04:11:37 -05:00
## `struct_lit_width`
2020-02-22 22:01:48 -06:00
Maximum width in the body of a struct literal before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off` .
- **Default value**: `18`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `struct_lit_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ), [`use_small_heuristics` ](#use_small_heuristics ), and [`struct_lit_single_line` ](#struct_lit_single_line )
2021-06-21 04:11:37 -05:00
## `struct_variant_width`
2020-02-22 22:01:48 -06:00
Maximum width in the body of a struct variant before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off` .
- **Default value**: `35`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width` ](#max_width )
- **Stable**: Yes
2021-06-21 04:11:37 -05:00
By default this option is set as a percentage of [`max_width` ](#max_width ) provided by [`use_small_heuristics` ](#use_small_heuristics ), but a value set directly for `struct_variant_width` will take precedence.
2020-02-22 22:01:48 -06:00
See also [`max_width` ](#max_width ) and [`use_small_heuristics` ](#use_small_heuristics )
2018-11-05 22:50:54 -06:00
2019-08-05 21:07:12 -05:00
## `tab_spaces`
2018-11-05 22:50:54 -06:00
2019-08-05 21:07:12 -05:00
Number of spaces per tab
2018-11-05 22:50:54 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `4`
- **Possible values**: any positive integer
- **Stable**: Yes
2018-11-05 22:50:54 -06:00
2019-08-05 21:07:12 -05:00
#### `4` (default):
2018-11-05 22:50:54 -06:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem() {
let ipsum = dolor();
let sit = vec![
"amet consectetur adipiscing elit amet",
"consectetur adipiscing elit amet consectetur.",
];
2018-11-05 22:50:54 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `2`:
2018-11-05 22:50:54 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn lorem() {
let ipsum = dolor();
let sit = vec![
"amet consectetur adipiscing elit amet",
"consectetur adipiscing elit amet consectetur.",
];
2018-11-05 22:50:54 -06:00
}
```
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
See also: [`hard_tabs` ](#hard_tabs ).
2018-02-03 12:55:50 -06:00
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
## `trailing_comma`
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
How to handle trailing commas for lists
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"Vertical"`
- **Possible values**: `"Always"` , `"Never"` , `"Vertical"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3379 ](https://github.com/rust-lang/rustfmt/issues/3379 ))
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
#### `"Vertical"` (default):
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
```rust
fn main() {
let Lorem { ipsum, dolor, sit } = amet;
let Lorem {
ipsum,
dolor,
sit,
amet,
consectetur,
adipiscing,
} = elit;
2017-12-26 06:00:48 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `"Always"`:
2017-12-26 06:00:48 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn main() {
let Lorem { ipsum, dolor, sit, } = amet;
let Lorem {
ipsum,
dolor,
sit,
amet,
consectetur,
adipiscing,
} = elit;
2017-12-26 06:00:48 -06:00
}
2019-08-05 21:07:12 -05:00
```
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
#### `"Never"`:
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
```rust
fn main() {
let Lorem { ipsum, dolor, sit } = amet;
let Lorem {
ipsum,
dolor,
sit,
amet,
consectetur,
adipiscing
} = elit;
2017-12-26 06:00:48 -06:00
}
```
2019-08-05 21:07:12 -05:00
See also: [`match_block_trailing_comma` ](#match_block_trailing_comma ).
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
## `trailing_semicolon`
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
Add trailing semicolon after break, continue and return
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `true`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3378 ](https://github.com/rust-lang/rustfmt/issues/3378 ))
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
#### `true` (default):
```rust
fn foo() -> usize {
return 0;
2017-12-26 06:00:48 -06:00
}
```
2019-08-05 21:07:12 -05:00
#### `false`:
2017-12-26 06:00:48 -06:00
```rust
2019-08-05 21:07:12 -05:00
fn foo() -> usize {
return 0
2017-12-26 06:00:48 -06:00
}
```
2019-08-05 21:07:12 -05:00
## `type_punctuation_density`
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
Determines if `+` or `=` are wrapped in spaces in the punctuation of types
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"Wide"`
- **Possible values**: `"Compressed"` , `"Wide"`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3364 ](https://github.com/rust-lang/rustfmt/issues/3364 ))
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
#### `"Wide"` (default):
2017-12-26 06:00:48 -06:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem< Ipsum: Dolor + Sit = Amet > () {
// body
2017-12-26 06:00:48 -06:00
}
```
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
#### `"Compressed"`:
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
```rust
fn lorem< Ipsum: Dolor + Sit = Amet > () {
// body
}
```
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
## `unstable_features`
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
Enable unstable features on the unstable channel.
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3387 ](https://github.com/rust-lang/rustfmt/issues/3387 ))
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
## `use_field_init_shorthand`
Use field initialize shorthand if possible.
2018-02-23 06:55:16 -06:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2019-08-05 21:07:12 -05:00
- **Stable**: Yes
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
```rust
struct Foo {
x: u32,
y: u32,
z: u32,
}
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
fn main() {
let x = 1;
let y = 2;
let z = 3;
2021-10-20 00:11:59 -05:00
let a = Foo { x, y, z };
let b = Foo { x: x, y: y, z: z };
2019-08-05 21:07:12 -05:00
}
```
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
#### `true`:
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
```rust
struct Foo {
x: u32,
y: u32,
z: u32,
}
2018-02-23 06:55:16 -06:00
2019-08-05 21:07:12 -05:00
fn main() {
let x = 1;
let y = 2;
let z = 3;
let a = Foo { x, y, z };
}
```
2018-02-26 10:01:40 -06:00
2019-08-05 21:07:12 -05:00
## `use_small_heuristics`
2018-02-26 10:01:40 -06:00
2020-02-22 22:01:48 -06:00
This option can be used to simplify the management and bulk updates of the granular width configuration settings ([`fn_call_width`](#fn_call_width), [`attr_fn_like_width` ](#attr_fn_like_width ), [`struct_lit_width` ](#struct_lit_width ), [`struct_variant_width` ](#struct_variant_width ), [`array_width` ](#array_width ), [`chain_width` ](#chain_width ), [`single_line_if_else_max_width` ](#single_line_if_else_max_width )), that respectively control when formatted constructs are multi-lined/vertical based on width.
2021-06-21 04:11:37 -05:00
Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics` .
2018-02-26 10:01:40 -06:00
2019-08-05 21:07:12 -05:00
- **Default value**: `"Default"`
- **Possible values**: `"Default"` , `"Off"` , `"Max"`
- **Stable**: Yes
2018-02-26 10:01:40 -06:00
2019-08-05 21:07:12 -05:00
#### `Default` (default):
2020-02-22 22:01:48 -06:00
When `use_small_heuristics` is set to `Default` , the values for the granular width settings are calculated as a ratio of the value for `max_width` .
The ratios are:
* [`fn_call_width` ](#fn_call_width ) - `60%`
* [`attr_fn_like_width` ](#attr_fn_like_width ) - `70%`
* [`struct_lit_width` ](#struct_lit_width ) - `18%`
* [`struct_variant_width` ](#struct_variant_width ) - `35%`
* [`array_width` ](#array_width ) - `60%`
* [`chain_width` ](#chain_width ) - `60%`
* [`single_line_if_else_max_width` ](#single_line_if_else_max_width ) - `50%`
For example when `max_width` is set to `100` , the width settings are:
* `fn_call_width=60`
* `attr_fn_like_width=70`
* `struct_lit_width=18`
* `struct_variant_width=35`
* `array_width=60`
* `chain_width=60`
* `single_line_if_else_max_width=50`
and when `max_width` is set to `200` :
* `fn_call_width=120`
* `attr_fn_like_width=140`
* `struct_lit_width=36`
* `struct_variant_width=70`
* `array_width=120`
* `chain_width=120`
* `single_line_if_else_max_width=100`
2018-02-26 10:01:40 -06:00
2019-08-05 21:07:12 -05:00
```rust
enum Lorem {
Ipsum,
Dolor(bool),
Sit { amet: Consectetur, adipiscing: Elit },
}
2018-02-26 10:01:40 -06:00
2019-08-05 21:07:12 -05:00
fn main() {
lorem(
"lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
);
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
let lorem = Lorem {
ipsum: dolor,
sit: amet,
};
let lorem = Lorem { ipsum: dolor };
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
let lorem = if ipsum { dolor } else { sit };
}
```
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
#### `Off`:
2021-06-21 04:11:37 -05:00
When `use_small_heuristics` is set to `Off` , the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics.
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
```rust
enum Lorem {
Ipsum,
Dolor(bool),
Sit {
amet: Consectetur,
adipiscing: Elit,
},
}
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
fn main() {
lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
let lorem = Lorem {
ipsum: dolor,
sit: amet,
};
let lorem = if ipsum {
dolor
} else {
sit
};
}
2018-03-08 22:27:43 -06:00
```
2019-08-05 21:07:12 -05:00
#### `Max`:
2020-02-22 22:01:48 -06:00
When `use_small_heuristics` is set to `Max` , then each granular width setting is set to the same value as `max_width` .
So if `max_width` is set to `200` , then all the width settings are also set to `200` .
* `fn_call_width=200`
* `attr_fn_like_width=200`
* `struct_lit_width=200`
* `struct_variant_width=200`
* `array_width=200`
* `chain_width=200`
* `single_line_if_else_max_width=200`
2018-03-08 22:27:43 -06:00
2019-08-05 21:07:12 -05:00
```rust
enum Lorem {
Ipsum,
Dolor(bool),
Sit { amet: Consectetur, adipiscing: Elit },
}
2018-05-20 21:11:15 -05:00
2019-08-05 21:07:12 -05:00
fn main() {
lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing");
2019-05-22 19:43:43 -05:00
2019-08-05 21:07:12 -05:00
let lorem = Lorem { ipsum: dolor, sit: amet };
let lorem = if ipsum { dolor } else { sit };
}
2019-05-22 19:43:43 -05:00
```
2020-02-22 22:01:48 -06:00
See also:
* [`max_width` ](#max_width )
* [`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 )
2019-08-05 21:07:12 -05:00
## `use_try_shorthand`
2018-07-09 09:20:38 -05:00
2019-08-05 21:07:12 -05:00
Replace uses of the try! macro by the ? shorthand
2018-07-09 09:20:38 -05:00
2019-08-05 21:07:12 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2018-10-24 20:31:42 -05:00
- **Stable**: Yes
2018-07-09 09:20:38 -05:00
2019-08-05 21:07:12 -05:00
#### `false` (default):
2018-07-09 09:20:38 -05:00
2019-08-05 21:07:12 -05:00
```rust
fn main() {
2021-10-20 00:11:59 -05:00
let lorem = ipsum.map(|dolor| dolor.sit())?;
2019-08-05 21:07:12 -05:00
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
}
```
#### `true`:
```rust
fn main() {
let lorem = ipsum.map(|dolor| dolor.sit())?;
}
2018-07-09 09:20:38 -05:00
```
2019-02-18 13:35:22 -06:00
## `version`
2018-11-26 19:04:48 -06:00
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`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3383 ](https://github.com/rust-lang/rustfmt/issues/3383 ))
2018-11-26 19:04:48 -06:00
### Example
```toml
version = "Two"
```
2019-08-05 21:07:12 -05:00
## `where_single_line`
2018-09-07 12:51:21 -05:00
2019-08-05 21:07:12 -05:00
Forces the `where` clause to be laid out on a single line.
2018-09-07 12:51:21 -05:00
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3359 ](https://github.com/rust-lang/rustfmt/issues/3359 ))
2018-09-07 12:51:21 -05:00
#### `false` (default):
```rust
2019-08-05 21:07:12 -05:00
impl< T > Lorem for T
where
Option< T > : Ipsum,
{
// body
}
2018-09-07 12:51:21 -05:00
```
#### `true`:
```rust
2019-08-05 21:07:12 -05:00
impl< T > Lorem for T
where Option< T > : Ipsum
{
// body
}
2018-09-07 12:51:21 -05:00
```
2019-08-05 21:07:12 -05:00
See also [`brace_style` ](#brace_style ), [`control_brace_style` ](#control_brace_style ).
2019-02-20 05:25:01 -06:00
2019-08-05 21:07:12 -05:00
## `wrap_comments`
2019-02-20 05:25:01 -06:00
2019-08-05 21:07:12 -05:00
Break comments to fit on the line
- **Default value**: `false`
- **Possible values**: `true` , `false`
2021-12-02 21:35:30 -06:00
- **Stable**: No (tracking issue: [#3347 ](https://github.com/rust-lang/rustfmt/issues/3347 ))
2019-08-05 21:07:12 -05:00
#### `false` (default):
2019-02-20 05:25:01 -06:00
```rust
2021-10-20 00:11:59 -05:00
// 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.
2019-08-05 21:07:12 -05:00
// 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.
2019-02-20 05:25:01 -06:00
```
2019-08-05 21:07:12 -05:00
#### `true`:
2019-02-20 05:25:01 -06:00
```rust
2019-08-05 21:07:12 -05:00
// 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.
2019-02-20 05:25:01 -06:00
```
2019-08-05 21:07:12 -05:00
# Internal Options
2019-02-18 13:35:22 -06:00
## `emit_mode`
2018-05-20 21:11:15 -05:00
Internal option
2019-02-18 13:35:22 -06:00
## `make_backup`
2018-05-20 21:11:15 -05:00
Internal option, use `--backup`
2019-08-18 21:04:40 -05:00
## `print_misformatted_file_names`
Internal option, use `-l` or `--files-with-diff`