Merge Async and Gen into CoroutineKind

This commit is contained in:
Eric Holk
2023-11-30 14:54:39 -08:00
parent 3887b1645a
commit 48d5f1f0f2
25 changed files with 442 additions and 238 deletions

View File

@@ -195,39 +195,37 @@ impl<'hir> LoweringContext<'_, 'hir> {
binder,
capture_clause,
constness,
asyncness,
coro_kind,
movability,
fn_decl,
body,
fn_decl_span,
fn_arg_span,
}) => {
if let Async::Yes { closure_id, .. } = asyncness {
self.lower_expr_async_closure(
binder,
*capture_clause,
e.id,
hir_id,
*closure_id,
fn_decl,
body,
*fn_decl_span,
*fn_arg_span,
)
} else {
self.lower_expr_closure(
binder,
*capture_clause,
e.id,
*constness,
*movability,
fn_decl,
body,
*fn_decl_span,
*fn_arg_span,
)
}
}
}) => match coro_kind {
CoroutineKind::Async { closure_id, .. }
| CoroutineKind::Gen { closure_id, .. } => self.lower_expr_async_closure(
binder,
*capture_clause,
e.id,
hir_id,
*closure_id,
fn_decl,
body,
*fn_decl_span,
*fn_arg_span,
),
CoroutineKind::None => self.lower_expr_closure(
binder,
*capture_clause,
e.id,
*constness,
*movability,
fn_decl,
body,
*fn_decl_span,
*fn_arg_span,
),
},
ExprKind::Block(blk, opt_label) => {
let opt_label = self.lower_label(*opt_label);
hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label)
@@ -935,7 +933,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
// Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = self.lower_fn_decl(decl, closure_id, fn_decl_span, FnDeclKind::Closure, None);
let fn_decl = self.lower_fn_decl(
decl,
closure_id,
fn_decl_span,
FnDeclKind::Closure,
CoroutineKind::None,
);
let c = self.arena.alloc(hir::Closure {
def_id: self.local_def_id(closure_id),
@@ -1050,8 +1054,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
// We need to lower the declaration outside the new scope, because we
// have to conserve the state of being inside a loop condition for the
// closure argument types.
let fn_decl =
self.lower_fn_decl(&outer_decl, closure_id, fn_decl_span, FnDeclKind::Closure, None);
let fn_decl = self.lower_fn_decl(
&outer_decl,
closure_id,
fn_decl_span,
FnDeclKind::Closure,
CoroutineKind::None,
);
let c = self.arena.alloc(hir::Closure {
def_id: self.local_def_id(closure_id),