about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-05-19 19:31:01 +0900
committertopecongiro <seuchida@gmail.com>2017-05-23 11:37:12 +0900
commitf2ec5a7bac3f8bdda148307c576f41f2ca005828 (patch)
tree344cf4f1c4bf6e4d79c18fb94df6d93c5f7c74e2 /src
parent520340481d4238d63a4eef2555fba45405dc74b4 (diff)
Refactor source codes
Diffstat (limited to 'src')
-rw-r--r--src/chains.rs1
-rw-r--r--src/expr.rs11
2 files changed, 4 insertions, 8 deletions
diff --git a/src/chains.rs b/src/chains.rs
index 5da00d29330..fbc42a5d84e 100644
--- a/src/chains.rs
+++ b/src/chains.rs
@@ -173,7 +173,6 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
         if rewrites.len() > 1 {
             true
         } else if rewrites.len() == 1 {
-            let one_line_len = parent_rewrite.len() + first_line_width(&rewrites[0]);
             one_line_len > shape.width
         } else {
             false
diff --git a/src/expr.rs b/src/expr.rs
index a2c5f1c077c..7226357f7a3 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -286,7 +286,7 @@ pub fn rewrite_pair<LHS, RHS>(lhs: &LHS,
 
                 let remaining_width = shape
                     .width
-                    .checked_sub(last_line_width(&result))
+                    .checked_sub(last_line_width(&result) + suffix.len())
                     .unwrap_or(0);
 
                 if rhs_result.len() <= remaining_width {
@@ -2106,10 +2106,7 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
             // Expression did not fit on the same line as the identifier or is
             // at least three lines big. Try splitting the line and see
             // if that works better.
-            let new_offset = shape.indent.block_indent(context.config);
-            let max_width = try_opt!((shape.width + shape.indent.width())
-                                         .checked_sub(new_offset.width()));
-            let new_shape = Shape::legacy(max_width, new_offset);
+            let new_shape = try_opt!(shape.block_left(context.config.tab_spaces));
             let new_rhs = ex.rewrite(context, new_shape);
 
             // FIXME: DRY!
@@ -2118,11 +2115,11 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
                     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()) => {
-                    result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
+                    result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
                     result.push_str(replacement_rhs);
                 }
                 (None, Some(ref final_rhs)) => {
-                    result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
+                    result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
                     result.push_str(final_rhs);
                 }
                 (None, None) => return None,