diff options
| author | topecongiro <seuchida@gmail.com> | 2017-06-01 19:59:50 +0900 |
|---|---|---|
| committer | topecongiro <seuchida@gmail.com> | 2017-06-01 19:59:50 +0900 |
| commit | fbd4b87329324e3d53064601cccf7c8e4ced5b31 (patch) | |
| tree | 2b3ec86d551f6bca738326aa045e2caa10a19cab /src/expr.rs | |
| parent | b79094262f9737b3fd0379fdd2cb0fc6e23008ad (diff) | |
Use correct one line budget when using Rfc control style
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/expr.rs b/src/expr.rs index a8f1c3a01b5..b05c7ba6c97 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -326,23 +326,29 @@ pub fn rewrite_pair<LHS, RHS>(lhs: &LHS, // Re-evaluate the rhs because we have more space now: let infix = infix.trim_right(); - let lhs_budget = try_opt!(context - .config - .max_width() - .checked_sub(shape.used_width() + prefix.len() + infix.len())); let rhs_shape = match context.config.control_style() { Style::Default => { try_opt!(shape.sub_width(suffix.len() + prefix.len())).visual_indent(prefix.len()) } - Style::Rfc => try_opt!(shape.block_left(context.config.tab_spaces())), + Style::Rfc => { + shape + .block_indent(context.config.tab_spaces()) + .with_max_width(context.config) + } }; let rhs_result = try_opt!(rhs.rewrite(context, rhs_shape)); - let lhs_result = try_opt!(lhs.rewrite(context, - Shape { - width: lhs_budget, - ..shape - })); + let lhs_shape = match context.config.control_style() { + Style::Default => { + let lhs_overhead = shape.used_width() + prefix.len() + infix.len(); + Shape { + width: try_opt!(context.config.max_width().checked_sub(lhs_overhead)), + ..shape + } + } + Style::Rfc => try_opt!(shape.sub_width(prefix.len() + infix.len())), + }; + let lhs_result = try_opt!(lhs.rewrite(context, lhs_shape)); Some(format!("{}{}{}\n{}{}{}", prefix, lhs_result, @@ -906,7 +912,7 @@ impl<'a> Rewrite for ControlFlow<'a> { Some(cond) => { let mut cond_shape = match context.config.control_style() { Style::Default => try_opt!(constr_shape.shrink_left(add_offset)), - Style::Rfc => constr_shape, + Style::Rfc => try_opt!(constr_shape.sub_width(add_offset)), }; if context.config.control_brace_style() != ControlBraceStyle::AlwaysNextLine { // 2 = " {".len() |
