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