Add chain_split_single_child option

This commit is contained in:
topecongiro 2017-05-25 16:07:56 +09:00
parent c69608a7e0
commit 2580d7a310
4 changed files with 38 additions and 5 deletions

View File

@ -112,6 +112,28 @@ let lorem = ipsum.dolor().sit().amet().consectetur().adipiscing().elit();
#### Lines longer than `chain_one_line_max`:
See [`chain_indent`](#chain_indent).
## `chain_split_single_child`
Split a chain with a single child if its length exceeds [`chain_one_line_max`](#chain_one_line_max).
- **Default value**: `false`
- **Possible values**: `false`, `true`
#### `false`
```rust
let files = fs::read_dir("tests/coverage/source").expect("Couldn't read source dir");
```
#### `true`
```rust
let files = fs::read_dir("tests/coverage/source")
.expect("Couldn't read source dir");
```
See also [`chain_one_line_max`](#chain_one_line_max).
## `closure_block_indent_threshold`
How many lines a closure must have before it is block indented. -1 means never use block indent.

View File

@ -163,10 +163,10 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
first_child_shape,
other_child_shape);
let child_shape_iter = Some(first_child_shape)
.into_iter()
.chain(::std::iter::repeat(other_child_shape)
.take(subexpr_list.len() - 1));
let child_shape_iter =
Some(first_child_shape)
.into_iter()
.chain(::std::iter::repeat(other_child_shape).take(subexpr_list.len() - 1));
let iter = subexpr_list.iter().rev().zip(child_shape_iter);
let mut rewrites = try_opt!(iter.map(|(e, shape)| {
rewrite_chain_subexpr(e, total_span, context, shape)
@ -186,7 +186,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
if rewrites.len() > 1 {
true
} else if rewrites.len() == 1 {
parent_rewrite.len() > context.config.chain_one_line_max() / 2
context.config.chain_split_single_child() || one_line_len > shape.width
} else {
false
}

View File

@ -0,0 +1,5 @@
// rustfmt-chain_split_single_child: false
fn main() {
let files = fs::read_dir("tests/source").expect("Couldn't read source dir");
}

View File

@ -0,0 +1,6 @@
// rustfmt-chain_split_single_child: true
fn main() {
let files = fs::read_dir("tests/source")
.expect("Couldn't read source dir");
}