about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2018-07-11 21:01:40 +1200
committerNick Cameron <ncameron@mozilla.com>2018-07-24 15:43:29 +1200
commitf0fe9c3c4acb4eafba5a552a2823e6997e75a3f4 (patch)
treef28efab727642d68955b9286b9fac80efd76f4fd /src/expr.rs
parent5bc27593f44a7c2108ca1a69eba2d34b3db90935 (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/expr.rs')
-rw-r--r--src/expr.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 6e1af266e9b..8aa5d9bd286 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -39,9 +39,9 @@ use spanned::Spanned;
 use string::{rewrite_string, StringFormat};
 use types::{can_be_overflowed_type, rewrite_path, PathContext};
 use utils::{
-    colon_spaces, contains_skip, count_newlines, first_line_width, inner_attributes,
-    last_line_extendable, last_line_width, mk_sp, outer_attributes, ptr_vec_to_ref_vec,
-    semicolon_for_stmt, wrap_str,
+    colon_spaces, contains_skip, count_newlines, first_line_ends_with, first_line_width,
+    inner_attributes, last_line_extendable, last_line_width, mk_sp, outer_attributes,
+    ptr_vec_to_ref_vec, semicolon_for_stmt, wrap_str,
 };
 use vertical::rewrite_with_alignment;
 use visitor::FmtVisitor;
@@ -1953,6 +1953,9 @@ pub fn prefer_next_line(orig_rhs: &str, next_line_rhs: &str, rhs_tactics: RhsTac
     rhs_tactics == RhsTactics::ForceNextLineWithoutIndent
         || !next_line_rhs.contains('\n')
         || count_newlines(orig_rhs) > count_newlines(next_line_rhs) + 1
+        || first_line_ends_with(orig_rhs, '(') && !first_line_ends_with(next_line_rhs, '(')
+        || first_line_ends_with(orig_rhs, '{') && !first_line_ends_with(next_line_rhs, '{')
+        || first_line_ends_with(orig_rhs, '[') && !first_line_ends_with(next_line_rhs, '[')
 }
 
 fn rewrite_expr_addrof(