aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/method_resolution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/method_resolution.rs')
-rw-r--r--crates/ra_hir_ty/src/method_resolution.rs30
1 files changed, 10 insertions, 20 deletions
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs
index 53c541eb8..ee1936b0e 100644
--- a/crates/ra_hir_ty/src/method_resolution.rs
+++ b/crates/ra_hir_ty/src/method_resolution.rs
@@ -6,8 +6,8 @@ use std::sync::Arc;
6 6
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use hir_def::{ 8use hir_def::{
9 lang_item::LangItemTarget, resolver::HasResolver, resolver::Resolver, type_ref::Mutability, 9 lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, AstItemDef,
10 AssocItemId, AstItemDef, FunctionId, HasModule, ImplId, TraitId, 10 FunctionId, HasModule, ImplId, TraitId,
11}; 11};
12use hir_expand::name::Name; 12use hir_expand::name::Name;
13use ra_db::CrateId; 13use ra_db::CrateId;
@@ -15,14 +15,13 @@ use ra_prof::profile;
15use rustc_hash::FxHashMap; 15use rustc_hash::FxHashMap;
16 16
17use crate::{ 17use crate::{
18 autoderef,
18 db::HirDatabase, 19 db::HirDatabase,
19 primitive::{FloatBitness, Uncertain}, 20 primitive::{FloatBitness, Uncertain},
20 utils::all_super_traits, 21 utils::all_super_traits,
21 Ty, TypeCtor, 22 Canonical, ImplTy, InEnvironment, TraitEnvironment, TraitRef, Ty, TypeCtor,
22}; 23};
23 24
24use super::{autoderef, Canonical, InEnvironment, TraitEnvironment, TraitRef};
25
26/// This is used as a key for indexing impls. 25/// This is used as a key for indexing impls.
27#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 26#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
28pub enum TyFingerprint { 27pub enum TyFingerprint {
@@ -59,22 +58,13 @@ impl CrateImplBlocks {
59 let crate_def_map = db.crate_def_map(krate); 58 let crate_def_map = db.crate_def_map(krate);
60 for (_module_id, module_data) in crate_def_map.modules.iter() { 59 for (_module_id, module_data) in crate_def_map.modules.iter() {
61 for &impl_id in module_data.impls.iter() { 60 for &impl_id in module_data.impls.iter() {
62 let impl_data = db.impl_data(impl_id); 61 match db.impl_ty(impl_id) {
63 let resolver = impl_id.resolver(db); 62 ImplTy::TraitRef(tr) => {
64 63 res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id);
65 let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
66
67 match &impl_data.target_trait {
68 Some(trait_ref) => {
69 if let Some(tr) =
70 TraitRef::from_hir(db, &resolver, &trait_ref, Some(target_ty))
71 {
72 res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id);
73 }
74 } 64 }
75 None => { 65 ImplTy::Inherent(self_ty) => {
76 if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { 66 if let Some(self_ty_fp) = TyFingerprint::for_impl(&self_ty) {
77 res.impls.entry(target_ty_fp).or_default().push(impl_id); 67 res.impls.entry(self_ty_fp).or_default().push(impl_id);
78 } 68 }
79 } 69 }
80 } 70 }