From 14cb96ec0e6be3b99bfe4ea373c058dcbd2a4f79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 19:54:16 +0200 Subject: Allign RecordPat with RecordExpr --- crates/ra_hir_def/src/body/lower.rs | 39 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'crates/ra_hir_def/src/body') 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 @@ //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` //! representation. +use std::{any::type_name, sync::Arc}; + use either::Either; use hir_expand::{ hygiene::Hygiene, @@ -10,11 +12,12 @@ use hir_expand::{ use ra_arena::Arena; use ra_syntax::{ ast::{ - self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, + self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner, SlicePatComponents, }, AstNode, AstPtr, }; +use rustc_hash::FxHashMap; use test_utils::mark; use crate::{ @@ -35,9 +38,6 @@ use crate::{ }; use super::{ExprSource, PatSource}; -use ast::AstChildren; -use rustc_hash::FxHashMap; -use std::{any::type_name, sync::Arc}; pub(crate) struct LowerCtx { hygiene: Hygiene, @@ -786,29 +786,26 @@ impl ExprCollector<'_> { ast::Pat::PlaceholderPat(_) => Pat::Wild, ast::Pat::RecordPat(p) => { let path = p.path().and_then(|path| self.expander.parse_path(path)); - let record_field_pat_list = - p.record_field_pat_list().expect("every struct should have a field list"); - let mut fields: Vec<_> = record_field_pat_list - .bind_pats() - .filter_map(|bind_pat| { - let ast_pat = - ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat"); + + let args: Vec<_> = p + .record_pat_field_list() + .expect("every struct should have a field list") + .fields() + .filter_map(|f| { + let ast_pat = f.pat()?; let pat = self.collect_pat(ast_pat); - let name = bind_pat.name()?.as_name(); + let name = f.field_name()?.as_name(); Some(RecordFieldPat { name, pat }) }) .collect(); - let iter = record_field_pat_list.record_field_pats().filter_map(|f| { - let ast_pat = f.pat()?; - let pat = self.collect_pat(ast_pat); - let name = f.field_name()?.as_name(); - Some(RecordFieldPat { name, pat }) - }); - fields.extend(iter); - let ellipsis = record_field_pat_list.dotdot_token().is_some(); + let ellipsis = p + .record_pat_field_list() + .expect("every struct should have a field list") + .dotdot_token() + .is_some(); - Pat::Record { path, args: fields, ellipsis } + Pat::Record { path, args, ellipsis } } ast::Pat::SlicePat(p) => { let SlicePatComponents { prefix, slice, suffix } = p.components(); -- cgit v1.2.3 From d7f75db90d99216c13000681ff2c4a887451c4b2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:04:40 +0200 Subject: Reorder --- crates/ra_hir_def/src/body/lower.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_hir_def/src/body') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 25e29b7cd..ef1c0df01 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -786,7 +786,6 @@ impl ExprCollector<'_> { ast::Pat::PlaceholderPat(_) => Pat::Wild, ast::Pat::RecordPat(p) => { let path = p.path().and_then(|path| self.expander.parse_path(path)); - let args: Vec<_> = p .record_pat_field_list() .expect("every struct should have a field list") -- cgit v1.2.3 From 6791eb9685375da94556bb910ea71f78b08be5ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:07:21 +0200 Subject: Rename PalceholderPat -> WildcardPat --- crates/ra_hir_def/src/body/lower.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/body') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index ef1c0df01..7b988ae33 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -783,7 +783,7 @@ impl ExprCollector<'_> { let (args, ellipsis) = self.collect_tuple_pat(p.args()); Pat::Tuple { args, ellipsis } } - ast::Pat::PlaceholderPat(_) => Pat::Wild, + ast::Pat::WildcardPat(_) => Pat::Wild, ast::Pat::RecordPat(p) => { let path = p.path().and_then(|path| self.expander.parse_path(path)); let args: Vec<_> = p -- cgit v1.2.3 From 98181087984157e27faba0b969e384f3c62c39d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:09:09 +0200 Subject: Rename BindPat -> IdentPat --- crates/ra_hir_def/src/body/lower.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/body') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 7b988ae33..3f210547e 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -723,7 +723,7 @@ impl ExprCollector<'_> { fn collect_pat(&mut self, pat: ast::Pat) -> PatId { let pattern = match &pat { - ast::Pat::BindPat(bp) => { + ast::Pat::IdentPat(bp) => { let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); let annotation = BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); -- cgit v1.2.3