diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index c762ec606..5ea62a14c 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -496,6 +496,8 @@ impl InferenceResult { | |||
496 | struct InferenceContext<'a, D: HirDatabase> { | 496 | struct InferenceContext<'a, D: HirDatabase> { |
497 | db: &'a D, | 497 | db: &'a D, |
498 | scopes: Arc<FnScopes>, | 498 | scopes: Arc<FnScopes>, |
499 | /// The self param for the current method, if it exists. | ||
500 | self_param: Option<LocalSyntaxPtr>, | ||
499 | module: Module, | 501 | module: Module, |
500 | var_unification_table: InPlaceUnificationTable<TypeVarId>, | 502 | var_unification_table: InPlaceUnificationTable<TypeVarId>, |
501 | type_of: FxHashMap<LocalSyntaxPtr, Ty>, | 503 | type_of: FxHashMap<LocalSyntaxPtr, Ty>, |
@@ -506,6 +508,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
506 | InferenceContext { | 508 | InferenceContext { |
507 | type_of: FxHashMap::default(), | 509 | type_of: FxHashMap::default(), |
508 | var_unification_table: InPlaceUnificationTable::new(), | 510 | var_unification_table: InPlaceUnificationTable::new(), |
511 | self_param: None, // set during parameter typing | ||
509 | db, | 512 | db, |
510 | scopes, | 513 | scopes, |
511 | module, | 514 | module, |
@@ -628,6 +631,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
628 | let ty = self.resolve_ty_as_possible(ty.clone()); | 631 | let ty = self.resolve_ty_as_possible(ty.clone()); |
629 | return Ok(Some(ty)); | 632 | return Ok(Some(ty)); |
630 | }; | 633 | }; |
634 | } else if path.is_self() { | ||
635 | // resolve `self` param | ||
636 | let self_param = ctry!(self.self_param); | ||
637 | let ty = ctry!(self.type_of.get(&self_param)); | ||
638 | let ty = self.resolve_ty_as_possible(ty.clone()); | ||
639 | return Ok(Some(ty)); | ||
631 | }; | 640 | }; |
632 | 641 | ||
633 | // resolve in module | 642 | // resolve in module |
@@ -940,8 +949,9 @@ pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceRe | |||
940 | ctx.new_type_var() | 949 | ctx.new_type_var() |
941 | }; | 950 | }; |
942 | if let Some(self_kw) = self_param.self_kw() { | 951 | if let Some(self_kw) = self_param.self_kw() { |
943 | ctx.type_of | 952 | let self_param = LocalSyntaxPtr::new(self_kw.syntax()); |
944 | .insert(LocalSyntaxPtr::new(self_kw.syntax()), self_type); | 953 | ctx.self_param = Some(self_param); |
954 | ctx.type_of.insert(self_param, self_type); | ||
945 | } | 955 | } |
946 | } | 956 | } |
947 | for param in param_list.params() { | 957 | for param in param_list.params() { |