rustfmt
rustfmt, a tool to format Rust code. Documentation: https://rust-lang.github.io/rustfmt
rustfmt.toml.rustfmt.toml
Validate
Check your file against this schema
Opens the validator with this schema already loaded. Paste your
rustfmt.toml and it validates in your browser — nothing is uploaded.
Reference
Fields
Generated directly from the schema, following local
$refs, to two levels of nesting.
| Field | Type | Description |
|---|---|---|
array_width | integer | Maximum width of an array literal before falling back to vertical formatting. Possible values: any positive integer that is less than or equal to the value specified for `max_width` Stable: Yes By default this option is set as a percentage default: 60 |
attr_fn_like_width | integer | Maximum width of the args of a function-like attributes before falling back to vertical formatting. Possible values: any positive integer that is less than or equal to the value specified for `max_width` Stable: Yes By default this option default: 70 |
binop_separator | string | Where to put a binary operator when a binary expression goes multiline. Stable: No (tracking issue: [#3368](https://github.com/rust-lang/rustfmt/issues/3368)) #### `"Front"` (default): ```rust fn main() { let or = default: "Front"one of: "Front", "Back" |
blank_lines_lower_bound | integer | 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. Possible values: *unsigned integer* Stable: No (tracking issue default: 0 |
blank_lines_upper_bound | integer | 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. Possible values: any non-negative integer Stable: No (tracking issue default: 1 |
brace_style | string | Brace style for items Stable: No (tracking issue: [#3376](https://github.com/rust-lang/rustfmt/issues/3376)) ### Functions #### `"SameLineWhere"` (default): ```rust fn lorem() { // body } fn lorem(ipsum: usize) { // body } fn default: "SameLineWhere"one of: "AlwaysNextLine", "PreferSameLine", "SameLineWhere" |
chain_width | integer | Maximum width of a chain to fit on one line. Possible values: any positive integer that is less than or equal to the value specified for `max_width` Stable: Yes By default this option is set as a percentage of `max_width` provided by default: 60 |
color | string | Whether to use colored output or not. Stable: No (tracking issue: [#3385](https://github.com/rust-lang/rustfmt/issues/3385)) default: "Auto"one of: "Auto", "Always", "Never" |
combine_control_expr | boolean | Combine control expressions with function calls. Stable: No (tracking issue: [#3369](https://github.com/rust-lang/rustfmt/issues/3369)) #### `true` (default): ```rust fn example() { // If foo!(if x { foo(); } else { bar(); }); // IfLet default: true |
comment_width | integer | Maximum length of comments. No effect unless `wrap_comments = true`. Possible values: any positive integer Stable: No (tracking issue: [#3349](https://github.com/rust-lang/rustfmt/issues/3349)) **Note:** A value of `0` results in default: 80 |
condense_wildcard_suffixes | boolean | Replace strings of _ wildcards by a single .. in tuple patterns Stable: No (tracking issue: [#3384](https://github.com/rust-lang/rustfmt/issues/3384)) #### `false` (default): ```rust fn main() { let (lorem, ipsum, _, _) = (1, 2, 3, 4); let default: false |
control_brace_style | string | Brace style for control flow constructs Stable: No (tracking issue: [#3377](https://github.com/rust-lang/rustfmt/issues/3377)) #### `"AlwaysSameLine"` (default): ```rust fn main() { if lorem { println!("ipsum!"); } else { default: "AlwaysSameLine"one of: "AlwaysNextLine", "AlwaysSameLine", "ClosingNextLine" |
disable_all_formatting | boolean | 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. Stable: Yes default: false |
edition | string | Specifies which edition is used by the parser. Stable: Yes The `edition` option determines the Rust language edition used for parsing the code. This is important for syntax compatibility but does not directly control formatting behavior default: "2015"one of: "2015", "2018", "2021", "2024" |
empty_item_single_line | boolean | Put empty-body functions and impls on a single line Stable: No (tracking issue: [#3356](https://github.com/rust-lang/rustfmt/issues/3356)) #### `true` (default): ```rust fn lorem() {} impl Lorem {} ``` #### `false`: ```rust fn lorem() { } default: true |
enum_discrim_align_threshold | integer | 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 default: 0 |
error_on_line_overflow | boolean | 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 default: false |
error_on_unformatted | boolean | Error if unable to get comments or string literals within `max_width`, or they are left with trailing whitespaces. Stable: No (tracking issue: [#3392](https://github.com/rust-lang/rustfmt/issues/3392)) default: false |
fn_args_layout | string | 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. Stable: Yes #### `"Tall"` (default): ```rust trait Lorem { fn lorem(ipsum: Ipsum default: "Tall"one of: "Compressed", "Tall", "Vertical" |
fn_call_width | integer | Maximum width of the args of a function call before falling back to vertical formatting. Possible values: any positive integer that is less than or equal to the value specified for `max_width` Stable: Yes By default this option is set as a default: 60 |
fn_params_layout | string | Control the layout of parameters in function signatures. 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) { // default: "Tall"one of: "Compressed", "Tall", "Vertical" |
fn_single_line | boolean | Put single-expression functions on a single line Stable: No (tracking issue: [#3358](https://github.com/rust-lang/rustfmt/issues/3358)) #### `false` (default): ```rust fn lorem() -> usize { 42 } fn lorem() -> usize { let ipsum = 42; ipsum default: false |
force_explicit_abi | boolean | Always print the abi for extern items Stable: Yes **Note:** Non-"C" ABIs are always printed. If `false` then "C" is removed. #### `true` (default): ```rust extern "C" { pub static lorem: c_int; } ``` #### `false`: ```rust extern { pub default: true |
force_multiline_blocks | boolean | Force multiline closure and match arm bodies to be wrapped in a block Stable: No (tracking issue: [#3374](https://github.com/rust-lang/rustfmt/issues/3374)) #### `false` (default): ```rust fn main() { result.and_then(|maybe_value| match default: false |
format_code_in_doc_comments | boolean | Format code snippet included in doc comments. Stable: No (tracking issue: [#3348](https://github.com/rust-lang/rustfmt/issues/3348)) #### `false` (default): ```rust /// Adds one to the number given. /// /// # Examples /// /// ```rust /// default: false |
doc_comment_code_block_width | integer | Max width for code snippets included in doc comments. Only used if `format_code_in_doc_comments` is true. Possible values: any positive integer that is less than or equal to the value specified for `max_width` Stable: No (tracking issue default: 100 |
format_generated_files | boolean | Format generated files. A file is considered generated if any of the first several lines contain a `@generated` comment marker. The number of lines to check is configured by `generated_marker_line_search_limit`. By default, generated files default: true |
generated_marker_line_search_limit | integer | Number of lines to check for a `@generated` pragma header, starting from the top of the file. Setting this value to `0` will treat all files as non-generated. When`format_generated_files` is `true`, this option has no effect. Possible default: 5 |
format_macro_matchers | boolean | Format the metavariable matching patterns in macros. Stable: No (tracking issue: [#3354](https://github.com/rust-lang/rustfmt/issues/3354)) #### `false` (default): ```rust macro_rules! foo { ($a: ident : $b: ty) => { $a(42): $b; }; ($a default: false |
format_macro_bodies | boolean | Format the bodies of declarative macro definitions. Stable: No (tracking issue: [#3355](https://github.com/rust-lang/rustfmt/issues/3355)) #### `true` (default): ```rust macro_rules! foo { ($a: ident : $b: ty) => { $a(42): $b; }; ($a default: true |
skip_macro_invocations | any | 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 default: [] |
format_strings | boolean | Format string literals where necessary Stable: No (tracking issue: [#3353](https://github.com/rust-lang/rustfmt/issues/3353)) #### `false` (default): ```rust fn main() { let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem default: false |
hard_tabs | boolean | Use tab characters for indentation, spaces for alignment Stable: Yes #### `false` (default): ```rust fn lorem() -> usize { 42 // spaces before 42 } ``` #### `true`: ```rust fn lorem() -> usize { 42 // tabs before 42 } ``` See also default: false |
hex_literal_case | string | Control the case of the letters in hexadecimal literal values Stable: No (tracking issue: [#5081](https://github.com/rust-lang/rustfmt/issues/5081)) default: "Preserve"one of: "Preserve", "Upper", "Lower" |
float_literal_trailing_zero | string | Control the presence of trailing zero in floating-point literal values Stable: No (tracking issue: [#6471](https://github.com/rust-lang/rustfmt/issues/6471)) #### `Preserve` (default): Leave the literal as-is. ```rust fn main() { let default: "Preserve"one of: "Preserve", "Always", "IfNoPostfix", "Never" |
hide_parse_errors | boolean | This option is deprecated and has been renamed to `show_parse_errors` to avoid confusion around the double negative default of `hide_parse_errors=false`. Stable: No (tracking issue: [#3390](https://github.com/rust-lang/rustfmt/issues/3390)) default: false |
show_parse_errors | boolean | Show parse errors if the parser failed to parse files. Stable: No (tracking issue: [#5977](https://github.com/rust-lang/rustfmt/issues/5977)) default: true |
ignore | any | 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 |
imports_indent | string | Indent style of imports Stable: No (tracking issue: [#3360](https://github.com/rust-lang/rustfmt/issues/3360)) #### `"Block"` (default): ```rust use foo::{ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy default: "Block"one of: "Block", "Visual" |
imports_layout | string | Item layout inside a imports block Stable: No (tracking issue: [#3361](https://github.com/rust-lang/rustfmt/issues/3361)) #### `"Mixed"` (default): ```rust use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; use foo::{ default: "Mixed"one of: "Horizontal", "HorizontalVertica…, "Mixed", "Vertical" |
indent_style | string | Indent on expressions or items. Stable: No (tracking issue: [#3346](https://github.com/rust-lang/rustfmt/issues/3346)) ### Array #### `"Block"` (default): ```rust fn main() { let lorem = vec) ### Example #### `0` default: 0 |
match_arm_blocks | boolean | 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 default: true |
match_arm_leading_pipes | string | Controls whether to include a leading pipe on match arms Stable: Yes #### `Never` (default): ```rust // Leading pipes are removed from this: // fn foo() { // match foo { // | "foo" | "bar" => {} // | "baz" // | "something relatively long" default: "Never"one of: "Always", "Never", "Preserve" |
match_arm_indent | boolean | Controls whether match arms are indented. If disabled, match arms will be formatted at the same indentation level as the outer `match` statement. Meaning that match blocks will only be indented once, not twice. Stable: No (tracking issue default: true |
match_block_trailing_comma | boolean | Put a trailing comma after a block based match arm (non-block arms are not affected) Stable: Yes #### `false` (default): ```rust fn main() { match lorem { Lorem::Ipsum => { println!("ipsum"); } Lorem::Dolor => println!("dolor"), } } ``` default: false |
max_width | integer | Maximum width of each line Possible values: any positive integer Stable: Yes See also `error_on_line_overflow`. default: 100 |
merge_derives | boolean | Merge multiple derives into a single one. Stable: Yes #### `true` (default): ```rust #[derive(Eq, PartialEq, Debug, Copy, Clone)] pub enum Foo {} ``` #### `false`: ```rust #[derive(Eq, PartialEq, Debug, Copy, Clone)] pub enum Bar {} default: true |
imports_granularity | string | Controls how imports are structured in `use` statements. Imports will be merged or split to the configured level of granularity. Similar to other `import` related configuration options, this option operates within the bounds of default: "Preserve"one of: "Preserve", "Crate", "Module", "Item", "One" |
merge_imports | boolean | This option is deprecated. Use `imports_granularity = "Crate"` instead. Stable: undefined #### `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: false |
newline_style | string | Unix or Windows line endings Stable: Yes #### `Auto` (default): The newline style is detected automatically on a per-file basis. Files with mixed line endings will be converted to the first detected line ending style. #### `Native` Line default: "Auto"one of: "Auto", "Native", "Unix", "Windows" |
normalize_comments | boolean | Convert /* */ comments to // comments where possible Stable: No (tracking issue: [#3350](https://github.com/rust-lang/rustfmt/issues/3350)) #### `false` (default): ```rust // Lorem ipsum: fn dolor() -> usize {} /* sit amet: */ fn default: false |
normalize_doc_attributes | boolean | Convert `#![doc]` and `#[doc]` attributes to `//!` and `///` doc comments. Stable: No (tracking issue: [#3351](https://github.com/rust-lang/rustfmt/issues/3351)) #### `false` (default): ```rust #![doc = "Example documentation"] #[doc = default: false |
overflow_delimited_expr | boolean | 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. Stable: No (tracking issue default: false |
remove_nested_parens | boolean | Remove nested parens. Stable: Yes #### `true` (default): ```rust fn main() { (foo()); } ``` #### `false`: ```rust fn main() { (foo()); ((((foo())))); } ``` default: true |
reorder_impl_items | boolean | Reorder impl items. `type` and `const` are put first, then macros and methods. Stable: No (tracking issue: [#3363](https://github.com/rust-lang/rustfmt/issues/3363)) #### `false` (default) ```rust struct Dummy; impl Iterator for Dummy { fn default: false |
reorder_imports | boolean | Reorder import and extern crate statements alphabetically in groups (a group is separated by a newline). Stable: Yes #### `true` (default): ```rust use dolor; use ipsum; use lorem; use sit; ``` #### `false`: ```rust use lorem; use ipsum default: true |
group_imports | string | 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 default: "Preserve"one of: "Preserve", "StdExternalCrate", "One" |
reorder_modules | boolean | Reorder `mod` declarations alphabetically in group. Stable: Yes #### `true` (default) ```rust mod a; mod b; mod dolor; mod ipsum; mod lorem; mod sit; ``` #### `false` ```rust mod b; mod a; mod lorem; mod ipsum; mod dolor; mod sit; ``` default: true |
required_version | any | 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. Possible values: `semver` compliant values, such as defined on [semver.org](https://semver.org/) default: "CARGO_PKG_VERSION" |
short_array_element_width_threshold | integer | 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") default: 10 |
skip_children | boolean | Don't reformat out of line modules Stable: No (tracking issue: [#3389](https://github.com/rust-lang/rustfmt/issues/3389)) default: false |
single_line_if_else_max_width | integer | 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`. Possible values: any default: 50 |
single_line_let_else_max_width | integer | Maximum line length for single line let-else statements. See the [let-else statement section of the Rust Style Guide](https://github.com/rust-lang/rust/blob/master/src/doc/style-guide/src/statements.md#else-blocks-let-else-statements) for default: 50 |
space_after_colon | boolean | Leave a space after the colon. Stable: No (tracking issue: [#3366](https://github.com/rust-lang/rustfmt/issues/3366)) #### `true` (default): ```rust fn lorem<T: Eq>(t: T) { let lorem: Dolor = Lorem { ipsum: dolor, sit: amet, }; } ``` #### default: true |
space_before_colon | boolean | Leave a space before the colon. Stable: No (tracking issue: [#3365](https://github.com/rust-lang/rustfmt/issues/3365)) #### `false` (default): ```rust fn lorem<T: Eq>(t: T) { let lorem: Dolor = Lorem { ipsum: dolor, sit: amet, }; } ``` default: false |
spaces_around_ranges | boolean | Put spaces around the .., ..=, and ... range operators Stable: No (tracking issue: [#3367](https://github.com/rust-lang/rustfmt/issues/3367)) #### `false` (default): ```rust fn main() { let lorem = 0..10; let ipsum = 0..=10; match lorem { default: false |
struct_field_align_threshold | integer | The maximum diff of width between struct fields to be aligned with each other. Possible values: any non-negative integer Stable: No (tracking issue: [#3371](https://github.com/rust-lang/rustfmt/issues/3371)) #### `0` (default): ```rust default: 0 |
struct_lit_single_line | boolean | Put small struct literals on a single line Stable: No (tracking issue: [#3357](https://github.com/rust-lang/rustfmt/issues/3357)) #### `true` (default): ```rust fn main() { let lorem = Lorem { foo: bar, baz: ofo }; } ``` #### `false` default: true |
struct_lit_width | integer | 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 default: 18 |
struct_variant_width | integer | 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 default: 35 |
style_edition | any | Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]) Possible values: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant) Stable: No This option is inferred from the `edition` if not specified. See [Rust default: "2015" |
tab_spaces | integer | Number of spaces per tab Possible values: any positive integer Stable: Yes #### `4` (default): ```rust fn lorem() { let ipsum = dolor(); let sit = vec) #### `"Vertical"` (default): ```rust fn main() { let Lorem { ipsum, dolor, sit } = amet; let Lorem { ipsum default: "Vertical"one of: "Always", "Never", "Vertical" |
trailing_semicolon | boolean | Add trailing semicolon after break, continue and return Stable: No (tracking issue: [#3378](https://github.com/rust-lang/rustfmt/issues/3378)) #### `true` (default): ```rust fn foo() -> usize { return 0; } ``` #### `false`: ```rust fn default: true |
type_punctuation_density | string | Determines if `+` or `=` are wrapped in spaces in the punctuation of types Stable: No (tracking issue: [#3364](https://github.com/rust-lang/rustfmt/issues/3364)) #### `"Wide"` (default): ```rust fn lorem<Ipsum: Dolor + Sit = Amet>() { // default: "Wide"one of: "Compressed", "Wide" |
unstable_features | boolean | Enable unstable features on the unstable channel. Stable: No (tracking issue: [#3387](https://github.com/rust-lang/rustfmt/issues/3387)) default: false |
use_field_init_shorthand | boolean | Use field initialize shorthand if possible. Stable: Yes #### `false` (default): ```rust struct Foo { x: u32, y: u32, z: u32, } fn main() { let x = 1; let y = 2; let z = 3; let a = Foo { x, y, z }; let b = Foo { x: x, y: y, z: z }; } ``` default: false |
use_small_heuristics | string | This option can be used to simplify the management and bulk updates of the granular width configuration settings (`fn_call_width`, `attr_fn_like_width`, `struct_lit_width`, `struct_variant_width`, `array_width`, `chain_width` default: "Default"one of: "Default", "Off", "Max" |
use_try_shorthand | boolean | Replace uses of the try! macro by the ? shorthand Stable: Yes #### `false` (default): ```rust fn main() { let lorem = ipsum.map(|dolor| dolor.sit())?; let lorem = try!(ipsum.map(|dolor| dolor.sit())); } ``` #### `true`: ```rust fn main() { default: false |
version | string | This option is deprecated and has been replaced by `style_edition`. `version = "One"` is equivalent to `style_edition = "(2015|2018|2021)"` and `version = "Two"` is equivalent to `style_edition = "2024"` Stable: No (tracking issue default: "One"one of: "One", "Two" |
where_single_line | boolean | Forces the `where` clause to be laid out on a single line. Stable: No (tracking issue: [#3359](https://github.com/rust-lang/rustfmt/issues/3359)) #### `false` (default): ```rust impl<T> Lorem for T where Option<T>: Ipsum, { // body } ``` default: false |
wrap_comments | boolean | Break comments to fit on the line Note that no wrapping will happen if: 1. The comment is the start of a markdown header doc comment 2. A URL was found in the comment Stable: No (tracking issue default: false |
Audit
What we found in this schema
- Declared draft: draft-07
- Validates cleanly against its own meta-schema.
- Uses non-standard keywords that generic validators ignore:
annotations. - 83 properties, 100% carrying a description, max nesting depth 3.
Standards
Specification sections for the keywords in this schema
| Keyword | Document | Section |
|---|---|---|
$comment | JSON Schema Core, draft 2020-12 | §8.3 — Comments With "$comment" |
$id | JSON Schema Core, draft 2020-12 | §8.2.1 — The "$id" Keyword |
$schema | JSON Schema Core, draft 2020-12 | §8.1.1 — "$schema" |
default | JSON Schema Validation, draft 2020-12 | §9.2 — "default" |
description | JSON Schema Validation, draft 2020-12 | §9.1 — "title" and "description" |
enum | JSON Schema Validation, draft 2020-12 | §6.1.2 — "enum" |
properties | JSON Schema Core, draft 2020-12 | §10.3.2.1 — "properties" |
type | JSON Schema Validation, draft 2020-12 | §6.1.1 — "type" |
Documents
- JSON Schema Core, draft 2020-12 — JSON Schema: A Media Type for Describing JSON Documents, A. Wright, H. Andrews, B. Hutton, G. Dennis, Eds., 2022. draft-bhutton-json-schema-01. An expired Internet-Draft with no formal standing in the IETF standards process; it is nonetheless the specification of record for JSON Schema 2020-12, published by json-schema.org.
- JSON Schema Validation, draft 2020-12 — JSON Schema Validation: A Vocabulary for Structural Validation of JSON, A. Wright, H. Andrews, B. Hutton, Eds., 2022.
- RFC 8259 (STD 90) — The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray, Ed., 2017. The format a schema describes.
- RFC 6901 — JavaScript Object Notation (JSON) Pointer. Defines the pointer syntax used by $ref fragments and the ~0 / ~1 escapes.
Source
Attribution
This schema comes from SchemaStore, distributed under the Apache License 2.0. Copyright 2015–present Mads Kristensen and contributors. View the original file. The field table and audit on this page are generated by JSONTools.tools; the schema itself is unmodified.