diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-16 21:10:26 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-16 21:10:26 +0000 |
commit | edd4c1d8a6c270fe39ae881c23c722c658c87c32 (patch) | |
tree | 0e6b42eaaa3228d7af8d54355d034e698db5c743 /crates/ra_hir/src/ty/method_resolution.rs | |
parent | 6932b77093fd444def066e80ed37defa2742f2a9 (diff) | |
parent | 0242acae5388188c06d826f4aed41eee3e91d018 (diff) |
Merge #842
842: Turn ImplBlock into a copy type just containing IDs r=matklad a=flodiebold
This makes it more like the other code model types.
Also make Module::definition_source/declaration_source return HirFileIds, to
make them more like the other source functions.
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 | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index e81bd3e06..8d1076774 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -40,32 +40,25 @@ pub struct CrateImplBlocks { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | impl CrateImplBlocks { | 42 | impl CrateImplBlocks { |
43 | pub fn lookup_impl_blocks<'a>( | 43 | pub fn lookup_impl_blocks<'a>(&'a self, ty: &Ty) -> impl Iterator<Item = ImplBlock> + 'a { |
44 | &'a self, | ||
45 | db: &'a impl HirDatabase, | ||
46 | ty: &Ty, | ||
47 | ) -> impl Iterator<Item = (Module, ImplBlock)> + 'a { | ||
48 | let fingerprint = TyFingerprint::for_impl(ty); | 44 | let fingerprint = TyFingerprint::for_impl(ty); |
49 | fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flat_map(|i| i.iter()).map( | 45 | fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flat_map(|i| i.iter()).map( |
50 | move |(module_id, impl_id)| { | 46 | move |(module_id, impl_id)| { |
51 | let module = Module { krate: self.krate, module_id: *module_id }; | 47 | let module = Module { krate: self.krate, module_id: *module_id }; |
52 | let module_impl_blocks = db.impls_in_module(module); | 48 | ImplBlock::from_id(module, *impl_id) |
53 | (module, ImplBlock::from_id(module_impl_blocks, *impl_id)) | ||
54 | }, | 49 | }, |
55 | ) | 50 | ) |
56 | } | 51 | } |
57 | 52 | ||
58 | pub fn lookup_impl_blocks_for_trait<'a>( | 53 | pub fn lookup_impl_blocks_for_trait<'a>( |
59 | &'a self, | 54 | &'a self, |
60 | db: &'a impl HirDatabase, | ||
61 | tr: &Trait, | 55 | tr: &Trait, |
62 | ) -> impl Iterator<Item = (Module, ImplBlock)> + 'a { | 56 | ) -> impl Iterator<Item = ImplBlock> + 'a { |
63 | let id = tr.id; | 57 | let id = tr.id; |
64 | self.impls_by_trait.get(&id).into_iter().flat_map(|i| i.iter()).map( | 58 | self.impls_by_trait.get(&id).into_iter().flat_map(|i| i.iter()).map( |
65 | move |(module_id, impl_id)| { | 59 | move |(module_id, impl_id)| { |
66 | let module = Module { krate: self.krate, module_id: *module_id }; | 60 | let module = Module { krate: self.krate, module_id: *module_id }; |
67 | let module_impl_blocks = db.impls_in_module(module); | 61 | ImplBlock::from_id(module, *impl_id) |
68 | (module, ImplBlock::from_id(module_impl_blocks, *impl_id)) | ||
69 | }, | 62 | }, |
70 | ) | 63 | ) |
71 | } | 64 | } |
@@ -74,7 +67,7 @@ impl CrateImplBlocks { | |||
74 | let module_impl_blocks = db.impls_in_module(module.clone()); | 67 | let module_impl_blocks = db.impls_in_module(module.clone()); |
75 | 68 | ||
76 | for (impl_id, _) in module_impl_blocks.impls.iter() { | 69 | for (impl_id, _) in module_impl_blocks.impls.iter() { |
77 | let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); | 70 | let impl_block = ImplBlock::from_id(module_impl_blocks.module, impl_id); |
78 | 71 | ||
79 | let target_ty = impl_block.target_ty(db); | 72 | let target_ty = impl_block.target_ty(db); |
80 | 73 | ||
@@ -159,11 +152,11 @@ impl Ty { | |||
159 | }; | 152 | }; |
160 | let impls = db.impls_in_crate(krate); | 153 | let impls = db.impls_in_crate(krate); |
161 | 154 | ||
162 | for (_, impl_block) in impls.lookup_impl_blocks(db, &derefed_ty) { | 155 | for impl_block in impls.lookup_impl_blocks(&derefed_ty) { |
163 | for item in impl_block.items() { | 156 | for item in impl_block.items(db) { |
164 | match item { | 157 | match item { |
165 | ImplItem::Method(f) => { | 158 | ImplItem::Method(f) => { |
166 | if let Some(result) = callback(*f) { | 159 | if let Some(result) = callback(f) { |
167 | return Some(result); | 160 | return Some(result); |
168 | } | 161 | } |
169 | } | 162 | } |
@@ -185,9 +178,9 @@ impl Ty { | |||
185 | let krate = def_crate(db, &self)?; | 178 | let krate = def_crate(db, &self)?; |
186 | let impls = db.impls_in_crate(krate); | 179 | let impls = db.impls_in_crate(krate); |
187 | 180 | ||
188 | for (_, impl_block) in impls.lookup_impl_blocks(db, &self) { | 181 | for impl_block in impls.lookup_impl_blocks(&self) { |
189 | for item in impl_block.items() { | 182 | for item in impl_block.items(db) { |
190 | if let Some(result) = callback(*item) { | 183 | if let Some(result) = callback(item) { |
191 | return Some(result); | 184 | return Some(result); |
192 | } | 185 | } |
193 | } | 186 | } |