aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/method_resolution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/method_resolution.rs')
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs28
1 files changed, 7 insertions, 21 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index ba516313c..dca56a434 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -112,33 +112,19 @@ impl CrateImplBlocks {
112 } 112 }
113} 113}
114 114
115/// Rudimentary check whether an impl exists for a given type and trait; this 115fn def_crate(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<Crate> {
116/// will actually be done by chalk.
117pub(crate) fn implements(db: &impl HirDatabase, trait_ref: TraitRef) -> bool {
118 // FIXME use all trait impls in the whole crate graph
119 let krate = trait_ref.trait_.module(db).krate(db);
120 let krate = match krate {
121 Some(krate) => krate,
122 None => return false,
123 };
124 let crate_impl_blocks = db.impls_in_crate(krate);
125 let mut impl_blocks = crate_impl_blocks.lookup_impl_blocks_for_trait(&trait_ref.trait_);
126 impl_blocks.any(|impl_block| &impl_block.target_ty(db) == trait_ref.self_ty())
127}
128
129fn def_crate(db: &impl HirDatabase, cur_krate: Crate, ty: &Ty) -> Option<Crate> {
130 match ty { 116 match ty {
131 Ty::Apply(a_ty) => match a_ty.ctor { 117 Ty::Apply(a_ty) => match a_ty.ctor {
132 TypeCtor::Adt(def_id) => def_id.krate(db), 118 TypeCtor::Adt(def_id) => def_id.krate(db),
133 TypeCtor::Bool => lang_item_lookup(db, cur_krate, "bool")?.krate(db), 119 TypeCtor::Bool => lang_item_lookup(db, cur_crate, "bool")?.krate(db),
134 TypeCtor::Char => lang_item_lookup(db, cur_krate, "char")?.krate(db), 120 TypeCtor::Char => lang_item_lookup(db, cur_crate, "char")?.krate(db),
135 TypeCtor::Float(UncertainFloatTy::Known(f)) => { 121 TypeCtor::Float(UncertainFloatTy::Known(f)) => {
136 lang_item_lookup(db, cur_krate, f.ty_to_string())?.krate(db) 122 lang_item_lookup(db, cur_crate, f.ty_to_string())?.krate(db)
137 } 123 }
138 TypeCtor::Int(UncertainIntTy::Known(i)) => { 124 TypeCtor::Int(UncertainIntTy::Known(i)) => {
139 lang_item_lookup(db, cur_krate, i.ty_to_string())?.krate(db) 125 lang_item_lookup(db, cur_crate, i.ty_to_string())?.krate(db)
140 } 126 }
141 TypeCtor::Str => lang_item_lookup(db, cur_krate, "str")?.krate(db), 127 TypeCtor::Str => lang_item_lookup(db, cur_crate, "str")?.krate(db),
142 _ => None, 128 _ => None,
143 }, 129 },
144 _ => None, 130 _ => None,
@@ -175,7 +161,7 @@ impl Ty {
175 // find in the end takes &self, we still do the autoderef step (just as 161 // find in the end takes &self, we still do the autoderef step (just as
176 // rustc does an autoderef and then autoref again). 162 // rustc does an autoderef and then autoref again).
177 163
178 let krate = resolver.module().map(|t| t.0.krate())?; 164 let krate = resolver.krate()?;
179 for derefed_ty in self.autoderef(db) { 165 for derefed_ty in self.autoderef(db) {
180 if let Some(result) = 166 if let Some(result) =
181 derefed_ty.iterate_inherent_methods(db, name, krate, &mut callback) 167 derefed_ty.iterate_inherent_methods(db, name, krate, &mut callback)