From 8feeddf1f88cb3753b51c894cffea4f11b0036d3 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Mon, 8 Oct 2018 20:49:33 -0300 Subject: Only combine `match` if its condition expression fits in a single line This improves the formatting and reading of code avoiding the condition expression to be rewrite, if it goes multi line. Fixes: #3029. Signed-off-by: Otavio Salvador --- src/overflow.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/overflow.rs b/src/overflow.rs index a7fc9728666..40cfc4be30f 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -18,6 +18,7 @@ use syntax::{ast, ptr}; use closures; use expr::{ can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr, + rewrite_cond, }; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator}; use macros::MacroArg; @@ -403,6 +404,16 @@ impl<'a> Context<'a> { closures::rewrite_last_closure(self.context, expr, shape) } } + ast::ExprKind::Match(..) => { + let multi_line = rewrite_cond(self.context, expr, shape) + .map_or(false, |cond| cond.contains('\n')); + + if multi_line { + None + } else { + expr.rewrite(self.context, shape) + } + } _ => expr.rewrite(self.context, shape), } } -- cgit 1.4.1-3-g733a5