Skip to content

Commit ad878e0

Browse files
fix: async expression indentation
1 parent afb1ee1 commit ad878e0

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/utils.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,27 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
466466
ast::ExprKind::Lit(_) => {
467467
repr.contains('\n') && trimmed_last_line_width(repr) <= context.config.tab_spaces()
468468
}
469-
_ => false,
469+
ast::ExprKind::Async(..) => true,
470+
ast::ExprKind::AddrOf(..)
471+
| ast::ExprKind::Assign(..)
472+
| ast::ExprKind::AssignOp(..)
473+
| ast::ExprKind::Await(..)
474+
| ast::ExprKind::Box(..)
475+
| ast::ExprKind::Break(..)
476+
| ast::ExprKind::Cast(..)
477+
| ast::ExprKind::Continue(..)
478+
| ast::ExprKind::Err
479+
| ast::ExprKind::Field(..)
480+
| ast::ExprKind::InlineAsm(..)
481+
| ast::ExprKind::Let(..)
482+
| ast::ExprKind::Path(..)
483+
| ast::ExprKind::Range(..)
484+
| ast::ExprKind::Repeat(..)
485+
| ast::ExprKind::Ret(..)
486+
| ast::ExprKind::TryBlock(..)
487+
| ast::ExprKind::Tup(..)
488+
| ast::ExprKind::Type(..)
489+
| ast::ExprKind::Yield(None) => false,
470490
}
471491
}
472492

tests/source/expr.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,21 @@ fn overflow_with_attr() {
545545
foobar(x, y, #[cfg(feature = "zero")]
546546
{});
547547
}
548+
549+
550+
// https://github.com/rust-lang/rustfmt/issues/3765
551+
fn foo() {
552+
async {
553+
// Do
554+
// some
555+
// work
556+
}
557+
.await;
558+
559+
async {
560+
// Do
561+
// some
562+
// work
563+
}
564+
.await;
565+
}

tests/target/expr.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,20 @@ fn overflow_with_attr() {
638638
{},
639639
);
640640
}
641+
642+
// https://github.com/rust-lang/rustfmt/issues/3765
643+
fn foo() {
644+
async {
645+
// Do
646+
// some
647+
// work
648+
}
649+
.await;
650+
651+
async {
652+
// Do
653+
// some
654+
// work
655+
}
656+
.await;
657+
}

0 commit comments

Comments
 (0)