Argument density in functions
- **Default value**: `"Tall"`
-- **Possible values**: `"Compressed"`, `"CompressedIfEmpty"`, `"Tall"`, `"Vertical"`
+- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
#### `"Tall"` (default):
}
```
-#### `"CompressedIfEmpty"`:
-
-```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
```
+## `empty_item_single_line`
-## `fn_empty_single_line`
-
-Put empty-body functions on a single line
+Put empty-body functions and impls on a single line
- **Default value**: `true`
- **Possible values**: `true`, `false`
```rust
fn lorem() {}
+
+impl Lorem {}
```
#### `false`:
```rust
fn lorem() {
}
+
+impl Lorem {
+}
```
-See also [`control_brace_style`](#control_brace_style).
+See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
## `fn_single_line`
See also: [`tab_spaces`](#tab_spaces).
-## `impl_empty_single_line`
-
-Put empty-body implementations on a single line
-
-- **Default value**: `true`
-- **Possible values**: `true`, `false`
-
-#### `true` (default):
-
-```rust
-impl Lorem {}
-```
-
-#### `false`:
-
-```rust
-impl Lorem {
-}
-```
-
-See also [`brace_style`](#brace_style).
-
## `imports_indent`
}
```
-See also: [`trailing_comma`](#trailing_comma), [`wrap_match_arms`](#wrap_match_arms).
+See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks).
## `max_width`
// commodo consequat.
```
-## `wrap_match_arms`
+## `match_arm_blocks`
Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms
Compressed,
// Use more lines.
Tall,
- // Try to compress if the body is empty.
- CompressedIfEmpty,
// Place every item on a separate line.
Vertical,
}
pub fn to_list_tactic(self) -> ListTactic {
match self {
Density::Compressed => ListTactic::Mixed,
- Density::Tall | Density::CompressedIfEmpty => ListTactic::HorizontalVertical,
+ Density::Tall => ListTactic::HorizontalVertical,
Density::Vertical => ListTactic::Vertical,
}
}
normalize_comments: bool, false, true, "Convert /* */ comments to // comments where possible";
// Single line expressions and items.
+ empty_item_single_line: bool, true, false,
+ "Put empty-body functions and impls on a single line";
struct_lit_single_line: bool, true, false,
"Put small struct literals on a single line";
- impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";
- fn_empty_single_line: bool, true, false, "Put empty-body functions on a single line";
fn_single_line: bool, false, false, "Put single-expression functions on a single line";
where_single_line: bool, false, false, "To force single line where layout";
reorder_imported_names: bool, true, false,
"Reorder lists of names in import statements alphabetically";
- // Match
- wrap_match_arms: bool, true, false, "Wrap the body of arms in blocks when it does not fit on \
- the same line with the pattern of arms";
- match_block_trailing_comma: bool, false, false,
- "Put a trailing comma after a block based match arm (non-block arms are not affected)";
-
// Spaces around punctuation
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
"Where to put a binary operator when a binary expression goes multiline.";
"Remove blank lines at start or end of a block";
same_line_attributes: bool, true, false,
"Try to put attributes on the same line as fields and variants.";
+ match_arm_blocks: bool, true, false, "Wrap the body of arms in blocks when it does not fit on \
+ the same line with the pattern of arms";
force_multiline_blocks: bool, false, false,
"Force multiline closure bodies and match arms to be wrapped in a block";
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
"How to handle trailing commas for lists";
trailing_semicolon: bool, true, false,
"Add trailing semicolon after break, continue and return";
+ match_block_trailing_comma: bool, false, false,
+ "Put a trailing comma after a block based match arm (non-block arms are not affected)";
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
let indent_str = shape.indent.to_string(context.config);
let nested_indent_str = next_line_indent.to_string(context.config);
- let (body_prefix, body_suffix) = if context.config.wrap_match_arms() {
+ let (body_prefix, body_suffix) = if context.config.match_arm_blocks() {
let comma = if context.config.match_block_trailing_comma() {
","
} else {
let codemap = self.get_context().codemap;
- if self.config.fn_empty_single_line() && is_empty_block(block, codemap)
+ if self.config.empty_item_single_line() && is_empty_block(block, codemap)
&& self.block_indent.width() + fn_str.len() + 2 <= self.config.max_width()
{
return Some(format!("{}{{}}", fn_str));
let open_pos = snippet.find_uncommented("{")? + 1;
Some(
- context.config.impl_empty_single_line() && items.is_empty() && !result.contains('\n')
+ context.config.empty_item_single_line() && items.is_empty() && !result.contains('\n')
&& result.len() + where_clause_str.len() <= context.config.max_width()
&& !contains_comment(&snippet[open_pos..]),
)
--- /dev/null
+// rustfmt-empty_item_single_line: false
+// Empty impl on single line
+
+impl Lorem {
+
+}
+
+impl Ipsum {
+
+}
+
+fn lorem() {
+}
+
+fn lorem() {
+
+}
--- /dev/null
+// rustfmt-empty_item_single_line: true
+// Empty impl on single line
+
+impl Lorem {
+
+}
+
+impl Ipsum {
+
+}
+
+fn lorem() {
+}
+
+fn lorem() {
+
+}
+++ /dev/null
-// rustfmt-fn_args_density: CompressedIfEmpty
-// Function arguments density
-
-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: onsectetur, adipiscing: Adipiscing, elit: Elit);
-
- // FIXME: Previous line should be formatted like this:
- // fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
- // adipiscing: Adipiscing, elit: Elit);
-
- fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit) {
- // body
- }
-}
+++ /dev/null
-// rustfmt-fn_empty_single_line: false
-// Empty function on single line
-
-fn lorem() {
-}
-
-fn lorem() {
-
-}
+++ /dev/null
-// rustfmt-fn_empty_single_line: true
-// Empty function on single line
-
-fn lorem() {
-}
-
-fn lorem() {
-
-}
+++ /dev/null
-// rustfmt-impl_empty_single_line: false
-// Empty impl on single line
-
-impl Lorem {
-
-}
-
-impl Ipsum {
-
-}
+++ /dev/null
-// rustfmt-impl_empty_single_line: true
-// Empty impl on single line
-
-impl Lorem {
-
-}
-
-impl Ipsum {
-
-}
--- /dev/null
+// rustfmt-match_arm_blocks: false
+// Wrap match-arms
+
+fn main() {
+ match lorem {
+ true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
+ false => {
+ println!("{}", sit)
+ }
+ }
+}
--- /dev/null
+// rustfmt-match_arm_blocks: true
+// Wrap match-arms
+
+fn main() {
+ match lorem {
+ true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
+ false => {
+ println!("{}", sit)
+ }
+ }
+}
+++ /dev/null
-// rustfmt-wrap_match_arms: false
-// Wrap match-arms
-
-fn main() {
- match lorem {
- true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
- false => {
- println!("{}", sit)
- }
- }
-}
+++ /dev/null
-// rustfmt-wrap_match_arms: true
-// Wrap match-arms
-
-fn main() {
- match lorem {
- true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
- false => {
- println!("{}", sit)
- }
- }
-}
// rustfmt-max_width:120
-// rustfmt-wrap_match_arms: false
+// rustfmt-match_arm_blocks: false
// rustfmt-match_block_trailing_comma: true
fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 {
-// rustfmt-wrap_match_arms: false
+// rustfmt-match_arm_blocks: false
// rustfmt-match_block_trailing_comma: true
// Match expressions, no unwrapping of block arms or wrapping of multiline
// expressions.
-// rustfmt-wrap_match_arms: false
+// rustfmt-match_arm_blocks: false
// Match expressions, no unwrapping of block arms or wrapping of multiline
// expressions.
match rewrite {
Some(ref body_str)
if (!body_str.contains('\n') && body_str.len() <= arm_shape.width)
- || !context.config.wrap_match_arms()
+ || !context.config.match_arm_blocks()
|| (extend && first_line_width(body_str) <= arm_shape.width)
|| is_block =>
{
--- /dev/null
+// rustfmt-empty_item_single_line: false
+// Empty impl on single line
+
+impl Lorem {
+}
+
+impl Ipsum {
+}
+
+fn lorem() {
+}
+
+fn lorem() {
+
+}
--- /dev/null
+// rustfmt-empty_item_single_line: true
+// Empty impl on single line
+
+impl Lorem {}
+
+impl Ipsum {}
+
+fn lorem() {}
+
+fn lorem() {}
+++ /dev/null
-// rustfmt-fn_args_density: CompressedIfEmpty
-// Function arguments density
-
-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: onsectetur,
- adipiscing: Adipiscing,
- elit: Elit,
- );
-
- // FIXME: Previous line should be formatted like this:
- // fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
- // adipiscing: Adipiscing, elit: Elit);
-
- fn lorem(
- ipsum: Ipsum,
- dolor: Dolor,
- sit: Sit,
- amet: Amet,
- consectetur: onsectetur,
- adipiscing: Adipiscing,
- elit: Elit,
- ) {
- // body
- }
-}
+++ /dev/null
-// rustfmt-fn_empty_single_line: false
-// Empty function on single line
-
-fn lorem() {
-}
-
-fn lorem() {
-
-}
+++ /dev/null
-// rustfmt-fn_empty_single_line: true
-// Empty function on single line
-
-fn lorem() {}
-
-fn lorem() {}
+++ /dev/null
-// rustfmt-impl_empty_single_line: false
-// Empty impl on single line
-
-impl Lorem {
-}
-
-impl Ipsum {
-}
+++ /dev/null
-// rustfmt-impl_empty_single_line: true
-// Empty impl on single line
-
-impl Lorem {}
-
-impl Ipsum {}
--- /dev/null
+// rustfmt-match_arm_blocks: false
+// Wrap match-arms
+
+fn main() {
+ match lorem {
+ true =>
+ foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
+ false => println!("{}", sit),
+ }
+}
--- /dev/null
+// rustfmt-match_arm_blocks: true
+// Wrap match-arms
+
+fn main() {
+ match lorem {
+ true => {
+ foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
+ }
+ false => println!("{}", sit),
+ }
+}
+++ /dev/null
-// rustfmt-wrap_match_arms: false
-// Wrap match-arms
-
-fn main() {
- match lorem {
- true =>
- foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
- false => println!("{}", sit),
- }
-}
+++ /dev/null
-// rustfmt-wrap_match_arms: true
-// Wrap match-arms
-
-fn main() {
- match lorem {
- true => {
- foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
- }
- false => println!("{}", sit),
- }
-}
// rustfmt-max_width:120
-// rustfmt-wrap_match_arms: false
+// rustfmt-match_arm_blocks: false
// rustfmt-match_block_trailing_comma: true
fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 {
-// rustfmt-wrap_match_arms: false
+// rustfmt-match_arm_blocks: false
// rustfmt-match_block_trailing_comma: true
// Match expressions, no unwrapping of block arms or wrapping of multiline
// expressions.
-// rustfmt-wrap_match_arms: false
+// rustfmt-match_arm_blocks: false
// Match expressions, no unwrapping of block arms or wrapping of multiline
// expressions.