From cf8b191852ba63e0c1c645cfb1af9d832fc613ee Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Thu, 20 Jul 2017 00:09:03 +0900 Subject: [PATCH] Put the brace of match on the next line if condition is multi-lined --- src/expr.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 1b8cfbe8c04..14bf46e966f 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1514,15 +1514,17 @@ fn rewrite_match( return None; } - // `match `cond` {` + // 6 = `match `, 2 = ` {` let cond_shape = match context.config.control_style() { Style::Legacy => try_opt!(shape.shrink_left(6).and_then(|s| s.sub_width(2))), - Style::Rfc => try_opt!(shape.offset_left(8)), + Style::Rfc => try_opt!(shape.offset_left(6).and_then(|s| s.sub_width(2))), }; let cond_str = try_opt!(cond.rewrite(context, cond_shape)); let alt_block_sep = String::from("\n") + &shape.indent.block_only().to_string(context.config); let block_sep = match context.config.control_brace_style() { - ControlBraceStyle::AlwaysNextLine => alt_block_sep.as_str(), + ControlBraceStyle::AlwaysNextLine => &alt_block_sep, + _ if last_line_extendable(&cond_str) => " ", + _ if cond_str.contains('\n') => &alt_block_sep, _ => " ", };