diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-01 22:37:59 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-01 22:37:59 +0000 |
commit | 4447019f4b5f24728bb7b91b161755ddb373c74c (patch) | |
tree | c53ff3531cbbad182e821eb92fa9ad201d2bff0c /crates/ra_hir/src/ty/method_resolution.rs | |
parent | 2b5c226e86892113bcab478cdf4c9adaf1e7b2f6 (diff) | |
parent | c5852f422ff45adaa21815c1a15e03b067a56a82 (diff) |
Merge #693
693: Name resolution refactoring r=matklad a=flodiebold
This is still very WIP, but it's becoming quite big and I want to make sure this isn't going in a completely bad direction :sweat_smile:. I'm not really happy with how the path resolution looks, and I'm not sure `PerNs<Resolution>` is the best return type -- there are 'this cannot happen in the (types/values) namespace' cases everywhere. I also want to unify the `resolver` and `nameres` namespaces once I'm done switching everything to `Resolver`. Also, `Resolver` only has a lifetime because it needs to have a reference to the `ItemMap` during import resolution :confused:
The differences in the completion snapshots are almost completely just ordering (except it completes `Self` as well now), so I changed it to sort the completions before snapshotting.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/method_resolution.rs')
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index e857d6856..2282286b0 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -7,12 +7,10 @@ use std::sync::Arc; | |||
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | HirDatabase, module_tree::ModuleId, Module, ModuleDef, Crate, Name, Function, Trait, | 10 | HirDatabase, module_tree::ModuleId, Module, Crate, Name, Function, Trait, |
11 | ids::TraitId, | 11 | ids::TraitId, |
12 | impl_block::{ImplId, ImplBlock, ImplItem}, | 12 | impl_block::{ImplId, ImplBlock, ImplItem}, |
13 | generics::GenericParams, | ||
14 | ty::{AdtDef, Ty}, | 13 | ty::{AdtDef, Ty}, |
15 | type_ref::TypeRef, | ||
16 | }; | 14 | }; |
17 | 15 | ||
18 | /// This is used as a key for indexing impls. | 16 | /// This is used as a key for indexing impls. |
@@ -85,17 +83,10 @@ impl CrateImplBlocks { | |||
85 | fn collect_recursive(&mut self, db: &impl HirDatabase, module: &Module) { | 83 | fn collect_recursive(&mut self, db: &impl HirDatabase, module: &Module) { |
86 | let module_impl_blocks = db.impls_in_module(module.clone()); | 84 | let module_impl_blocks = db.impls_in_module(module.clone()); |
87 | 85 | ||
88 | for (impl_id, impl_data) in module_impl_blocks.impls.iter() { | 86 | for (impl_id, _) in module_impl_blocks.impls.iter() { |
89 | let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); | 87 | let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); |
90 | // TODO provide generics of impl | 88 | |
91 | let generics = GenericParams::default(); | 89 | let target_ty = impl_block.target_ty(db); |
92 | let target_ty = Ty::from_hir( | ||
93 | db, | ||
94 | &module, | ||
95 | Some(&impl_block), | ||
96 | &generics, | ||
97 | impl_data.target_type(), | ||
98 | ); | ||
99 | 90 | ||
100 | if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { | 91 | if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { |
101 | self.impls | 92 | self.impls |
@@ -104,14 +95,11 @@ impl CrateImplBlocks { | |||
104 | .push((module.module_id, impl_id)); | 95 | .push((module.module_id, impl_id)); |
105 | } | 96 | } |
106 | 97 | ||
107 | if let Some(TypeRef::Path(path)) = impl_data.target_trait() { | 98 | if let Some(tr) = impl_block.target_trait(db) { |
108 | let perns = module.resolve_path(db, path); | 99 | self.impls_by_trait |
109 | if let Some(ModuleDef::Trait(tr)) = perns.take_types() { | 100 | .entry(tr.id) |
110 | self.impls_by_trait | 101 | .or_insert_with(Vec::new) |
111 | .entry(tr.id) | 102 | .push((module.module_id, impl_id)); |
112 | .or_insert_with(Vec::new) | ||
113 | .push((module.module_id, impl_id)); | ||
114 | } | ||
115 | } | 103 | } |
116 | } | 104 | } |
117 | 105 | ||