From 35cd72d9890d4800886de4fd3e4a4f245c3931d2 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 7 Oct 2017 21:48:05 +0900 Subject: [PATCH] Use correct budget for the last child of chain --- src/chains.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/chains.rs b/src/chains.rs index 74c43d783b7c..c5a1644b67a8 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -182,7 +182,17 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) - let all_in_one_line = !parent_rewrite_contains_newline && rewrites.iter().all(|s| !s.contains('\n')) && almost_total < one_line_budget; - let rewrite_last = || rewrite_chain_subexpr(last_subexpr, total_span, context, nested_shape); + let last_shape = if rewrites.is_empty() { + // We only have a single child. + first_child_shape + } else { + match context.config.chain_indent() { + IndentStyle::Visual => other_child_shape.sub_width(shape.rhs_overhead(context.config))?, + IndentStyle::Block => other_child_shape, + } + }; + let last_shape = last_shape.sub_width(suffix_try_num)?; + let rewrite_last = || rewrite_chain_subexpr(last_subexpr, total_span, context, last_shape); let (last_subexpr_str, fits_single_line) = if all_in_one_line || extend_last_subexr { parent_shape.offset_left(almost_total).map(|shape| { if let Some(rw) = rewrite_chain_subexpr(last_subexpr, total_span, context, shape) {