diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2018-07-11 21:01:40 +1200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2018-07-24 15:43:29 +1200 |
| commit | f0fe9c3c4acb4eafba5a552a2823e6997e75a3f4 (patch) | |
| tree | f28efab727642d68955b9286b9fac80efd76f4fd /src/chains.rs | |
| parent | 5bc27593f44a7c2108ca1a69eba2d34b3db90935 (diff) | |
chains: prefer to use the next line for an expression, if using the same line would introduce an open block or similar
This problem came to light due to the chains changes, but effects other code too. It only happens rarely, e.g.,
before this fix:
```
match foo {
MacroArgKind::Delimited(ref delim_tok, ref args) => rewrite_delimited_inner(
delim_tok,
args,
).map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs)),
};
```
after:
```
match foo {
MacroArgKind::Delimited(ref delim_tok, ref args) => {
rewrite_delimited_inner(delim_tok, args)
.map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs))
}
}
```
Diffstat (limited to 'src/chains.rs')
| -rw-r--r-- | src/chains.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/chains.rs b/src/chains.rs index 81be8d54128..d7126b2f5e7 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -398,8 +398,8 @@ impl <'a> ChainFormatterShared<'a> { if all_in_one_line || extendable { // First we try to 'overflow' the last child and see if it looks better than using // vertical layout. - if let Some(shape) = last_shape.offset_left(almost_total) { - if let Some(rw) = last.rewrite_postfix(context, shape) { + if let Some(one_line_shape) = last_shape.offset_left(almost_total) { + if let Some(rw) = last.rewrite_postfix(context, one_line_shape) { // We allow overflowing here only if both of the following conditions match: // 1. The entire chain fits in a single line except the last child. // 2. `last_child_str.lines().count() >= 5`. @@ -413,6 +413,7 @@ impl <'a> ChainFormatterShared<'a> { // layout, just by looking at the overflowed rewrite. Now we rewrite the // last child on its own line, and compare two rewrites to choose which is // better. + let last_shape = child_shape.sub_width(shape.rhs_overhead(context.config) + last.tries)?; match last.rewrite_postfix(context, last_shape) { Some(ref new_rw) if !could_fit_single_line => { last_subexpr_str = Some(new_rw.clone()); |
