diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index d447b4571..d1f10e675 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -11,8 +11,8 @@ use std::fmt::Write; | |||
11 | use std::sync::Arc; | 11 | use std::sync::Arc; |
12 | 12 | ||
13 | use hir_def::{ | 13 | use hir_def::{ |
14 | body::BodySourceMap, child_by_source::ChildBySource, db::DefDatabase, keys, | 14 | body::BodySourceMap, child_by_source::ChildBySource, db::DefDatabase, item_scope::ItemScope, |
15 | nameres::CrateDefMap, AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, | 15 | keys, nameres::CrateDefMap, AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, |
16 | }; | 16 | }; |
17 | use hir_expand::InFile; | 17 | use hir_expand::InFile; |
18 | use insta::assert_snapshot; | 18 | use insta::assert_snapshot; |
@@ -163,35 +163,69 @@ fn visit_module( | |||
163 | module_id: LocalModuleId, | 163 | module_id: LocalModuleId, |
164 | cb: &mut dyn FnMut(DefWithBodyId), | 164 | cb: &mut dyn FnMut(DefWithBodyId), |
165 | ) { | 165 | ) { |
166 | for decl in crate_def_map[module_id].scope.declarations() { | 166 | visit_scope(db, crate_def_map, &crate_def_map[module_id].scope, cb); |
167 | match decl { | ||
168 | ModuleDefId::FunctionId(it) => cb(it.into()), | ||
169 | ModuleDefId::ConstId(it) => cb(it.into()), | ||
170 | ModuleDefId::StaticId(it) => cb(it.into()), | ||
171 | ModuleDefId::TraitId(it) => { | ||
172 | let trait_data = db.trait_data(it); | ||
173 | for &(_, item) in trait_data.items.iter() { | ||
174 | match item { | ||
175 | AssocItemId::FunctionId(it) => cb(it.into()), | ||
176 | AssocItemId::ConstId(it) => cb(it.into()), | ||
177 | AssocItemId::TypeAliasId(_) => (), | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | ModuleDefId::ModuleId(it) => visit_module(db, crate_def_map, it.local_id, cb), | ||
182 | _ => (), | ||
183 | } | ||
184 | } | ||
185 | for impl_id in crate_def_map[module_id].scope.impls() { | 167 | for impl_id in crate_def_map[module_id].scope.impls() { |
186 | let impl_data = db.impl_data(impl_id); | 168 | let impl_data = db.impl_data(impl_id); |
187 | for &item in impl_data.items.iter() { | 169 | for &item in impl_data.items.iter() { |
188 | match item { | 170 | match item { |
189 | AssocItemId::FunctionId(it) => cb(it.into()), | 171 | AssocItemId::FunctionId(it) => { |
190 | AssocItemId::ConstId(it) => cb(it.into()), | 172 | let def = it.into(); |
173 | cb(def); | ||
174 | let body = db.body(def); | ||
175 | visit_scope(db, crate_def_map, &body.item_scope, cb); | ||
176 | } | ||
177 | AssocItemId::ConstId(it) => { | ||
178 | let def = it.into(); | ||
179 | cb(def); | ||
180 | let body = db.body(def); | ||
181 | visit_scope(db, crate_def_map, &body.item_scope, cb); | ||
182 | } | ||
191 | AssocItemId::TypeAliasId(_) => (), | 183 | AssocItemId::TypeAliasId(_) => (), |
192 | } | 184 | } |
193 | } | 185 | } |
194 | } | 186 | } |
187 | |||
188 | fn visit_scope( | ||
189 | db: &TestDB, | ||
190 | crate_def_map: &CrateDefMap, | ||
191 | scope: &ItemScope, | ||
192 | cb: &mut dyn FnMut(DefWithBodyId), | ||
193 | ) { | ||
194 | for decl in scope.declarations() { | ||
195 | match decl { | ||
196 | ModuleDefId::FunctionId(it) => { | ||
197 | let def = it.into(); | ||
198 | cb(def); | ||
199 | let body = db.body(def); | ||
200 | visit_scope(db, crate_def_map, &body.item_scope, cb); | ||
201 | } | ||
202 | ModuleDefId::ConstId(it) => { | ||
203 | let def = it.into(); | ||
204 | cb(def); | ||
205 | let body = db.body(def); | ||
206 | visit_scope(db, crate_def_map, &body.item_scope, cb); | ||
207 | } | ||
208 | ModuleDefId::StaticId(it) => { | ||
209 | let def = it.into(); | ||
210 | cb(def); | ||
211 | let body = db.body(def); | ||
212 | visit_scope(db, crate_def_map, &body.item_scope, cb); | ||
213 | } | ||
214 | ModuleDefId::TraitId(it) => { | ||
215 | let trait_data = db.trait_data(it); | ||
216 | for &(_, item) in trait_data.items.iter() { | ||
217 | match item { | ||
218 | AssocItemId::FunctionId(it) => cb(it.into()), | ||
219 | AssocItemId::ConstId(it) => cb(it.into()), | ||
220 | AssocItemId::TypeAliasId(_) => (), | ||
221 | } | ||
222 | } | ||
223 | } | ||
224 | ModuleDefId::ModuleId(it) => visit_module(db, crate_def_map, it.local_id, cb), | ||
225 | _ => (), | ||
226 | } | ||
227 | } | ||
228 | } | ||
195 | } | 229 | } |
196 | 230 | ||
197 | fn ellipsize(mut text: String, max_len: usize) -> String { | 231 | fn ellipsize(mut text: String, max_len: usize) -> String { |