aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-11 15:42:24 +0100
committerAleksey Kladov <[email protected]>2020-04-11 18:20:41 +0100
commit7a39bc3ba29351feabcd4a16e12568a9e12818ca (patch)
treea5f102f40002dd66b4fc06aa2c3474f3be184a17 /crates/ra_hir_def/src/body
parente7a68c8f55e0770fdeae508a1710509c13aaffa1 (diff)
Make records grammar more orthogonal
We used name [: expr] grammar before, now it is [name :] expr which makes things simpler
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs27
1 files changed, 5 insertions, 22 deletions
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::{
27 }, 27 },
28 item_scope::BuiltinShadowMode, 28 item_scope::BuiltinShadowMode,
29 path::GenericArgs, 29 path::GenericArgs,
30 path::Path,
31 type_ref::{Mutability, TypeRef}, 30 type_ref::{Mutability, TypeRef},
32 AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, 31 AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId,
33 StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, 32 StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
@@ -113,13 +112,6 @@ impl ExprCollector<'_> {
113 fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { 112 fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId {
114 self.make_expr(expr, Err(SyntheticSyntax)) 113 self.make_expr(expr, Err(SyntheticSyntax))
115 } 114 }
116 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
117 let ptr = Either::Right(ptr);
118 let src = self.expander.to_source(ptr);
119 let id = self.make_expr(expr, Ok(src.clone()));
120 self.source_map.expr_map.insert(src, id);
121 id
122 }
123 fn empty_block(&mut self) -> ExprId { 115 fn empty_block(&mut self) -> ExprId {
124 self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) 116 self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None })
125 } 117 }
@@ -309,22 +301,13 @@ impl ExprCollector<'_> {
309 if !self.expander.is_cfg_enabled(&attrs) { 301 if !self.expander.is_cfg_enabled(&attrs) {
310 return None; 302 return None;
311 } 303 }
304 let name = field.field_name()?.as_name();
312 305
313 Some(RecordLitField { 306 Some(RecordLitField {
314 name: field 307 name,
315 .name_ref() 308 expr: match field.expr() {
316 .map(|nr| nr.as_name()) 309 Some(e) => self.collect_expr(e),
317 .unwrap_or_else(Name::missing), 310 None => self.missing_expr(),
318 expr: if let Some(e) = field.expr() {
319 self.collect_expr(e)
320 } else if let Some(nr) = field.name_ref() {
321 // field shorthand
322 self.alloc_expr_field_shorthand(
323 Expr::Path(Path::from_name_ref(&nr)),
324 AstPtr::new(&field),
325 )
326 } else {
327 self.missing_expr()
328 }, 311 },
329 }) 312 })
330 }) 313 })