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/src') 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 From 0aece75cdd40daa4d48484103cfcd36ba13ba076 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 19:25:33 +0200 Subject: Remove dead code --- crates/ra_hir_def/src/body.rs | 8 ++++---- crates/ra_hir_def/src/body/lower.rs | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 67d623714..eafaf48c1 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -9,6 +9,8 @@ use drop_bomb::DropBomb; use either::Either; use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId}; use ra_arena::{map::ArenaMap, Arena}; +use ra_cfg::CfgOptions; +use ra_db::CrateId; use ra_prof::profile; use ra_syntax::{ast, AstNode, AstPtr}; use rustc_hash::FxHashMap; @@ -24,8 +26,6 @@ use crate::{ src::HasSource, AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, }; -use ra_cfg::CfgOptions; -use ra_db::CrateId; /// A subser of Exander that only deals with cfg attributes. We only need it to /// avoid cyclic queries in crate def map during enum processing. @@ -187,7 +187,7 @@ pub struct Body { pub item_scope: ItemScope, } -pub type ExprPtr = Either, AstPtr>; +pub type ExprPtr = AstPtr; pub type ExprSource = InFile; pub type PatPtr = Either, AstPtr>; @@ -285,7 +285,7 @@ impl BodySourceMap { } pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option { - let src = node.map(|it| Either::Left(AstPtr::new(it))); + let src = node.map(|it| AstPtr::new(it)); self.expr_map.get(&src).cloned() } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 990761661..cc2532e88 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -101,7 +101,6 @@ impl ExprCollector<'_> { } fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { - let ptr = Either::Left(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); @@ -281,7 +280,7 @@ impl ExprCollector<'_> { ast::Expr::ParenExpr(e) => { let inner = self.collect_expr_opt(e.expr()); // make the paren expr point to the inner expression as well - let src = self.expander.to_source(Either::Left(syntax_ptr)); + let src = self.expander.to_source(syntax_ptr); self.source_map.expr_map.insert(src, inner); inner } -- cgit v1.2.3