From 0a780c0ab3869d92fb56ae3b2ddc7636fb169314 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 23 Dec 2020 12:15:38 +0100 Subject: Implement const pat inference --- crates/hir_def/src/body/lower.rs | 12 +++++++++--- crates/hir_def/src/expr.rs | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 978c3a324..4492a7d77 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -932,10 +932,16 @@ impl ExprCollector<'_> { let inner = self.collect_pat_opt(boxpat.pat()); Pat::Box { inner } } - // FIXME: implement - ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) | ast::Pat::ConstBlockPat(_) => { - Pat::Missing + ast::Pat::ConstBlockPat(const_block_pat) => { + if let Some(expr) = const_block_pat.block_expr() { + let expr_id = self.collect_block(expr); + Pat::ConstBlock(expr_id) + } else { + Pat::Missing + } } + // FIXME: implement + ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) => Pat::Missing, }; let ptr = AstPtr::new(&pat); self.alloc_pat(pattern, Either::Left(ptr)) diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index e5d740a36..b1e57c693 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -399,12 +399,18 @@ pub enum Pat { TupleStruct { path: Option, args: Vec, ellipsis: Option }, Ref { pat: PatId, mutability: Mutability }, Box { inner: PatId }, + ConstBlock(ExprId), } impl Pat { pub fn walk_child_pats(&self, mut f: impl FnMut(PatId)) { match self { - Pat::Range { .. } | Pat::Lit(..) | Pat::Path(..) | Pat::Wild | Pat::Missing => {} + Pat::Range { .. } + | Pat::Lit(..) + | Pat::Path(..) + | Pat::ConstBlock(..) + | Pat::Wild + | Pat::Missing => {} Pat::Bind { subpat, .. } => { subpat.iter().copied().for_each(f); } -- cgit v1.2.3 From a142beaf013a016a48eb9f193b55e0cbcb80b6a9 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 23 Dec 2020 12:24:24 +0100 Subject: Implement const block inference --- crates/hir_def/src/body/lower.rs | 4 ++++ crates/hir_def/src/expr.rs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 4492a7d77..1b98504bb 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -246,6 +246,10 @@ impl ExprCollector<'_> { let body = self.collect_block_opt(e.block_expr()); self.alloc_expr(Expr::Async { body }, syntax_ptr) } + ast::Effect::Const(_) => { + let body = self.collect_block_opt(e.block_expr()); + self.alloc_expr(Expr::Const { 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 b1e57c693..3bba30397 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -114,6 +114,9 @@ pub enum Expr { Async { body: ExprId, }, + Const { + body: ExprId, + }, Cast { expr: ExprId, type_ref: TypeRef, @@ -253,7 +256,10 @@ impl Expr { f(*expr); } } - Expr::TryBlock { body } | Expr::Unsafe { body } | Expr::Async { body } => f(*body), + Expr::TryBlock { body } + | Expr::Unsafe { body } + | Expr::Async { body } + | Expr::Const { body } => f(*body), Expr::Loop { body, .. } => f(*body), Expr::While { condition, body, .. } => { f(*condition); -- cgit v1.2.3