diff --git a/src/chains.rs b/src/chains.rs index 5da00d29330d..fbc42a5d84e8 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 a2c5f1c077ce..7226357f7a38 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -286,7 +286,7 @@ pub fn rewrite_pair(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 @@ fn count_line_breaks(src: &str) -> usize { // 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 @@ fn count_line_breaks(src: &str) -> usize { 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,