diff --git a/src/closures.rs b/src/closures.rs index a09146e9592..534e83ce26e 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -185,7 +185,7 @@ fn rewrite_closure_expr( context: &RewriteContext<'_>, shape: Shape, ) -> Option { - fn allow_multi_line(expr: &ast::Expr) -> bool { + fn allow_multi_line(expr: &ast::Expr, context: &RewriteContext<'_>) -> bool { match expr.kind { ast::ExprKind::Match(..) | ast::ExprKind::Async(..) @@ -197,7 +197,13 @@ fn rewrite_closure_expr( ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) - | ast::ExprKind::Cast(ref expr, _) => allow_multi_line(expr), + | ast::ExprKind::Cast(ref expr, _) => allow_multi_line(expr, context), + + ast::ExprKind::Binary(_, ref expr1, ref expr2) + if context.config.version() == Version::Two => + { + allow_multi_line(expr1, context) && allow_multi_line(expr2, context) + } _ => false, } @@ -205,7 +211,7 @@ fn rewrite_closure_expr( // When rewriting closure's body without block, we require it to fit in a single line // unless it is a block-like expression or we are inside macro call. - let veto_multiline = (!allow_multi_line(expr) && !context.inside_macro()) + let veto_multiline = (!allow_multi_line(expr, context) && !context.inside_macro()) || context.config.force_multiline_blocks(); expr.rewrite(context, shape) .and_then(|rw| { diff --git a/tests/source/issue-5624.rs b/tests/source/issue-5624.rs new file mode 100644 index 00000000000..625d541daad --- /dev/null +++ b/tests/source/issue-5624.rs @@ -0,0 +1,15 @@ +// rustfmt-version: Two + +fn func usize>(f: F) -> usize { + f(0) +} + +fn main() { + let _result = func(|x| + match x { + _ => 0, + } + match 1 { + _ => 1, + } + ); +} diff --git a/tests/target/issue-5624.rs b/tests/target/issue-5624.rs new file mode 100644 index 00000000000..571b011c0fd --- /dev/null +++ b/tests/target/issue-5624.rs @@ -0,0 +1,13 @@ +// rustfmt-version: Two + +fn func usize>(f: F) -> usize { + f(0) +} + +fn main() { + let _result = func(|x| match x { + _ => 0, + } + match 1 { + _ => 1, + }); +}