Add chain_split_single_child option
This commit is contained in:
parent
c69608a7e0
commit
2580d7a310
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
5
tests/target/configs-chain_split_single_child-false.rs
Normal file
5
tests/target/configs-chain_split_single_child-false.rs
Normal 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");
|
||||
}
|
6
tests/target/configs-chain_split_single_child-true.rs
Normal file
6
tests/target/configs-chain_split_single_child-true.rs
Normal 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");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user