diff options
author | Marco Groppo <[email protected]> | 2019-04-17 22:40:00 +0100 |
---|---|---|
committer | Marco Groppo <[email protected]> | 2019-04-19 23:20:26 +0100 |
commit | 8ebb20edce85b74eab0ed78ba5c4969ec733ad12 (patch) | |
tree | eb23fc45cc395de68ad60ced6bd65d80c4945245 /crates/ra_hir/src/ty/method_resolution.rs | |
parent | e85ee60c42db57368e24ad9ac24840c2494d383c (diff) |
New krate() method in Resolver.
Renamed Impl to ImplBlock.
Diffstat (limited to 'crates/ra_hir/src/ty/method_resolution.rs')
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 28 |
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 | 115 | fn def_crate(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<Crate> { |
116 | /// will actually be done by chalk. | ||
117 | pub(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 | |||
129 | fn 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) |