```toml
indent_style = "Block"
-reorder_imported_names = true
+reorder_imports = false
```
Each configuration option is either stable or unstable.
```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
{
// ...
```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
{
// ...
let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
|| barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
- let sum = 123456789012345678901234567890 + 123456789012345678901234567890
+ let sum = 123456789012345678901234567890
+ + 123456789012345678901234567890
+ 123456789012345678901234567890;
let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
let or = foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo ||
barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar;
- let sum = 123456789012345678901234567890 + 123456789012345678901234567890 +
+ let sum = 123456789012345678901234567890 +
+ 123456789012345678901234567890 +
123456789012345678901234567890;
let range = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
## `error_on_line_overflow`
-Error if unable to get all lines within `max_width`, except for comments and string literals.
+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**: `true`
+- **Default value**: `false`
- **Possible values**: `true`, `false`
- **Stable**: No
## `where_single_line`
-To force single line where layout
+Forces the `where` clause to be laid out on a single line.
- **Default value**: `false`
- **Possible values**: `true`, `false`
```rust
use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz};
-use foo::{aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
- eeeeeeeeeeeeeeeeee, ffffffffffffffffff};
+use foo::{
+ aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd,
+ eeeeeeeeeeeeeeeeee, ffffffffffffffffff,
+};
```
#### `"Horizontal"`:
```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};
```
- **Default value**: `false`
- **Possible values**: `true`, `false`
-- **Stable**: Yes
+- **Stable**: No
#### `false` (default):
fn adipiscing() -> usize {}
```
-## `reorder_imported_names`
+## `remove_nested_parens`
-Reorder lists of names in import statements alphabetically
+Remove nested parens.
-- **Default value**: `false`
+- **Default value**: `true`,
- **Possible values**: `true`, `false`
-- **Stable**: No
+- **Stable**: Yes
-#### `false` (default):
+#### `true` (default):
```rust
-use super::{lorem, ipsum, dolor, sit};
+fn main() {
+ (foo());
+}
```
-#### `true`:
-
+#### `false`:
```rust
-use super::{dolor, ipsum, lorem, sit};
+fn main() {
+ ((((foo()))));
+}
```
-See also [`reorder_imports`](#reorder_imports).
## `reorder_imports`
-Reorder import 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
-
-#### `false` (default):
-
-```rust
-use lorem;
-use ipsum;
-use dolor;
-use sit;
-```
+- **Stable**: Yes
-#### `true`:
+#### `true` (default):
```rust
use dolor;
use sit;
```
-See also [`reorder_imported_names`](#reorder_imported_names), [`reorder_imports_in_group`](#reorder_imports_in_group).
-
-## `reorder_imports_in_group`
-
-Reorder import statements in group
-
-- **Default value**: `false`
-- **Possible values**: `true`, `false`
-- **Stable**: No
-
-**Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`.
-
-#### `false` (default):
+#### `false`:
```rust
-use std::mem;
-use std::io;
-
use lorem;
use ipsum;
use dolor;
use sit;
```
-#### `true`:
-
-```rust
-use std::io;
-use std::mem;
-
-use dolor;
-use ipsum;
-use lorem;
-use sit;
-```
-
-See also [`reorder_imports`](#reorder_imports).
-
-## `reorder_extern_crates`
-
-Reorder `extern crate` statements alphabetically
-
-- **Default value**: `true`
-- **Possible values**: `true`, `false`
-- **Stable**: No
-
-#### `true` (default):
-
-```rust
-extern crate dolor;
-extern crate ipsum;
-extern crate lorem;
-extern crate sit;
-```
-
-#### `false`:
-
-```rust
-extern crate lorem;
-extern crate ipsum;
-
-extern crate dolor;
-extern crate sit;
-```
-
-See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group).
-
-## `reorder_extern_crates_in_group`
-
-Reorder `extern crate` statements in group
-
-- **Default value**: `true`
-- **Possible values**: `true`, `false`
-- **Stable**: No
-
-#### `true` (default):
-
-**Note:** This only takes effect when [`reorder_extern_crates`](#reorder_extern_crates) is set to `true`.
-
-```rust
-extern crate a;
-extern crate b;
-
-extern crate dolor;
-extern crate ipsum;
-extern crate lorem;
-extern crate sit;
-```
-
-#### `false`:
-
-This value has no influence beyond the effect of the [`reorder_extern_crates`](#reorder_extern_crates) option. Set [`reorder_extern_crates`](#reorder_extern_crates) to `false` if you do not want `extern crate` groups to be collapsed and ordered.
## `reorder_modules`
- **Default value**: `true`
- **Possible values**: `true`, `false`
-- **Stable**: No
+- **Stable**: Yes
-#### `true`
+#### `true` (default)
```rust
mod a;
**Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantic
of the original source code.
+## `reorder_impl_items`
+
+Reorder impl items. `type` and `const` are put first, then macros and methods.
+
+- **Default value**: `false`
+- **Possible values**: `true`, `false`
+- **Stable**: No
+
+#### `false` (default)
+
+```rust
+struct Dummy;
+
+impl Iterator for Dummy {
+ fn next(&mut self) -> Option<Self::Item> {
+ None
+ }
+
+ type Item = i32;
+}
+```
+
+#### `true`
+
+```rust
+struct Dummy;
+
+impl Iterator for Dummy {
+ type Item = i32;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ None
+ }
+}
+```
+
## `report_todo`
Report `TODO` items in comments.
}
```
-## `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: 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];
-}
-```
-
-#### `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
fn lorem() {
let ipsum = dolor();
let sit = vec![
- "amet consectetur adipiscing elit amet consectetur adipiscing elit amet consectetur.",
+ "amet consectetur adipiscing elit amet",
+ "consectetur adipiscing elit amet consectetur.",
];
}
```
fn lorem() {
let ipsum = dolor();
let sit = vec![
- "amet consectetur adipiscing elit amet consectetur adipiscing elit amet consectetur.",
+ "amet consectetur adipiscing elit amet",
+ "consectetur adipiscing elit amet consectetur.",
];
}
```
- **Default value**: `false`
- **Possible values**: `true`, `false`
-- **Stable**: No
+- **Stable**: Yes
#### `false` (default):
- **Default value**: `false`
- **Possible values**: `true`, `false`
-- **Stable**: No
+- **Stable**: Yes
#### `false` (default):
- **Default value**: `false`
- **Possible values**: `true`, `false`
-- **Stable**: Yes
+- **Stable**: No
#### `false` (default):
See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
-## `write_mode`
-
-What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage
-
-- **Default value**: `"Overwrite"`
-- **Possible values**: `"Checkstyle"`, `"Coverage"`, `"Diff"`, `"Display"`, `"Overwrite"`, `"Plain"`, `"Replace"`
-- **Stable**: No
## `blank_lines_upper_bound`
Original Code:
```rust
-#![rustfmt_skip]
+#![rustfmt::skip]
fn foo() {
println!("a");
Original Code (rustfmt will not change it with the default value of `0`):
```rust
-#![rustfmt_skip]
+#![rustfmt::skip]
fn foo() {
println!("a");
}
```
-## `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`
## `unstable_features`
-Enable unstable featuers on stable channel.
+Enable unstable features on stable channel.
- **Default value**: `false`
- **Possible values**: `true`, `false`
-- **Stable**: Yes
+- **Stable**: No
+
+## `license_template_path`
+
+Check whether beginnings of files match a license template.
+
+- **Default value**: `""``
+- **Possible values**: path to a license template file
+- **Stable**: No
+
+A license template is a plain text file which is matched literally against the
+beginning of each source file, except for `{}`-delimited blocks, which are
+matched as regular expressions. The following license template therefore
+matches strings like `// Copyright 2017 The Rust Project Developers.`, `//
+Copyright 2018 The Rust Project Developers.`, etc.:
+
+```
+// Copyright {\d+} The Rust Project Developers.
+```
+
+`\{`, `\}` and `\\` match literal braces / backslashes.
+
+## `ignore`
+
+Skip formatting the specified files and directories.
+
+- **Default value**: format every files
+- **Possible values**: See an example below
+- **Stable**: No
+
+### 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",
+]
+```
+
+## `emit_mode`
+
+Internal option
+
+## `make_backup`
+
+Internal option, use `--backup`