diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index bf9609d8c..6aaf61c0e 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -48,7 +48,7 @@ use crate::{ | |||
48 | resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, | 48 | resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, |
49 | ty::infer::diagnostics::InferenceDiagnostic, | 49 | ty::infer::diagnostics::InferenceDiagnostic, |
50 | type_ref::{Mutability, TypeRef}, | 50 | type_ref::{Mutability, TypeRef}, |
51 | Adt, ConstData, DefWithBody, Either, FnData, Function, HasBody, ImplItem, Name, Path, | 51 | Adt, AssocItem, ConstData, DefWithBody, Either, FnData, Function, HasBody, ImplItem, Name, Path, |
52 | StructField, | 52 | StructField, |
53 | }; | 53 | }; |
54 | 54 | ||
@@ -121,7 +121,7 @@ pub struct InferenceResult { | |||
121 | /// For each struct literal, records the variant it resolves to. | 121 | /// For each struct literal, records the variant it resolves to. |
122 | variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>, | 122 | variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>, |
123 | /// For each associated item record what it resolves to | 123 | /// For each associated item record what it resolves to |
124 | assoc_resolutions: FxHashMap<ExprOrPatId, ImplItem>, | 124 | assoc_resolutions: FxHashMap<ExprOrPatId, AssocItem>, |
125 | diagnostics: Vec<InferenceDiagnostic>, | 125 | diagnostics: Vec<InferenceDiagnostic>, |
126 | pub(super) type_of_expr: ArenaMap<ExprId, Ty>, | 126 | pub(super) type_of_expr: ArenaMap<ExprId, Ty>, |
127 | pub(super) type_of_pat: ArenaMap<PatId, Ty>, | 127 | pub(super) type_of_pat: ArenaMap<PatId, Ty>, |
@@ -141,10 +141,10 @@ impl InferenceResult { | |||
141 | pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> { | 141 | pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> { |
142 | self.variant_resolutions.get(&id.into()).copied() | 142 | self.variant_resolutions.get(&id.into()).copied() |
143 | } | 143 | } |
144 | pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> { | 144 | pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<AssocItem> { |
145 | self.assoc_resolutions.get(&id.into()).copied() | 145 | self.assoc_resolutions.get(&id.into()).copied() |
146 | } | 146 | } |
147 | pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<ImplItem> { | 147 | pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<AssocItem> { |
148 | self.assoc_resolutions.get(&id.into()).copied() | 148 | self.assoc_resolutions.get(&id.into()).copied() |
149 | } | 149 | } |
150 | pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> { | 150 | pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> { |
@@ -235,7 +235,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
235 | self.result.variant_resolutions.insert(id, variant); | 235 | self.result.variant_resolutions.insert(id, variant); |
236 | } | 236 | } |
237 | 237 | ||
238 | fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: ImplItem) { | 238 | fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: AssocItem) { |
239 | self.result.assoc_resolutions.insert(id, item); | 239 | self.result.assoc_resolutions.insert(id, item); |
240 | } | 240 | } |
241 | 241 | ||
@@ -560,8 +560,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
560 | let ty = mem::replace(&mut ty, Ty::Unknown); | 560 | let ty = mem::replace(&mut ty, Ty::Unknown); |
561 | def_or_ty = ty.iterate_impl_items(self.db, krate, |item| { | 561 | def_or_ty = ty.iterate_impl_items(self.db, krate, |item| { |
562 | match item { | 562 | match item { |
563 | crate::ImplItem::Method(_) => None, | 563 | crate::ImplItem::Method(_) | crate::ImplItem::Const(_) => None, |
564 | crate::ImplItem::Const(_) => None, | ||
565 | 564 | ||
566 | // FIXME: Resolve associated types | 565 | // FIXME: Resolve associated types |
567 | crate::ImplItem::TypeAlias(_) => { | 566 | crate::ImplItem::TypeAlias(_) => { |
@@ -573,34 +572,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
573 | } | 572 | } |
574 | 573 | ||
575 | let segment = path.segments.last().unwrap(); | 574 | let segment = path.segments.last().unwrap(); |
576 | let def = ty.clone().iterate_impl_items(self.db, krate, |item| { | 575 | let def = ty.clone().iterate_impl_items(self.db, krate, |item| match item { |
577 | let matching_def: Option<ValueNs> = match item { | 576 | crate::ImplItem::Method(func) => { |
578 | crate::ImplItem::Method(func) => { | 577 | if segment.name == func.name(self.db) { |
579 | if segment.name == func.name(self.db) { | 578 | Some(ValueNs::Function(func)) |
580 | Some(ValueNs::Function(func)) | 579 | } else { |
581 | } else { | 580 | None |
582 | None | ||
583 | } | ||
584 | } | 581 | } |
582 | } | ||
585 | 583 | ||
586 | crate::ImplItem::Const(konst) => { | 584 | crate::ImplItem::Const(konst) => { |
587 | let data = konst.data(self.db); | 585 | if konst.name(self.db).map_or(false, |n| n == segment.name) { |
588 | if Some(&segment.name) == data.name() { | 586 | Some(ValueNs::Const(konst)) |
589 | Some(ValueNs::Const(konst)) | 587 | } else { |
590 | } else { | 588 | None |
591 | None | ||
592 | } | ||
593 | } | ||
594 | crate::ImplItem::TypeAlias(_) => None, | ||
595 | }; | ||
596 | match matching_def { | ||
597 | Some(_) => { | ||
598 | self.write_assoc_resolution(id, item); | ||
599 | matching_def | ||
600 | } | 589 | } |
601 | None => None, | ||
602 | } | 590 | } |
591 | crate::ImplItem::TypeAlias(_) => None, | ||
603 | })?; | 592 | })?; |
593 | self.write_assoc_resolution( | ||
594 | id, | ||
595 | match def { | ||
596 | ValueNs::Function(f) => AssocItem::Function(f), | ||
597 | ValueNs::Const(c) => AssocItem::Const(c), | ||
598 | _ => unreachable!(), | ||
599 | }, | ||
600 | ); | ||
604 | let self_types = self.find_self_types(&def, ty); | 601 | let self_types = self.find_self_types(&def, ty); |
605 | Some((def, self_types)) | 602 | Some((def, self_types)) |
606 | } | 603 | } |