diff options
Diffstat (limited to 'crates/ra_hir_def/src/body/lower.rs')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 30 |
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 | }) |