Skip to content

Commit dfe87fe

Browse files
calebcartwrighttopecongiro
authored andcommitted
fix: async expression indentation (#3789)
1 parent afb1ee1 commit dfe87fe

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
@@ -452,8 +452,10 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
452452
| ast::ExprKind::While(..)
453453
| ast::ExprKind::If(..)
454454
| ast::ExprKind::Block(..)
455+
| ast::ExprKind::Async(..)
455456
| ast::ExprKind::Loop(..)
456457
| ast::ExprKind::ForLoop(..)
458+
| ast::ExprKind::TryBlock(..)
457459
| ast::ExprKind::Match(..) => repr.contains('\n'),
458460
ast::ExprKind::Paren(ref expr)
459461
| ast::ExprKind::Binary(_, _, ref expr)
@@ -466,7 +468,25 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
466468
ast::ExprKind::Lit(_) => {
467469
repr.contains('\n') && trimmed_last_line_width(repr) <= context.config.tab_spaces()
468470
}
469-
_ => false,
471+
ast::ExprKind::AddrOf(..)
472+
| ast::ExprKind::Assign(..)
473+
| ast::ExprKind::AssignOp(..)
474+
| ast::ExprKind::Await(..)
475+
| ast::ExprKind::Box(..)
476+
| ast::ExprKind::Break(..)
477+
| ast::ExprKind::Cast(..)
478+
| ast::ExprKind::Continue(..)
479+
| ast::ExprKind::Err
480+
| ast::ExprKind::Field(..)
481+
| ast::ExprKind::InlineAsm(..)
482+
| ast::ExprKind::Let(..)
483+
| ast::ExprKind::Path(..)
484+
| ast::ExprKind::Range(..)
485+
| ast::ExprKind::Repeat(..)
486+
| ast::ExprKind::Ret(..)
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)