diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 6bedc6b56..3f210547e 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -1,6 +1,8 @@ | |||
1 | //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` | 1 | //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` |
2 | //! representation. | 2 | //! representation. |
3 | 3 | ||
4 | use std::{any::type_name, sync::Arc}; | ||
5 | |||
4 | use either::Either; | 6 | use either::Either; |
5 | use hir_expand::{ | 7 | use hir_expand::{ |
6 | hygiene::Hygiene, | 8 | hygiene::Hygiene, |
@@ -10,11 +12,12 @@ use hir_expand::{ | |||
10 | use ra_arena::Arena; | 12 | use ra_arena::Arena; |
11 | use ra_syntax::{ | 13 | use ra_syntax::{ |
12 | ast::{ | 14 | ast::{ |
13 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, | 15 | self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner, |
14 | SlicePatComponents, | 16 | SlicePatComponents, |
15 | }, | 17 | }, |
16 | AstNode, AstPtr, | 18 | AstNode, AstPtr, |
17 | }; | 19 | }; |
20 | use rustc_hash::FxHashMap; | ||
18 | use test_utils::mark; | 21 | use test_utils::mark; |
19 | 22 | ||
20 | use crate::{ | 23 | use crate::{ |
@@ -35,9 +38,6 @@ use crate::{ | |||
35 | }; | 38 | }; |
36 | 39 | ||
37 | use super::{ExprSource, PatSource}; | 40 | use super::{ExprSource, PatSource}; |
38 | use ast::AstChildren; | ||
39 | use rustc_hash::FxHashMap; | ||
40 | use std::{any::type_name, sync::Arc}; | ||
41 | 41 | ||
42 | pub(crate) struct LowerCtx { | 42 | pub(crate) struct LowerCtx { |
43 | hygiene: Hygiene, | 43 | hygiene: Hygiene, |
@@ -723,7 +723,7 @@ impl ExprCollector<'_> { | |||
723 | 723 | ||
724 | fn collect_pat(&mut self, pat: ast::Pat) -> PatId { | 724 | fn collect_pat(&mut self, pat: ast::Pat) -> PatId { |
725 | let pattern = match &pat { | 725 | let pattern = match &pat { |
726 | ast::Pat::BindPat(bp) => { | 726 | ast::Pat::IdentPat(bp) => { |
727 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); | 727 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); |
728 | let annotation = | 728 | let annotation = |
729 | BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); | 729 | BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); |
@@ -783,32 +783,28 @@ impl ExprCollector<'_> { | |||
783 | let (args, ellipsis) = self.collect_tuple_pat(p.args()); | 783 | let (args, ellipsis) = self.collect_tuple_pat(p.args()); |
784 | Pat::Tuple { args, ellipsis } | 784 | Pat::Tuple { args, ellipsis } |
785 | } | 785 | } |
786 | ast::Pat::PlaceholderPat(_) => Pat::Wild, | 786 | ast::Pat::WildcardPat(_) => Pat::Wild, |
787 | ast::Pat::RecordPat(p) => { | 787 | ast::Pat::RecordPat(p) => { |
788 | let path = p.path().and_then(|path| self.expander.parse_path(path)); | 788 | let path = p.path().and_then(|path| self.expander.parse_path(path)); |
789 | let record_field_pat_list = | 789 | let args: Vec<_> = p |
790 | p.record_field_pat_list().expect("every struct should have a field list"); | 790 | .record_pat_field_list() |
791 | let mut fields: Vec<_> = record_field_pat_list | 791 | .expect("every struct should have a field list") |
792 | .bind_pats() | 792 | .fields() |
793 | .filter_map(|bind_pat| { | 793 | .filter_map(|f| { |
794 | let ast_pat = | 794 | let ast_pat = f.pat()?; |
795 | ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat"); | ||
796 | let pat = self.collect_pat(ast_pat); | 795 | let pat = self.collect_pat(ast_pat); |
797 | let name = bind_pat.name()?.as_name(); | 796 | let name = f.field_name()?.as_name(); |
798 | Some(RecordFieldPat { name, pat }) | 797 | Some(RecordFieldPat { name, pat }) |
799 | }) | 798 | }) |
800 | .collect(); | 799 | .collect(); |
801 | let iter = record_field_pat_list.record_field_pats().filter_map(|f| { | ||
802 | let ast_pat = f.pat()?; | ||
803 | let pat = self.collect_pat(ast_pat); | ||
804 | let name = f.field_name()?.as_name(); | ||
805 | Some(RecordFieldPat { name, pat }) | ||
806 | }); | ||
807 | fields.extend(iter); | ||
808 | 800 | ||
809 | let ellipsis = record_field_pat_list.dotdot_token().is_some(); | 801 | let ellipsis = p |
802 | .record_pat_field_list() | ||
803 | .expect("every struct should have a field list") | ||
804 | .dotdot_token() | ||
805 | .is_some(); | ||
810 | 806 | ||
811 | Pat::Record { path, args: fields, ellipsis } | 807 | Pat::Record { path, args, ellipsis } |
812 | } | 808 | } |
813 | ast::Pat::SlicePat(p) => { | 809 | ast::Pat::SlicePat(p) => { |
814 | let SlicePatComponents { prefix, slice, suffix } = p.components(); | 810 | let SlicePatComponents { prefix, slice, suffix } = p.components(); |