From 8dc53d3750e3b683673b09785b2787543af19bb8 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sat, 15 Apr 2017 16:23:38 +0900 Subject: [PATCH] Check the length of the first line of the last method in the chain --- src/chains.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index 0181cd3d099..9dabf2d0322 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -195,12 +195,19 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) - if fits_single_line { fits_single_line = match expr.node { ref e @ ast::ExprKind::MethodCall(..) => { - rewrite_method_call_with_overflow(e, - &mut last[0], - almost_total, - total_span, - context, - shape) + if rewrite_method_call_with_overflow(e, + &mut last[0], + almost_total, + total_span, + context, + shape) { + // If the first line of the last method does not fit into a single line + // after the others, allow new lines. + let first_line = try_opt!(last[0].lines().nth(0)); + almost_total + first_line.len() < context.config.max_width + } else { + false + } } _ => !last[0].contains('\n'), }