aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 6bedc6b56..25e29b7cd 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
4use std::{any::type_name, sync::Arc};
5
4use either::Either; 6use either::Either;
5use hir_expand::{ 7use hir_expand::{
6 hygiene::Hygiene, 8 hygiene::Hygiene,
@@ -10,11 +12,12 @@ use hir_expand::{
10use ra_arena::Arena; 12use ra_arena::Arena;
11use ra_syntax::{ 13use 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};
20use rustc_hash::FxHashMap;
18use test_utils::mark; 21use test_utils::mark;
19 22
20use crate::{ 23use crate::{
@@ -35,9 +38,6 @@ use crate::{
35}; 38};
36 39
37use super::{ExprSource, PatSource}; 40use super::{ExprSource, PatSource};
38use ast::AstChildren;
39use rustc_hash::FxHashMap;
40use std::{any::type_name, sync::Arc};
41 41
42pub(crate) struct LowerCtx { 42pub(crate) struct LowerCtx {
43 hygiene: Hygiene, 43 hygiene: Hygiene,
@@ -786,29 +786,26 @@ impl ExprCollector<'_> {
786 ast::Pat::PlaceholderPat(_) => Pat::Wild, 786 ast::Pat::PlaceholderPat(_) => 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
790 p.record_field_pat_list().expect("every struct should have a field list"); 790 let args: Vec<_> = p
791 let mut fields: Vec<_> = record_field_pat_list 791 .record_pat_field_list()
792 .bind_pats() 792 .expect("every struct should have a field list")
793 .filter_map(|bind_pat| { 793 .fields()
794 let ast_pat = 794 .filter_map(|f| {
795 ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat"); 795 let ast_pat = f.pat()?;
796 let pat = self.collect_pat(ast_pat); 796 let pat = self.collect_pat(ast_pat);
797 let name = bind_pat.name()?.as_name(); 797 let name = f.field_name()?.as_name();
798 Some(RecordFieldPat { name, pat }) 798 Some(RecordFieldPat { name, pat })
799 }) 799 })
800 .collect(); 800 .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 801
809 let ellipsis = record_field_pat_list.dotdot_token().is_some(); 802 let ellipsis = p
803 .record_pat_field_list()
804 .expect("every struct should have a field list")
805 .dotdot_token()
806 .is_some();
810 807
811 Pat::Record { path, args: fields, ellipsis } 808 Pat::Record { path, args, ellipsis }
812 } 809 }
813 ast::Pat::SlicePat(p) => { 810 ast::Pat::SlicePat(p) => {
814 let SlicePatComponents { prefix, slice, suffix } = p.components(); 811 let SlicePatComponents { prefix, slice, suffix } = p.components();