aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/expr/lower.rs')
-rw-r--r--crates/ra_hir/src/expr/lower.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs
index 61535d24f..50ea429ea 100644
--- a/crates/ra_hir/src/expr/lower.rs
+++ b/crates/ra_hir/src/expr/lower.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use ra_arena::Arena; 3use ra_arena::Arena;
2use ra_syntax::{ 4use ra_syntax::{
3 ast::{ 5 ast::{
@@ -272,8 +274,11 @@ where
272 self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) 274 self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr)
273 } 275 }
274 ast::Expr::PathExpr(e) => { 276 ast::Expr::PathExpr(e) => {
275 let path = 277 let path = e
276 e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing); 278 .path()
279 .and_then(|path| self.parse_path(path))
280 .map(Expr::Path)
281 .unwrap_or(Expr::Missing);
277 self.alloc_expr(path, syntax_ptr) 282 self.alloc_expr(path, syntax_ptr)
278 } 283 }
279 ast::Expr::ContinueExpr(_e) => { 284 ast::Expr::ContinueExpr(_e) => {
@@ -295,7 +300,7 @@ where
295 self.alloc_expr(Expr::Return { expr }, syntax_ptr) 300 self.alloc_expr(Expr::Return { expr }, syntax_ptr)
296 } 301 }
297 ast::Expr::RecordLit(e) => { 302 ast::Expr::RecordLit(e) => {
298 let path = e.path().and_then(Path::from_ast); 303 let path = e.path().and_then(|path| self.parse_path(path));
299 let mut field_ptrs = Vec::new(); 304 let mut field_ptrs = Vec::new();
300 let record_lit = if let Some(nfl) = e.record_field_list() { 305 let record_lit = if let Some(nfl) = e.record_field_list() {
301 let fields = nfl 306 let fields = nfl
@@ -459,7 +464,7 @@ where
459 .ast_id(&e) 464 .ast_id(&e)
460 .with_file_id(self.current_file_id); 465 .with_file_id(self.current_file_id);
461 466
462 if let Some(path) = e.path().and_then(Path::from_ast) { 467 if let Some(path) = e.path().and_then(|path| self.parse_path(path)) {
463 if let Some(def) = self.resolver.resolve_path_as_macro(self.db, &path) { 468 if let Some(def) = self.resolver.resolve_path_as_macro(self.db, &path) {
464 let call_id = MacroCallLoc { def: def.id, ast_id }.id(self.db); 469 let call_id = MacroCallLoc { def: def.id, ast_id }.id(self.db);
465 let file_id = call_id.as_file(MacroFileKind::Expr); 470 let file_id = call_id.as_file(MacroFileKind::Expr);
@@ -529,7 +534,7 @@ where
529 Pat::Bind { name, mode: annotation, subpat } 534 Pat::Bind { name, mode: annotation, subpat }
530 } 535 }
531 ast::Pat::TupleStructPat(p) => { 536 ast::Pat::TupleStructPat(p) => {
532 let path = p.path().and_then(Path::from_ast); 537 let path = p.path().and_then(|path| self.parse_path(path));
533 let args = p.args().map(|p| self.collect_pat(p)).collect(); 538 let args = p.args().map(|p| self.collect_pat(p)).collect();
534 Pat::TupleStruct { path, args } 539 Pat::TupleStruct { path, args }
535 } 540 }
@@ -539,7 +544,7 @@ where
539 Pat::Ref { pat, mutability } 544 Pat::Ref { pat, mutability }
540 } 545 }
541 ast::Pat::PathPat(p) => { 546 ast::Pat::PathPat(p) => {
542 let path = p.path().and_then(Path::from_ast); 547 let path = p.path().and_then(|path| self.parse_path(path));
543 path.map(Pat::Path).unwrap_or(Pat::Missing) 548 path.map(Pat::Path).unwrap_or(Pat::Missing)
544 } 549 }
545 ast::Pat::TuplePat(p) => { 550 ast::Pat::TuplePat(p) => {
@@ -548,7 +553,7 @@ where
548 } 553 }
549 ast::Pat::PlaceholderPat(_) => Pat::Wild, 554 ast::Pat::PlaceholderPat(_) => Pat::Wild,
550 ast::Pat::RecordPat(p) => { 555 ast::Pat::RecordPat(p) => {
551 let path = p.path().and_then(Path::from_ast); 556 let path = p.path().and_then(|path| self.parse_path(path));
552 let record_field_pat_list = 557 let record_field_pat_list =
553 p.record_field_pat_list().expect("every struct should have a field list"); 558 p.record_field_pat_list().expect("every struct should have a field list");
554 let mut fields: Vec<_> = record_field_pat_list 559 let mut fields: Vec<_> = record_field_pat_list
@@ -589,6 +594,10 @@ where
589 self.missing_pat() 594 self.missing_pat()
590 } 595 }
591 } 596 }
597
598 fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
599 Path::from_src(Source { ast: path, file_id: self.current_file_id }, self.db)
600 }
592} 601}
593 602
594impl From<ast::BinOp> for BinaryOp { 603impl From<ast::BinOp> for BinaryOp {