diff options
Diffstat (limited to 'crates/ra_hir_def/src/body/lower.rs')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 5c57d8bde..827ced4ad 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -11,7 +11,7 @@ use ra_arena::Arena; | |||
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
12 | ast::{ | 12 | ast::{ |
13 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, | 13 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, |
14 | SlicePatComponents, TypeAscriptionOwner, | 14 | SlicePatComponents, |
15 | }, | 15 | }, |
16 | AstNode, AstPtr, | 16 | AstNode, AstPtr, |
17 | }; | 17 | }; |
@@ -379,10 +379,10 @@ impl ExprCollector<'_> { | |||
379 | let expr = e.expr().map(|e| self.collect_expr(e)); | 379 | let expr = e.expr().map(|e| self.collect_expr(e)); |
380 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) | 380 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) |
381 | } | 381 | } |
382 | ast::Expr::RecordLit(e) => { | 382 | ast::Expr::RecordExpr(e) => { |
383 | let path = e.path().and_then(|path| self.expander.parse_path(path)); | 383 | let path = e.path().and_then(|path| self.expander.parse_path(path)); |
384 | let mut field_ptrs = Vec::new(); | 384 | let mut field_ptrs = Vec::new(); |
385 | let record_lit = if let Some(nfl) = e.record_field_list() { | 385 | let record_lit = if let Some(nfl) = e.record_expr_field_list() { |
386 | let fields = nfl | 386 | let fields = nfl |
387 | .fields() | 387 | .fields() |
388 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) | 388 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) |
@@ -432,7 +432,7 @@ impl ExprCollector<'_> { | |||
432 | } | 432 | } |
433 | ast::Expr::CastExpr(e) => { | 433 | ast::Expr::CastExpr(e) => { |
434 | let expr = self.collect_expr_opt(e.expr()); | 434 | let expr = self.collect_expr_opt(e.expr()); |
435 | let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref()); | 435 | let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty()); |
436 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) | 436 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) |
437 | } | 437 | } |
438 | ast::Expr::RefExpr(e) => { | 438 | ast::Expr::RefExpr(e) => { |
@@ -466,16 +466,13 @@ impl ExprCollector<'_> { | |||
466 | if let Some(pl) = e.param_list() { | 466 | if let Some(pl) = e.param_list() { |
467 | for param in pl.params() { | 467 | for param in pl.params() { |
468 | let pat = self.collect_pat_opt(param.pat()); | 468 | let pat = self.collect_pat_opt(param.pat()); |
469 | let type_ref = | 469 | let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); |
470 | param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it)); | ||
471 | args.push(pat); | 470 | args.push(pat); |
472 | arg_types.push(type_ref); | 471 | arg_types.push(type_ref); |
473 | } | 472 | } |
474 | } | 473 | } |
475 | let ret_type = e | 474 | let ret_type = |
476 | .ret_type() | 475 | e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&self.ctx(), it)); |
477 | .and_then(|r| r.type_ref()) | ||
478 | .map(|it| TypeRef::from_ast(&self.ctx(), it)); | ||
479 | let body = self.collect_expr_opt(e.body()); | 476 | let body = self.collect_expr_opt(e.body()); |
480 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) | 477 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) |
481 | } | 478 | } |
@@ -607,8 +604,7 @@ impl ExprCollector<'_> { | |||
607 | .map(|s| match s { | 604 | .map(|s| match s { |
608 | ast::Stmt::LetStmt(stmt) => { | 605 | ast::Stmt::LetStmt(stmt) => { |
609 | let pat = self.collect_pat_opt(stmt.pat()); | 606 | let pat = self.collect_pat_opt(stmt.pat()); |
610 | let type_ref = | 607 | let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); |
611 | stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it)); | ||
612 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 608 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
613 | Statement::Let { pat, type_ref, initializer } | 609 | Statement::Let { pat, type_ref, initializer } |
614 | } | 610 | } |
@@ -627,49 +623,49 @@ impl ExprCollector<'_> { | |||
627 | .items() | 623 | .items() |
628 | .filter_map(|item| { | 624 | .filter_map(|item| { |
629 | let (def, name): (ModuleDefId, Option<ast::Name>) = match item { | 625 | let (def, name): (ModuleDefId, Option<ast::Name>) = match item { |
630 | ast::Item::FnDef(def) => { | 626 | ast::Item::Fn(def) => { |
631 | let id = self.find_inner_item(&def)?; | 627 | let id = self.find_inner_item(&def)?; |
632 | ( | 628 | ( |
633 | FunctionLoc { container: container.into(), id }.intern(self.db).into(), | 629 | FunctionLoc { container: container.into(), id }.intern(self.db).into(), |
634 | def.name(), | 630 | def.name(), |
635 | ) | 631 | ) |
636 | } | 632 | } |
637 | ast::Item::TypeAliasDef(def) => { | 633 | ast::Item::TypeAlias(def) => { |
638 | let id = self.find_inner_item(&def)?; | 634 | let id = self.find_inner_item(&def)?; |
639 | ( | 635 | ( |
640 | TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), | 636 | TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), |
641 | def.name(), | 637 | def.name(), |
642 | ) | 638 | ) |
643 | } | 639 | } |
644 | ast::Item::ConstDef(def) => { | 640 | ast::Item::Const(def) => { |
645 | let id = self.find_inner_item(&def)?; | 641 | let id = self.find_inner_item(&def)?; |
646 | ( | 642 | ( |
647 | ConstLoc { container: container.into(), id }.intern(self.db).into(), | 643 | ConstLoc { container: container.into(), id }.intern(self.db).into(), |
648 | def.name(), | 644 | def.name(), |
649 | ) | 645 | ) |
650 | } | 646 | } |
651 | ast::Item::StaticDef(def) => { | 647 | ast::Item::Static(def) => { |
652 | let id = self.find_inner_item(&def)?; | 648 | let id = self.find_inner_item(&def)?; |
653 | (StaticLoc { container, id }.intern(self.db).into(), def.name()) | 649 | (StaticLoc { container, id }.intern(self.db).into(), def.name()) |
654 | } | 650 | } |
655 | ast::Item::StructDef(def) => { | 651 | ast::Item::Struct(def) => { |
656 | let id = self.find_inner_item(&def)?; | 652 | let id = self.find_inner_item(&def)?; |
657 | (StructLoc { container, id }.intern(self.db).into(), def.name()) | 653 | (StructLoc { container, id }.intern(self.db).into(), def.name()) |
658 | } | 654 | } |
659 | ast::Item::EnumDef(def) => { | 655 | ast::Item::Enum(def) => { |
660 | let id = self.find_inner_item(&def)?; | 656 | let id = self.find_inner_item(&def)?; |
661 | (EnumLoc { container, id }.intern(self.db).into(), def.name()) | 657 | (EnumLoc { container, id }.intern(self.db).into(), def.name()) |
662 | } | 658 | } |
663 | ast::Item::UnionDef(def) => { | 659 | ast::Item::Union(def) => { |
664 | let id = self.find_inner_item(&def)?; | 660 | let id = self.find_inner_item(&def)?; |
665 | (UnionLoc { container, id }.intern(self.db).into(), def.name()) | 661 | (UnionLoc { container, id }.intern(self.db).into(), def.name()) |
666 | } | 662 | } |
667 | ast::Item::TraitDef(def) => { | 663 | ast::Item::Trait(def) => { |
668 | let id = self.find_inner_item(&def)?; | 664 | let id = self.find_inner_item(&def)?; |
669 | (TraitLoc { container, id }.intern(self.db).into(), def.name()) | 665 | (TraitLoc { container, id }.intern(self.db).into(), def.name()) |
670 | } | 666 | } |
671 | ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks | 667 | ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks |
672 | ast::Item::ImplDef(_) | 668 | ast::Item::Impl(_) |
673 | | ast::Item::Use(_) | 669 | | ast::Item::Use(_) |
674 | | ast::Item::ExternCrate(_) | 670 | | ast::Item::ExternCrate(_) |
675 | | ast::Item::Module(_) | 671 | | ast::Item::Module(_) |