From 7a39bc3ba29351feabcd4a16e12568a9e12818ca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 16:42:24 +0200 Subject: Make records grammar more orthogonal We used name [: expr] grammar before, now it is [name :] expr which makes things simpler --- crates/ra_hir_def/src/body.rs | 5 ----- crates/ra_hir_def/src/body/lower.rs | 27 +++++---------------------- crates/ra_hir_def/src/path.rs | 5 ----- 3 files changed, 5 insertions(+), 32 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 7fac6ce66..67d623714 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -294,11 +294,6 @@ impl BodySourceMap { self.expansions.get(&src).cloned() } - pub fn field_init_shorthand_expr(&self, node: InFile<&ast::RecordField>) -> Option { - let src = node.map(|it| Either::Right(AstPtr::new(it))); - self.expr_map.get(&src).cloned() - } - pub fn pat_syntax(&self, pat: PatId) -> Result { self.pat_map_back[pat].clone() } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c1d7eb826..990761661 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -27,7 +27,6 @@ use crate::{ }, item_scope::BuiltinShadowMode, path::GenericArgs, - path::Path, type_ref::{Mutability, TypeRef}, AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, @@ -113,13 +112,6 @@ impl ExprCollector<'_> { fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { self.make_expr(expr, Err(SyntheticSyntax)) } - fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { - let ptr = Either::Right(ptr); - let src = self.expander.to_source(ptr); - let id = self.make_expr(expr, Ok(src.clone())); - self.source_map.expr_map.insert(src, id); - id - } fn empty_block(&mut self) -> ExprId { self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) } @@ -309,22 +301,13 @@ impl ExprCollector<'_> { if !self.expander.is_cfg_enabled(&attrs) { return None; } + let name = field.field_name()?.as_name(); Some(RecordLitField { - name: field - .name_ref() - .map(|nr| nr.as_name()) - .unwrap_or_else(Name::missing), - expr: if let Some(e) = field.expr() { - self.collect_expr(e) - } else if let Some(nr) = field.name_ref() { - // field shorthand - self.alloc_expr_field_shorthand( - Expr::Path(Path::from_name_ref(&nr)), - AstPtr::new(&field), - ) - } else { - self.missing_expr() + name, + expr: match field.expr() { + Some(e) => self.collect_expr(e), + None => self.missing_expr(), }, }) }) diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 904080341..91c7b3e09 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs @@ -134,11 +134,6 @@ impl Path { lower::lower_path(path, hygiene) } - /// Converts an `ast::NameRef` into a single-identifier `Path`. - pub(crate) fn from_name_ref(name_ref: &ast::NameRef) -> Path { - Path { type_anchor: None, mod_path: name_ref.as_name().into(), generic_args: vec![None] } - } - /// Converts a known mod path to `Path`. pub(crate) fn from_known_path( path: ModPath, -- cgit v1.2.3