aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-11 18:37:02 +0100
committerGitHub <[email protected]>2020-04-11 18:37:02 +0100
commit1a1c09ed3e3a34c0a8750f98ece9ad85595395d2 (patch)
tree44136a4ce738d388bb9b0ce9f5569cf68465cbe2 /crates/ra_hir_def/src/body
parent11d400b63b07d3cffbe8d1363b802a2d52f5d786 (diff)
parent0aece75cdd40daa4d48484103cfcd36ba13ba076 (diff)
Merge #3951
3951: Simplify records grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs30
1 files changed, 6 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index c1d7eb826..cc2532e88 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,
@@ -102,7 +101,6 @@ impl ExprCollector<'_> {
102 } 101 }
103 102
104 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { 103 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
105 let ptr = Either::Left(ptr);
106 let src = self.expander.to_source(ptr); 104 let src = self.expander.to_source(ptr);
107 let id = self.make_expr(expr, Ok(src.clone())); 105 let id = self.make_expr(expr, Ok(src.clone()));
108 self.source_map.expr_map.insert(src, id); 106 self.source_map.expr_map.insert(src, id);
@@ -113,13 +111,6 @@ impl ExprCollector<'_> {
113 fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { 111 fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId {
114 self.make_expr(expr, Err(SyntheticSyntax)) 112 self.make_expr(expr, Err(SyntheticSyntax))
115 } 113 }
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 { 114 fn empty_block(&mut self) -> ExprId {
124 self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) 115 self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None })
125 } 116 }
@@ -289,7 +280,7 @@ impl ExprCollector<'_> {
289 ast::Expr::ParenExpr(e) => { 280 ast::Expr::ParenExpr(e) => {
290 let inner = self.collect_expr_opt(e.expr()); 281 let inner = self.collect_expr_opt(e.expr());
291 // make the paren expr point to the inner expression as well 282 // make the paren expr point to the inner expression as well
292 let src = self.expander.to_source(Either::Left(syntax_ptr)); 283 let src = self.expander.to_source(syntax_ptr);
293 self.source_map.expr_map.insert(src, inner); 284 self.source_map.expr_map.insert(src, inner);
294 inner 285 inner
295 } 286 }
@@ -309,22 +300,13 @@ impl ExprCollector<'_> {
309 if !self.expander.is_cfg_enabled(&attrs) { 300 if !self.expander.is_cfg_enabled(&attrs) {
310 return None; 301 return None;
311 } 302 }
303 let name = field.field_name()?.as_name();
312 304
313 Some(RecordLitField { 305 Some(RecordLitField {
314 name: field 306 name,
315 .name_ref() 307 expr: match field.expr() {
316 .map(|nr| nr.as_name()) 308 Some(e) => self.collect_expr(e),
317 .unwrap_or_else(Name::missing), 309 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 }, 310 },
329 }) 311 })
330 }) 312 })