From 251ef93ac3bbb138a2eedf6090f2f56f1a15d898 Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 10 Sep 2020 20:01:23 +0800 Subject: Implement async blocks --- crates/hir_def/src/body/lower.rs | 5 ++++- crates/hir_def/src/expr.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 30ac12a12..c5ebc2aa0 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -239,7 +239,10 @@ impl ExprCollector<'_> { None => self.missing_expr(), }, // FIXME: we need to record these effects somewhere... - ast::Effect::Async(_) => self.collect_block_opt(e.block_expr()), + ast::Effect::Async(_) => { + let body = self.collect_block_opt(e.block_expr()); + self.alloc_expr(Expr::Async { body }, syntax_ptr) + } }, ast::Expr::BlockExpr(e) => self.collect_block(e), ast::Expr::LoopExpr(e) => { diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index c94b3a36f..e862c2080 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -111,6 +111,9 @@ pub enum Expr { TryBlock { body: ExprId, }, + Async { + body: ExprId, + }, Cast { expr: ExprId, type_ref: TypeRef, @@ -250,7 +253,7 @@ impl Expr { f(*expr); } } - Expr::TryBlock { body } | Expr::Unsafe { body } => f(*body), + Expr::TryBlock { body } | Expr::Unsafe { body } | Expr::Async { body } => f(*body), Expr::Loop { body, .. } => f(*body), Expr::While { condition, body, .. } => { f(*condition); -- cgit v1.2.3