about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-05-24 00:06:23 +0900
committertopecongiro <seuchida@gmail.com>2017-05-24 00:06:23 +0900
commit92b54d6490fc638a136c07b42921ba7ff67743fa (patch)
tree7f419d83c7b0594d86e900f5a49861a7450a5eef /src
parentec33121aafb081f33c78f062492cd61b77cef565 (diff)
Add heuristic when rewriting chain with a single child
rustfmt splits chain into multiline when the length of chain exceeds
`chain_one_line_max`. However, currenly this rule only applies when the chain
has more than one child. This can lead to unexpected long chain if the parent
is long. This commit adds heuristic that if the length of parent is longer
than the half of `chain_one_line_max` we use multiline even if there is
only a single child.
Diffstat (limited to 'src')
-rw-r--r--src/chains.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/chains.rs b/src/chains.rs
index 7ab81aa7197..5ea43708af3 100644
--- a/src/chains.rs
+++ b/src/chains.rs
@@ -155,10 +155,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))
@@ -175,7 +175,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
         if rewrites.len() > 1 {
             true
         } else if rewrites.len() == 1 {
-            one_line_len > shape.width
+            parent_rewrite.len() > context.config.chain_one_line_max() / 2
         } else {
             false
         }