]> git.lizzy.rs Git - rust.git/blobdiff - src/overflow.rs
Only combine `match` if its condition expression fits in a single line
[rust.git] / src / overflow.rs
index a7fc9728666769162579e33d9d5aba5a6d785675..40cfc4be30f393f2dd95a5bd50946cb6da56cfe9 100644 (file)
@@ -18,6 +18,7 @@
 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 @@ fn rewrite_last_item_with_overflow(
                             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),
                 }
             }