Skip to content

Commit

Permalink
fix: async expression indentation (#3789)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright authored and topecongiro committed Sep 11, 2019
1 parent afb1ee1 commit dfe87fe
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/utils.rs
Expand Up @@ -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)
Expand All @@ -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,
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/source/expr.rs
Expand Up @@ -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;
}
17 changes: 17 additions & 0 deletions tests/target/expr.rs
Expand Up @@ -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;
}

0 comments on commit dfe87fe

Please sign in to comment.