diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-12 21:18:14 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-12 21:18:14 +0000 |
commit | eb931c0d9e0877e573622253ae5b05563841037b (patch) | |
tree | 653ef81450a4d39c5b46f98c97c23fa8586dd7f8 /crates/ra_hir/src/expr.rs | |
parent | e56072bfa3e5af69a4c293a38de6e1350ada3573 (diff) | |
parent | 1ed7fbfc1badd2c2a42b4dc2feb1b4bf7835d3ef (diff) |
Merge #505
505: Inherent methods r=matklad a=flodiebold
This adds resolution, type checking and completion for inherent methods.
The main open question here is the caching, I think. I'm not sure whether we should be caching method resolutions in a more fine grained way (currently we just build a hash map of types -> impl blocks, and iterate through all potential impl blocks when looking for a method).
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index e5596cbaa..67e123e4d 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -18,13 +18,13 @@ impl_arena_id!(ExprId); | |||
18 | pub struct Body { | 18 | pub struct Body { |
19 | exprs: Arena<ExprId, Expr>, | 19 | exprs: Arena<ExprId, Expr>, |
20 | pats: Arena<PatId, Pat>, | 20 | pats: Arena<PatId, Pat>, |
21 | /// The patterns for the function's arguments. While the argument types are | 21 | /// The patterns for the function's parameters. While the parameter types are |
22 | /// part of the function signature, the patterns are not (they don't change | 22 | /// part of the function signature, the patterns are not (they don't change |
23 | /// the external type of the function). | 23 | /// the external type of the function). |
24 | /// | 24 | /// |
25 | /// If this `Body` is for the body of a constant, this will just be | 25 | /// If this `Body` is for the body of a constant, this will just be |
26 | /// empty. | 26 | /// empty. |
27 | args: Vec<PatId>, | 27 | params: Vec<PatId>, |
28 | /// The `ExprId` of the actual body expression. | 28 | /// The `ExprId` of the actual body expression. |
29 | body_expr: ExprId, | 29 | body_expr: ExprId, |
30 | } | 30 | } |
@@ -44,8 +44,8 @@ pub struct BodySyntaxMapping { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | impl Body { | 46 | impl Body { |
47 | pub fn args(&self) -> &[PatId] { | 47 | pub fn params(&self) -> &[PatId] { |
48 | &self.args | 48 | &self.params |
49 | } | 49 | } |
50 | 50 | ||
51 | pub fn body_expr(&self) -> ExprId { | 51 | pub fn body_expr(&self) -> ExprId { |
@@ -699,11 +699,11 @@ impl ExprCollector { | |||
699 | } | 699 | } |
700 | } | 700 | } |
701 | 701 | ||
702 | fn into_body_syntax_mapping(self, args: Vec<PatId>, body_expr: ExprId) -> BodySyntaxMapping { | 702 | fn into_body_syntax_mapping(self, params: Vec<PatId>, body_expr: ExprId) -> BodySyntaxMapping { |
703 | let body = Body { | 703 | let body = Body { |
704 | exprs: self.exprs, | 704 | exprs: self.exprs, |
705 | pats: self.pats, | 705 | pats: self.pats, |
706 | args, | 706 | params, |
707 | body_expr, | 707 | body_expr, |
708 | }; | 708 | }; |
709 | BodySyntaxMapping { | 709 | BodySyntaxMapping { |
@@ -719,8 +719,8 @@ impl ExprCollector { | |||
719 | pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping { | 719 | pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping { |
720 | let mut collector = ExprCollector::new(); | 720 | let mut collector = ExprCollector::new(); |
721 | 721 | ||
722 | let args = if let Some(param_list) = node.param_list() { | 722 | let params = if let Some(param_list) = node.param_list() { |
723 | let mut args = Vec::new(); | 723 | let mut params = Vec::new(); |
724 | 724 | ||
725 | if let Some(self_param) = param_list.self_param() { | 725 | if let Some(self_param) = param_list.self_param() { |
726 | let self_param = LocalSyntaxPtr::new( | 726 | let self_param = LocalSyntaxPtr::new( |
@@ -729,13 +729,13 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping { | |||
729 | .expect("self param without self keyword") | 729 | .expect("self param without self keyword") |
730 | .syntax(), | 730 | .syntax(), |
731 | ); | 731 | ); |
732 | let arg = collector.alloc_pat( | 732 | let param = collector.alloc_pat( |
733 | Pat::Bind { | 733 | Pat::Bind { |
734 | name: Name::self_param(), | 734 | name: Name::self_param(), |
735 | }, | 735 | }, |
736 | self_param, | 736 | self_param, |
737 | ); | 737 | ); |
738 | args.push(arg); | 738 | params.push(param); |
739 | } | 739 | } |
740 | 740 | ||
741 | for param in param_list.params() { | 741 | for param in param_list.params() { |
@@ -744,15 +744,15 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping { | |||
744 | } else { | 744 | } else { |
745 | continue; | 745 | continue; |
746 | }; | 746 | }; |
747 | args.push(collector.collect_pat(pat)); | 747 | params.push(collector.collect_pat(pat)); |
748 | } | 748 | } |
749 | args | 749 | params |
750 | } else { | 750 | } else { |
751 | Vec::new() | 751 | Vec::new() |
752 | }; | 752 | }; |
753 | 753 | ||
754 | let body = collector.collect_block_opt(node.body()); | 754 | let body = collector.collect_block_opt(node.body()); |
755 | collector.into_body_syntax_mapping(args, body) | 755 | collector.into_body_syntax_mapping(params, body) |
756 | } | 756 | } |
757 | 757 | ||
758 | pub(crate) fn body_syntax_mapping( | 758 | pub(crate) fn body_syntax_mapping( |