From 760d6b85e2e8b837ee441e404b9eafd1c17be7c2 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 26 Jul 2017 17:41:45 +0900 Subject: [PATCH] Ignore the last line overhead when rewriting condition --- src/expr.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index f6edc454a77..99208b92134 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1156,12 +1156,23 @@ fn rewrite_cond( shape: Shape, alt_block_sep: &str, ) -> Option<(String, usize)> { + // Do not take the rhs overhead from the upper expressions into account + // when rewriting pattern. + let new_width = context + .config + .max_width() + .checked_sub(shape.used_width()) + .unwrap_or(0); + let fresh_shape = Shape { + width: new_width, + ..shape + }; let constr_shape = if self.nested_if { // We are part of an if-elseif-else chain. Our constraints are tightened. // 7 = "} else " .len() - try_opt!(shape.offset_left(7)) + try_opt!(fresh_shape.offset_left(7)) } else { - shape + fresh_shape }; let label_string = rewrite_label(self.label);