fix: async expression indentation (#3789)
This commit is contained in:
parent
afb1ee1c14
commit
dfe87fe946
3 changed files with 56 additions and 1 deletions
22
src/utils.rs
22
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue