diff --git a/src/utils.rs b/src/utils.rs index f2a2a3c6675..bad9bc1d788 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -452,8 +452,10 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::While(..) | ast::ExprKind::If(..) | ast::ExprKind::Block(..) + | ast::ExprKind::Async(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop(..) + | ast::ExprKind::TryBlock(..) | ast::ExprKind::Match(..) => repr.contains('\n'), ast::ExprKind::Paren(ref expr) | ast::ExprKind::Binary(_, _, ref expr) @@ -466,7 +468,25 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr ast::ExprKind::Lit(_) => { repr.contains('\n') && trimmed_last_line_width(repr) <= context.config.tab_spaces() } - _ => false, + ast::ExprKind::AddrOf(..) + | ast::ExprKind::Assign(..) + | ast::ExprKind::AssignOp(..) + | ast::ExprKind::Await(..) + | ast::ExprKind::Box(..) + | ast::ExprKind::Break(..) + | ast::ExprKind::Cast(..) + | ast::ExprKind::Continue(..) + | ast::ExprKind::Err + | ast::ExprKind::Field(..) + | ast::ExprKind::InlineAsm(..) + | ast::ExprKind::Let(..) + | ast::ExprKind::Path(..) + | ast::ExprKind::Range(..) + | ast::ExprKind::Repeat(..) + | ast::ExprKind::Ret(..) + | ast::ExprKind::Tup(..) + | ast::ExprKind::Type(..) + | ast::ExprKind::Yield(None) => false, } } diff --git a/tests/source/expr.rs b/tests/source/expr.rs index be87aca83a0..05af07f231b 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -545,3 +545,21 @@ fn overflow_with_attr() { foobar(x, y, #[cfg(feature = "zero")] {}); } + + +// https://github.com/rust-lang/rustfmt/issues/3765 +fn foo() { + async { + // Do + // some + // work + } + .await; + + async { + // Do + // some + // work + } + .await; +} diff --git a/tests/target/expr.rs b/tests/target/expr.rs index e63044ea913..c50693049a2 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -638,3 +638,20 @@ fn overflow_with_attr() { {}, ); } + +// https://github.com/rust-lang/rustfmt/issues/3765 +fn foo() { + async { + // Do + // some + // work + } + .await; + + async { + // Do + // some + // work + } + .await; +}