From a3b104aa6df205e74c116d8c9e41900807924e70 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 11 Feb 2020 22:33:11 +0100 Subject: Implement slice pattern AST > HIR lowering --- crates/ra_hir_def/src/body/lower.rs | 16 ++++++++++++---- crates/ra_hir_def/src/expr.rs | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index e656f9a41..5c779521b 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -8,7 +8,7 @@ use ra_arena::Arena; use ra_syntax::{ ast::{ self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, - TypeAscriptionOwner, + SlicePatComponents, TypeAscriptionOwner, }, AstNode, AstPtr, }; @@ -591,7 +591,7 @@ where let args = p.args().map(|p| self.collect_pat(p)).collect(); Pat::Tuple(args) } - ast::Pat::PlaceholderPat(_) => Pat::Wild, + ast::Pat::PlaceholderPat(_) | ast::Pat::DotDotPat(_) => Pat::Wild, ast::Pat::RecordPat(p) => { let path = p.path().and_then(|path| self.expander.parse_path(path)); let record_field_pat_list = @@ -616,12 +616,20 @@ where Pat::Record { path, args: fields } } + ast::Pat::SlicePat(p) => { + let SlicePatComponents { prefix, slice, suffix } = p.components(); + + Pat::Slice { + prefix: prefix.into_iter().map(|p| self.collect_pat(p)).collect(), + slice: slice.map(|p| self.collect_pat(p)), + suffix: suffix.into_iter().map(|p| self.collect_pat(p)).collect(), + } + } // FIXME: implement - ast::Pat::DotDotPat(_) => Pat::Missing, ast::Pat::BoxPat(_) => Pat::Missing, ast::Pat::LiteralPat(_) => Pat::Missing, - ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing, + ast::Pat::RangePat(_) => Pat::Missing, }; let ptr = AstPtr::new(&pat); self.alloc_pat(pattern, Either::Left(ptr)) diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs index a75ef9970..035824403 100644 --- a/crates/ra_hir_def/src/expr.rs +++ b/crates/ra_hir_def/src/expr.rs @@ -393,7 +393,7 @@ pub enum Pat { }, Slice { prefix: Vec, - rest: Option, + slice: Option, suffix: Vec, }, Path(Path), @@ -424,8 +424,8 @@ impl Pat { args.iter().copied().for_each(f); } Pat::Ref { pat, .. } => f(*pat), - Pat::Slice { prefix, rest, suffix } => { - let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter()); + Pat::Slice { prefix, slice, suffix } => { + let total_iter = prefix.iter().chain(slice.iter()).chain(suffix.iter()); total_iter.copied().for_each(f); } Pat::Record { args, .. } => { -- cgit v1.2.3