diff options
author | Aleksey Kladov <[email protected]> | 2019-08-19 12:04:51 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-08-19 12:04:51 +0100 |
commit | b50a04827c13af00314eb9869d3cc125b2419971 (patch) | |
tree | bd4e171b740362e50d3bc64a1edb06abdd59a2fd /crates | |
parent | 39e444d70145cbf61ddfdd202572d9c6a7f2fd3c (diff) |
remove ast::*Kind from hir
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 90 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir/src/traits.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/type_ref.rs | 35 |
6 files changed, 86 insertions, 83 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index a16561d11..328d635d4 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -602,8 +602,8 @@ where | |||
602 | 602 | ||
603 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { | 603 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { |
604 | let syntax_ptr = SyntaxNodePtr::new(expr.syntax()); | 604 | let syntax_ptr = SyntaxNodePtr::new(expr.syntax()); |
605 | match expr.kind() { | 605 | match expr { |
606 | ast::ExprKind::IfExpr(e) => { | 606 | ast::Expr::IfExpr(e) => { |
607 | let then_branch = self.collect_block_opt(e.then_branch()); | 607 | let then_branch = self.collect_block_opt(e.then_branch()); |
608 | 608 | ||
609 | let else_branch = e.else_branch().map(|b| match b { | 609 | let else_branch = e.else_branch().map(|b| match b { |
@@ -639,16 +639,16 @@ where | |||
639 | 639 | ||
640 | self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) | 640 | self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) |
641 | } | 641 | } |
642 | ast::ExprKind::TryBlockExpr(e) => { | 642 | ast::Expr::TryBlockExpr(e) => { |
643 | let body = self.collect_block_opt(e.try_body()); | 643 | let body = self.collect_block_opt(e.try_body()); |
644 | self.alloc_expr(Expr::TryBlock { body }, syntax_ptr) | 644 | self.alloc_expr(Expr::TryBlock { body }, syntax_ptr) |
645 | } | 645 | } |
646 | ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()), | 646 | ast::Expr::BlockExpr(e) => self.collect_block_opt(e.block()), |
647 | ast::ExprKind::LoopExpr(e) => { | 647 | ast::Expr::LoopExpr(e) => { |
648 | let body = self.collect_block_opt(e.loop_body()); | 648 | let body = self.collect_block_opt(e.loop_body()); |
649 | self.alloc_expr(Expr::Loop { body }, syntax_ptr) | 649 | self.alloc_expr(Expr::Loop { body }, syntax_ptr) |
650 | } | 650 | } |
651 | ast::ExprKind::WhileExpr(e) => { | 651 | ast::Expr::WhileExpr(e) => { |
652 | let body = self.collect_block_opt(e.loop_body()); | 652 | let body = self.collect_block_opt(e.loop_body()); |
653 | 653 | ||
654 | let condition = match e.condition() { | 654 | let condition = match e.condition() { |
@@ -675,13 +675,13 @@ where | |||
675 | 675 | ||
676 | self.alloc_expr(Expr::While { condition, body }, syntax_ptr) | 676 | self.alloc_expr(Expr::While { condition, body }, syntax_ptr) |
677 | } | 677 | } |
678 | ast::ExprKind::ForExpr(e) => { | 678 | ast::Expr::ForExpr(e) => { |
679 | let iterable = self.collect_expr_opt(e.iterable()); | 679 | let iterable = self.collect_expr_opt(e.iterable()); |
680 | let pat = self.collect_pat_opt(e.pat()); | 680 | let pat = self.collect_pat_opt(e.pat()); |
681 | let body = self.collect_block_opt(e.loop_body()); | 681 | let body = self.collect_block_opt(e.loop_body()); |
682 | self.alloc_expr(Expr::For { iterable, pat, body }, syntax_ptr) | 682 | self.alloc_expr(Expr::For { iterable, pat, body }, syntax_ptr) |
683 | } | 683 | } |
684 | ast::ExprKind::CallExpr(e) => { | 684 | ast::Expr::CallExpr(e) => { |
685 | let callee = self.collect_expr_opt(e.expr()); | 685 | let callee = self.collect_expr_opt(e.expr()); |
686 | let args = if let Some(arg_list) = e.arg_list() { | 686 | let args = if let Some(arg_list) = e.arg_list() { |
687 | arg_list.args().map(|e| self.collect_expr(e)).collect() | 687 | arg_list.args().map(|e| self.collect_expr(e)).collect() |
@@ -690,7 +690,7 @@ where | |||
690 | }; | 690 | }; |
691 | self.alloc_expr(Expr::Call { callee, args }, syntax_ptr) | 691 | self.alloc_expr(Expr::Call { callee, args }, syntax_ptr) |
692 | } | 692 | } |
693 | ast::ExprKind::MethodCallExpr(e) => { | 693 | ast::Expr::MethodCallExpr(e) => { |
694 | let receiver = self.collect_expr_opt(e.expr()); | 694 | let receiver = self.collect_expr_opt(e.expr()); |
695 | let args = if let Some(arg_list) = e.arg_list() { | 695 | let args = if let Some(arg_list) = e.arg_list() { |
696 | arg_list.args().map(|e| self.collect_expr(e)).collect() | 696 | arg_list.args().map(|e| self.collect_expr(e)).collect() |
@@ -704,7 +704,7 @@ where | |||
704 | syntax_ptr, | 704 | syntax_ptr, |
705 | ) | 705 | ) |
706 | } | 706 | } |
707 | ast::ExprKind::MatchExpr(e) => { | 707 | ast::Expr::MatchExpr(e) => { |
708 | let expr = self.collect_expr_opt(e.expr()); | 708 | let expr = self.collect_expr_opt(e.expr()); |
709 | let arms = if let Some(match_arm_list) = e.match_arm_list() { | 709 | let arms = if let Some(match_arm_list) = e.match_arm_list() { |
710 | match_arm_list | 710 | match_arm_list |
@@ -723,30 +723,30 @@ where | |||
723 | }; | 723 | }; |
724 | self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) | 724 | self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) |
725 | } | 725 | } |
726 | ast::ExprKind::PathExpr(e) => { | 726 | ast::Expr::PathExpr(e) => { |
727 | let path = | 727 | let path = |
728 | e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing); | 728 | e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing); |
729 | self.alloc_expr(path, syntax_ptr) | 729 | self.alloc_expr(path, syntax_ptr) |
730 | } | 730 | } |
731 | ast::ExprKind::ContinueExpr(_e) => { | 731 | ast::Expr::ContinueExpr(_e) => { |
732 | // FIXME: labels | 732 | // FIXME: labels |
733 | self.alloc_expr(Expr::Continue, syntax_ptr) | 733 | self.alloc_expr(Expr::Continue, syntax_ptr) |
734 | } | 734 | } |
735 | ast::ExprKind::BreakExpr(e) => { | 735 | ast::Expr::BreakExpr(e) => { |
736 | let expr = e.expr().map(|e| self.collect_expr(e)); | 736 | let expr = e.expr().map(|e| self.collect_expr(e)); |
737 | self.alloc_expr(Expr::Break { expr }, syntax_ptr) | 737 | self.alloc_expr(Expr::Break { expr }, syntax_ptr) |
738 | } | 738 | } |
739 | ast::ExprKind::ParenExpr(e) => { | 739 | ast::Expr::ParenExpr(e) => { |
740 | let inner = self.collect_expr_opt(e.expr()); | 740 | let inner = self.collect_expr_opt(e.expr()); |
741 | // make the paren expr point to the inner expression as well | 741 | // make the paren expr point to the inner expression as well |
742 | self.source_map.expr_map.insert(syntax_ptr, inner); | 742 | self.source_map.expr_map.insert(syntax_ptr, inner); |
743 | inner | 743 | inner |
744 | } | 744 | } |
745 | ast::ExprKind::ReturnExpr(e) => { | 745 | ast::Expr::ReturnExpr(e) => { |
746 | let expr = e.expr().map(|e| self.collect_expr(e)); | 746 | let expr = e.expr().map(|e| self.collect_expr(e)); |
747 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) | 747 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) |
748 | } | 748 | } |
749 | ast::ExprKind::StructLit(e) => { | 749 | ast::Expr::StructLit(e) => { |
750 | let path = e.path().and_then(Path::from_ast); | 750 | let path = e.path().and_then(Path::from_ast); |
751 | let mut field_ptrs = Vec::new(); | 751 | let mut field_ptrs = Vec::new(); |
752 | let struct_lit = if let Some(nfl) = e.named_field_list() { | 752 | let struct_lit = if let Some(nfl) = e.named_field_list() { |
@@ -787,7 +787,7 @@ where | |||
787 | } | 787 | } |
788 | res | 788 | res |
789 | } | 789 | } |
790 | ast::ExprKind::FieldExpr(e) => { | 790 | ast::Expr::FieldExpr(e) => { |
791 | let expr = self.collect_expr_opt(e.expr()); | 791 | let expr = self.collect_expr_opt(e.expr()); |
792 | let name = match e.field_access() { | 792 | let name = match e.field_access() { |
793 | Some(kind) => kind.as_name(), | 793 | Some(kind) => kind.as_name(), |
@@ -795,25 +795,25 @@ where | |||
795 | }; | 795 | }; |
796 | self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) | 796 | self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) |
797 | } | 797 | } |
798 | ast::ExprKind::AwaitExpr(e) => { | 798 | ast::Expr::AwaitExpr(e) => { |
799 | let expr = self.collect_expr_opt(e.expr()); | 799 | let expr = self.collect_expr_opt(e.expr()); |
800 | self.alloc_expr(Expr::Await { expr }, syntax_ptr) | 800 | self.alloc_expr(Expr::Await { expr }, syntax_ptr) |
801 | } | 801 | } |
802 | ast::ExprKind::TryExpr(e) => { | 802 | ast::Expr::TryExpr(e) => { |
803 | let expr = self.collect_expr_opt(e.expr()); | 803 | let expr = self.collect_expr_opt(e.expr()); |
804 | self.alloc_expr(Expr::Try { expr }, syntax_ptr) | 804 | self.alloc_expr(Expr::Try { expr }, syntax_ptr) |
805 | } | 805 | } |
806 | ast::ExprKind::CastExpr(e) => { | 806 | ast::Expr::CastExpr(e) => { |
807 | let expr = self.collect_expr_opt(e.expr()); | 807 | let expr = self.collect_expr_opt(e.expr()); |
808 | let type_ref = TypeRef::from_ast_opt(e.type_ref()); | 808 | let type_ref = TypeRef::from_ast_opt(e.type_ref()); |
809 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) | 809 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) |
810 | } | 810 | } |
811 | ast::ExprKind::RefExpr(e) => { | 811 | ast::Expr::RefExpr(e) => { |
812 | let expr = self.collect_expr_opt(e.expr()); | 812 | let expr = self.collect_expr_opt(e.expr()); |
813 | let mutability = Mutability::from_mutable(e.is_mut()); | 813 | let mutability = Mutability::from_mutable(e.is_mut()); |
814 | self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) | 814 | self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) |
815 | } | 815 | } |
816 | ast::ExprKind::PrefixExpr(e) => { | 816 | ast::Expr::PrefixExpr(e) => { |
817 | let expr = self.collect_expr_opt(e.expr()); | 817 | let expr = self.collect_expr_opt(e.expr()); |
818 | if let Some(op) = e.op_kind() { | 818 | if let Some(op) = e.op_kind() { |
819 | self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr) | 819 | self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr) |
@@ -821,7 +821,7 @@ where | |||
821 | self.alloc_expr(Expr::Missing, syntax_ptr) | 821 | self.alloc_expr(Expr::Missing, syntax_ptr) |
822 | } | 822 | } |
823 | } | 823 | } |
824 | ast::ExprKind::LambdaExpr(e) => { | 824 | ast::Expr::LambdaExpr(e) => { |
825 | let mut args = Vec::new(); | 825 | let mut args = Vec::new(); |
826 | let mut arg_types = Vec::new(); | 826 | let mut arg_types = Vec::new(); |
827 | if let Some(pl) = e.param_list() { | 827 | if let Some(pl) = e.param_list() { |
@@ -835,18 +835,18 @@ where | |||
835 | let body = self.collect_expr_opt(e.body()); | 835 | let body = self.collect_expr_opt(e.body()); |
836 | self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr) | 836 | self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr) |
837 | } | 837 | } |
838 | ast::ExprKind::BinExpr(e) => { | 838 | ast::Expr::BinExpr(e) => { |
839 | let lhs = self.collect_expr_opt(e.lhs()); | 839 | let lhs = self.collect_expr_opt(e.lhs()); |
840 | let rhs = self.collect_expr_opt(e.rhs()); | 840 | let rhs = self.collect_expr_opt(e.rhs()); |
841 | let op = e.op_kind().map(BinaryOp::from); | 841 | let op = e.op_kind().map(BinaryOp::from); |
842 | self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr) | 842 | self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr) |
843 | } | 843 | } |
844 | ast::ExprKind::TupleExpr(e) => { | 844 | ast::Expr::TupleExpr(e) => { |
845 | let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); | 845 | let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); |
846 | self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) | 846 | self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) |
847 | } | 847 | } |
848 | 848 | ||
849 | ast::ExprKind::ArrayExpr(e) => { | 849 | ast::Expr::ArrayExpr(e) => { |
850 | let kind = e.kind(); | 850 | let kind = e.kind(); |
851 | 851 | ||
852 | match kind { | 852 | match kind { |
@@ -865,7 +865,7 @@ where | |||
865 | } | 865 | } |
866 | } | 866 | } |
867 | 867 | ||
868 | ast::ExprKind::Literal(e) => { | 868 | ast::Expr::Literal(e) => { |
869 | let lit = match e.kind() { | 869 | let lit = match e.kind() { |
870 | LiteralKind::IntNumber { suffix } => { | 870 | LiteralKind::IntNumber { suffix } => { |
871 | let known_name = suffix | 871 | let known_name = suffix |
@@ -895,16 +895,16 @@ where | |||
895 | }; | 895 | }; |
896 | self.alloc_expr(Expr::Literal(lit), syntax_ptr) | 896 | self.alloc_expr(Expr::Literal(lit), syntax_ptr) |
897 | } | 897 | } |
898 | ast::ExprKind::IndexExpr(e) => { | 898 | ast::Expr::IndexExpr(e) => { |
899 | let base = self.collect_expr_opt(e.base()); | 899 | let base = self.collect_expr_opt(e.base()); |
900 | let index = self.collect_expr_opt(e.index()); | 900 | let index = self.collect_expr_opt(e.index()); |
901 | self.alloc_expr(Expr::Index { base, index }, syntax_ptr) | 901 | self.alloc_expr(Expr::Index { base, index }, syntax_ptr) |
902 | } | 902 | } |
903 | 903 | ||
904 | // FIXME implement HIR for these: | 904 | // FIXME implement HIR for these: |
905 | ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 905 | ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
906 | ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 906 | ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
907 | ast::ExprKind::MacroCall(e) => { | 907 | ast::Expr::MacroCall(e) => { |
908 | let ast_id = self | 908 | let ast_id = self |
909 | .db | 909 | .db |
910 | .ast_id_map(self.current_file_id) | 910 | .ast_id_map(self.current_file_id) |
@@ -945,16 +945,14 @@ where | |||
945 | fn collect_block(&mut self, block: ast::Block) -> ExprId { | 945 | fn collect_block(&mut self, block: ast::Block) -> ExprId { |
946 | let statements = block | 946 | let statements = block |
947 | .statements() | 947 | .statements() |
948 | .map(|s| match s.kind() { | 948 | .map(|s| match s { |
949 | ast::StmtKind::LetStmt(stmt) => { | 949 | ast::Stmt::LetStmt(stmt) => { |
950 | let pat = self.collect_pat_opt(stmt.pat()); | 950 | let pat = self.collect_pat_opt(stmt.pat()); |
951 | let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); | 951 | let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); |
952 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 952 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
953 | Statement::Let { pat, type_ref, initializer } | 953 | Statement::Let { pat, type_ref, initializer } |
954 | } | 954 | } |
955 | ast::StmtKind::ExprStmt(stmt) => { | 955 | ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), |
956 | Statement::Expr(self.collect_expr_opt(stmt.expr())) | ||
957 | } | ||
958 | }) | 956 | }) |
959 | .collect(); | 957 | .collect(); |
960 | let tail = block.expr().map(|e| self.collect_expr(e)); | 958 | let tail = block.expr().map(|e| self.collect_expr(e)); |
@@ -970,33 +968,33 @@ where | |||
970 | } | 968 | } |
971 | 969 | ||
972 | fn collect_pat(&mut self, pat: ast::Pat) -> PatId { | 970 | fn collect_pat(&mut self, pat: ast::Pat) -> PatId { |
973 | let pattern = match pat.kind() { | 971 | let pattern = match &pat { |
974 | ast::PatKind::BindPat(bp) => { | 972 | ast::Pat::BindPat(bp) => { |
975 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); | 973 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); |
976 | let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref()); | 974 | let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref()); |
977 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); | 975 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); |
978 | Pat::Bind { name, mode: annotation, subpat } | 976 | Pat::Bind { name, mode: annotation, subpat } |
979 | } | 977 | } |
980 | ast::PatKind::TupleStructPat(p) => { | 978 | ast::Pat::TupleStructPat(p) => { |
981 | let path = p.path().and_then(Path::from_ast); | 979 | let path = p.path().and_then(Path::from_ast); |
982 | let args = p.args().map(|p| self.collect_pat(p)).collect(); | 980 | let args = p.args().map(|p| self.collect_pat(p)).collect(); |
983 | Pat::TupleStruct { path, args } | 981 | Pat::TupleStruct { path, args } |
984 | } | 982 | } |
985 | ast::PatKind::RefPat(p) => { | 983 | ast::Pat::RefPat(p) => { |
986 | let pat = self.collect_pat_opt(p.pat()); | 984 | let pat = self.collect_pat_opt(p.pat()); |
987 | let mutability = Mutability::from_mutable(p.is_mut()); | 985 | let mutability = Mutability::from_mutable(p.is_mut()); |
988 | Pat::Ref { pat, mutability } | 986 | Pat::Ref { pat, mutability } |
989 | } | 987 | } |
990 | ast::PatKind::PathPat(p) => { | 988 | ast::Pat::PathPat(p) => { |
991 | let path = p.path().and_then(Path::from_ast); | 989 | let path = p.path().and_then(Path::from_ast); |
992 | path.map(Pat::Path).unwrap_or(Pat::Missing) | 990 | path.map(Pat::Path).unwrap_or(Pat::Missing) |
993 | } | 991 | } |
994 | ast::PatKind::TuplePat(p) => { | 992 | ast::Pat::TuplePat(p) => { |
995 | let args = p.args().map(|p| self.collect_pat(p)).collect(); | 993 | let args = p.args().map(|p| self.collect_pat(p)).collect(); |
996 | Pat::Tuple(args) | 994 | Pat::Tuple(args) |
997 | } | 995 | } |
998 | ast::PatKind::PlaceholderPat(_) => Pat::Wild, | 996 | ast::Pat::PlaceholderPat(_) => Pat::Wild, |
999 | ast::PatKind::StructPat(p) => { | 997 | ast::Pat::StructPat(p) => { |
1000 | let path = p.path().and_then(Path::from_ast); | 998 | let path = p.path().and_then(Path::from_ast); |
1001 | let field_pat_list = | 999 | let field_pat_list = |
1002 | p.field_pat_list().expect("every struct should have a field list"); | 1000 | p.field_pat_list().expect("every struct should have a field list"); |
@@ -1022,8 +1020,8 @@ where | |||
1022 | } | 1020 | } |
1023 | 1021 | ||
1024 | // FIXME: implement | 1022 | // FIXME: implement |
1025 | ast::PatKind::LiteralPat(_) => Pat::Missing, | 1023 | ast::Pat::LiteralPat(_) => Pat::Missing, |
1026 | ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing, | 1024 | ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing, |
1027 | }; | 1025 | }; |
1028 | let ptr = AstPtr::new(&pat); | 1026 | let ptr = AstPtr::new(&pat); |
1029 | self.alloc_pat(pattern, Either::A(ptr)) | 1027 | self.alloc_pat(pattern, Either::A(ptr)) |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index bcbb4988d..e6482180d 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -137,8 +137,8 @@ impl GenericParams { | |||
137 | fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { | 137 | fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { |
138 | let path = bound | 138 | let path = bound |
139 | .type_ref() | 139 | .type_ref() |
140 | .and_then(|tr| match tr.kind() { | 140 | .and_then(|tr| match tr { |
141 | ast::TypeRefKind::PathType(path) => path.path(), | 141 | ast::TypeRef::PathType(path) => path.path(), |
142 | _ => None, | 142 | _ => None, |
143 | }) | 143 | }) |
144 | .and_then(Path::from_ast); | 144 | .and_then(Path::from_ast); |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 8e62cf66d..62a41719a 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -131,10 +131,10 @@ impl ImplData { | |||
131 | let items = if let Some(item_list) = node.item_list() { | 131 | let items = if let Some(item_list) = node.item_list() { |
132 | item_list | 132 | item_list |
133 | .impl_items() | 133 | .impl_items() |
134 | .map(|item_node| match item_node.kind() { | 134 | .map(|item_node| match item_node { |
135 | ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(&it) }.into(), | 135 | ast::ImplItem::FnDef(it) => Function { id: ctx.to_def(&it) }.into(), |
136 | ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(), | 136 | ast::ImplItem::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(), |
137 | ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(), | 137 | ast::ImplItem::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(), |
138 | }) | 138 | }) |
139 | .collect() | 139 | .collect() |
140 | } else { | 140 | } else { |
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 584e15e29..2f973359f 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -207,24 +207,24 @@ impl RawItemsCollector { | |||
207 | } | 207 | } |
208 | 208 | ||
209 | fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) { | 209 | fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) { |
210 | let (kind, name) = match item.kind() { | 210 | let (kind, name) = match item { |
211 | ast::ModuleItemKind::Module(module) => { | 211 | ast::ModuleItem::Module(module) => { |
212 | self.add_module(current_module, module); | 212 | self.add_module(current_module, module); |
213 | return; | 213 | return; |
214 | } | 214 | } |
215 | ast::ModuleItemKind::UseItem(use_item) => { | 215 | ast::ModuleItem::UseItem(use_item) => { |
216 | self.add_use_item(current_module, use_item); | 216 | self.add_use_item(current_module, use_item); |
217 | return; | 217 | return; |
218 | } | 218 | } |
219 | ast::ModuleItemKind::ExternCrateItem(extern_crate) => { | 219 | ast::ModuleItem::ExternCrateItem(extern_crate) => { |
220 | self.add_extern_crate_item(current_module, extern_crate); | 220 | self.add_extern_crate_item(current_module, extern_crate); |
221 | return; | 221 | return; |
222 | } | 222 | } |
223 | ast::ModuleItemKind::ImplBlock(_) => { | 223 | ast::ModuleItem::ImplBlock(_) => { |
224 | // impls don't participate in name resolution | 224 | // impls don't participate in name resolution |
225 | return; | 225 | return; |
226 | } | 226 | } |
227 | ast::ModuleItemKind::StructDef(it) => { | 227 | ast::ModuleItem::StructDef(it) => { |
228 | let id = self.source_ast_id_map.ast_id(&it); | 228 | let id = self.source_ast_id_map.ast_id(&it); |
229 | let name = it.name(); | 229 | let name = it.name(); |
230 | if it.is_union() { | 230 | if it.is_union() { |
@@ -233,22 +233,22 @@ impl RawItemsCollector { | |||
233 | (DefKind::Struct(id), name) | 233 | (DefKind::Struct(id), name) |
234 | } | 234 | } |
235 | } | 235 | } |
236 | ast::ModuleItemKind::EnumDef(it) => { | 236 | ast::ModuleItem::EnumDef(it) => { |
237 | (DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name()) | 237 | (DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name()) |
238 | } | 238 | } |
239 | ast::ModuleItemKind::FnDef(it) => { | 239 | ast::ModuleItem::FnDef(it) => { |
240 | (DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name()) | 240 | (DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name()) |
241 | } | 241 | } |
242 | ast::ModuleItemKind::TraitDef(it) => { | 242 | ast::ModuleItem::TraitDef(it) => { |
243 | (DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name()) | 243 | (DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name()) |
244 | } | 244 | } |
245 | ast::ModuleItemKind::TypeAliasDef(it) => { | 245 | ast::ModuleItem::TypeAliasDef(it) => { |
246 | (DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name()) | 246 | (DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name()) |
247 | } | 247 | } |
248 | ast::ModuleItemKind::ConstDef(it) => { | 248 | ast::ModuleItem::ConstDef(it) => { |
249 | (DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name()) | 249 | (DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name()) |
250 | } | 250 | } |
251 | ast::ModuleItemKind::StaticDef(it) => { | 251 | ast::ModuleItem::StaticDef(it) => { |
252 | (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name()) | 252 | (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name()) |
253 | } | 253 | } |
254 | }; | 254 | }; |
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index de26f1a68..6cdd3020a 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs | |||
@@ -30,10 +30,10 @@ impl TraitData { | |||
30 | let items = if let Some(item_list) = src.ast.item_list() { | 30 | let items = if let Some(item_list) = src.ast.item_list() { |
31 | item_list | 31 | item_list |
32 | .impl_items() | 32 | .impl_items() |
33 | .map(|item_node| match item_node.kind() { | 33 | .map(|item_node| match item_node { |
34 | ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(&it) }.into(), | 34 | ast::ImplItem::FnDef(it) => Function { id: ctx.to_def(&it) }.into(), |
35 | ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(), | 35 | ast::ImplItem::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(), |
36 | ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(), | 36 | ast::ImplItem::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(), |
37 | }) | 37 | }) |
38 | .collect() | 38 | .collect() |
39 | } else { | 39 | } else { |
diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs index 8536ae44a..b92a0b55a 100644 --- a/crates/ra_hir/src/type_ref.rs +++ b/crates/ra_hir/src/type_ref.rs | |||
@@ -57,28 +57,33 @@ pub enum TypeRef { | |||
57 | impl TypeRef { | 57 | impl TypeRef { |
58 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. | 58 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. |
59 | pub(crate) fn from_ast(node: ast::TypeRef) -> Self { | 59 | pub(crate) fn from_ast(node: ast::TypeRef) -> Self { |
60 | use ra_syntax::ast::TypeRefKind::*; | 60 | match node { |
61 | match node.kind() { | 61 | ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), |
62 | ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), | 62 | ast::TypeRef::TupleType(inner) => { |
63 | TupleType(inner) => TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()), | 63 | TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()) |
64 | NeverType(..) => TypeRef::Never, | 64 | } |
65 | PathType(inner) => { | 65 | ast::TypeRef::NeverType(..) => TypeRef::Never, |
66 | ast::TypeRef::PathType(inner) => { | ||
66 | inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error) | 67 | inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error) |
67 | } | 68 | } |
68 | PointerType(inner) => { | 69 | ast::TypeRef::PointerType(inner) => { |
69 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 70 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
70 | let mutability = Mutability::from_mutable(inner.is_mut()); | 71 | let mutability = Mutability::from_mutable(inner.is_mut()); |
71 | TypeRef::RawPtr(Box::new(inner_ty), mutability) | 72 | TypeRef::RawPtr(Box::new(inner_ty), mutability) |
72 | } | 73 | } |
73 | ArrayType(inner) => TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref()))), | 74 | ast::TypeRef::ArrayType(inner) => { |
74 | SliceType(inner) => TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref()))), | 75 | TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref()))) |
75 | ReferenceType(inner) => { | 76 | } |
77 | ast::TypeRef::SliceType(inner) => { | ||
78 | TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref()))) | ||
79 | } | ||
80 | ast::TypeRef::ReferenceType(inner) => { | ||
76 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 81 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
77 | let mutability = Mutability::from_mutable(inner.is_mut()); | 82 | let mutability = Mutability::from_mutable(inner.is_mut()); |
78 | TypeRef::Reference(Box::new(inner_ty), mutability) | 83 | TypeRef::Reference(Box::new(inner_ty), mutability) |
79 | } | 84 | } |
80 | PlaceholderType(_inner) => TypeRef::Placeholder, | 85 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, |
81 | FnPointerType(inner) => { | 86 | ast::TypeRef::FnPointerType(inner) => { |
82 | let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref())); | 87 | let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref())); |
83 | let mut params = if let Some(pl) = inner.param_list() { | 88 | let mut params = if let Some(pl) = inner.param_list() { |
84 | pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect() | 89 | pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect() |
@@ -89,9 +94,9 @@ impl TypeRef { | |||
89 | TypeRef::Fn(params) | 94 | TypeRef::Fn(params) |
90 | } | 95 | } |
91 | // for types are close enough for our purposes to the inner type for now... | 96 | // for types are close enough for our purposes to the inner type for now... |
92 | ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()), | 97 | ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()), |
93 | ImplTraitType(_inner) => TypeRef::Error, | 98 | ast::TypeRef::ImplTraitType(_inner) => TypeRef::Error, |
94 | DynTraitType(_inner) => TypeRef::Error, | 99 | ast::TypeRef::DynTraitType(_inner) => TypeRef::Error, |
95 | } | 100 | } |
96 | } | 101 | } |
97 | 102 | ||