]> git.lizzy.rs Git - rust.git/commitdiff
Use correct budget for chain
authortopecongiro <seuchida@gmail.com>
Sat, 17 Jun 2017 07:56:37 +0000 (16:56 +0900)
committertopecongiro <seuchida@gmail.com>
Sat, 17 Jun 2017 07:56:37 +0000 (16:56 +0900)
src/chains.rs
src/expr.rs

index 899d01ac4c5a2ab58c41f6f17213f23cfcb9ffce..ed5278e81fc3f1bedf7af245f570c3f81c08e63c 100644 (file)
@@ -124,7 +124,9 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
     let first_subexpr_is_try = subexpr_list.last().map_or(false, is_try);
     let (nested_shape, extend) = if !parent_rewrite_contains_newline && is_continuable(&parent) {
         let nested_shape = if first_subexpr_is_try {
-            parent_shape.block_indent(context.config.tab_spaces())
+            parent_shape
+                .block_indent(context.config.tab_spaces())
+                .with_max_width(context.config)
         } else {
             chain_indent(context, shape.add_offset(parent_rewrite.len()))
         };
@@ -143,7 +145,12 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
     } else if parent_rewrite_contains_newline {
         (chain_indent(context, parent_shape), false)
     } else {
-        (shape.block_indent(context.config.tab_spaces()), false)
+        (
+            shape
+                .block_indent(context.config.tab_spaces())
+                .with_max_width(context.config),
+            false,
+        )
     };
 
     let other_child_shape = nested_shape.with_max_width(context.config);
@@ -234,7 +241,8 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
         }
     }
 
-    // Try overflowing the last element if we are using block indent.
+    // Try overflowing the last element if we are using block indent and it goes multi line
+    // or it fits in a single line but goes over the max width.
     if !fits_single_line && context.use_block_indent() {
         let (init, last) = rewrites.split_at_mut(last_non_try_index);
         let almost_single_line = init.iter().all(|s| !s.contains('\n'));
index 8e2fe782ce987fc5102c07708c6f4038c44fe2bb..d22c3f21a779270406b3f0f15c1ef45c77e9b0ed 100644 (file)
@@ -2761,9 +2761,7 @@ fn count_line_breaks(src: &str) -> usize {
             // FIXME: DRY!
             match (rhs, new_rhs) {
                 (Some(ref orig_rhs), Some(ref replacement_rhs))
-                    if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 ||
-                           (orig_rhs.rewrite(context, shape).is_none() &&
-                                replacement_rhs.rewrite(context, new_shape).is_some()) => {
+                    if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 => {
                     result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
                     result.push_str(replacement_rhs);
                 }