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 | |
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')
4 files changed, 24 insertions, 36 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 | ||
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap index 8ff6e55a6..91c48897c 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap | |||
@@ -1,12 +1,12 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-26T18:16:16.530712344+00:00" | 2 | created: "2019-01-27T14:52:29.934503829+00:00" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | expression: "&result" | 4 | expression: "&result" |
5 | source: crates/ra_hir/src/ty/tests.rs | 5 | source: crates/ra_hir/src/ty/tests.rs |
6 | --- | 6 | --- |
7 | [10; 11) 't': [unknown] | 7 | [10; 11) 't': T |
8 | [21; 26) '{ t }': [unknown] | 8 | [21; 26) '{ t }': T |
9 | [23; 24) 't': [unknown] | 9 | [23; 24) 't': T |
10 | [38; 98) '{ ...(1); }': () | 10 | [38; 98) '{ ...(1); }': () |
11 | [44; 46) 'id': fn id<u32>(T) -> T | 11 | [44; 46) 'id': fn id<u32>(T) -> T |
12 | [44; 52) 'id(1u32)': u32 | 12 | [44; 52) 'id(1u32)': u32 |
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap index f21bffa75..626f31252 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap | |||
@@ -1,5 +1,5 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-26T17:46:03.866825843+00:00" | 2 | created: "2019-01-27T14:52:29.938713255+00:00" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | expression: "&result" | 4 | expression: "&result" |
5 | source: crates/ra_hir/src/ty/tests.rs | 5 | source: crates/ra_hir/src/ty/tests.rs |
@@ -8,9 +8,9 @@ source: crates/ra_hir/src/ty/tests.rs | |||
8 | [65; 87) '{ ... }': [unknown] | 8 | [65; 87) '{ ... }': [unknown] |
9 | [75; 79) 'self': A<[unknown]> | 9 | [75; 79) 'self': A<[unknown]> |
10 | [75; 81) 'self.x': [unknown] | 10 | [75; 81) 'self.x': [unknown] |
11 | [99; 100) 't': [unknown] | 11 | [99; 100) 't': T |
12 | [110; 115) '{ t }': [unknown] | 12 | [110; 115) '{ t }': T |
13 | [112; 113) 't': [unknown] | 13 | [112; 113) 't': T |
14 | [135; 261) '{ ....x() }': i128 | 14 | [135; 261) '{ ....x() }': i128 |
15 | [146; 147) 'x': i32 | 15 | [146; 147) 'x': i32 |
16 | [150; 151) '1': i32 | 16 | [150; 151) '1': i32 |
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap index a99323264..216d1e41f 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap | |||
@@ -1,15 +1,15 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-27T16:54:18.368427685+00:00" | 2 | created: "2019-01-27T20:38:32.153717698+00:00" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | expression: "&result" | 4 | expression: "&result" |
5 | source: crates/ra_hir/src/ty/tests.rs | 5 | source: crates/ra_hir/src/ty/tests.rs |
6 | --- | 6 | --- |
7 | [10; 11) 'x': [unknown] | 7 | [10; 11) 'x': T |
8 | [21; 30) '{ x }': [unknown] | 8 | [21; 30) '{ x }': T |
9 | [27; 28) 'x': [unknown] | 9 | [27; 28) 'x': T |
10 | [44; 45) 'x': &[unknown] | 10 | [44; 45) 'x': &T |
11 | [56; 65) '{ x }': &[unknown] | 11 | [56; 65) '{ x }': &T |
12 | [62; 63) 'x': &[unknown] | 12 | [62; 63) 'x': &T |
13 | [77; 157) '{ ...(1); }': () | 13 | [77; 157) '{ ...(1); }': () |
14 | [87; 88) 'y': u32 | 14 | [87; 88) 'y': u32 |
15 | [91; 96) '10u32': u32 | 15 | [91; 96) '10u32': u32 |