diff options
author | Jonas Schievink <[email protected]> | 2021-03-05 13:53:32 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-03-09 17:27:23 +0000 |
commit | 1da0a27626559eb74d2398db314df2edca18de70 (patch) | |
tree | 9b6760fadd6848fc607802d1fcef94aee0df653c /crates/hir_ty/src | |
parent | 0cb46a9e8d20a5f843e3a7fa6387779d1ff68c3b (diff) |
Use `body.block_scopes` in `hir_ty` tests
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/tests.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index 7386a4e7b..fc770ea60 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs | |||
@@ -13,7 +13,7 @@ use std::{env, sync::Arc}; | |||
13 | use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; | 13 | use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; |
14 | use expect_test::Expect; | 14 | use expect_test::Expect; |
15 | use hir_def::{ | 15 | use hir_def::{ |
16 | body::{BodySourceMap, SyntheticSyntax}, | 16 | body::{Body, BodySourceMap, SyntheticSyntax}, |
17 | child_by_source::ChildBySource, | 17 | child_by_source::ChildBySource, |
18 | db::DefDatabase, | 18 | db::DefDatabase, |
19 | item_scope::ItemScope, | 19 | item_scope::ItemScope, |
@@ -234,13 +234,13 @@ fn visit_module( | |||
234 | let def = it.into(); | 234 | let def = it.into(); |
235 | cb(def); | 235 | cb(def); |
236 | let body = db.body(def); | 236 | let body = db.body(def); |
237 | visit_scope(db, crate_def_map, &body.item_scope, cb); | 237 | visit_body(db, &body, cb); |
238 | } | 238 | } |
239 | AssocItemId::ConstId(it) => { | 239 | AssocItemId::ConstId(it) => { |
240 | let def = it.into(); | 240 | let def = it.into(); |
241 | cb(def); | 241 | cb(def); |
242 | let body = db.body(def); | 242 | let body = db.body(def); |
243 | visit_scope(db, crate_def_map, &body.item_scope, cb); | 243 | visit_body(db, &body, cb); |
244 | } | 244 | } |
245 | AssocItemId::TypeAliasId(_) => (), | 245 | AssocItemId::TypeAliasId(_) => (), |
246 | } | 246 | } |
@@ -259,19 +259,19 @@ fn visit_module( | |||
259 | let def = it.into(); | 259 | let def = it.into(); |
260 | cb(def); | 260 | cb(def); |
261 | let body = db.body(def); | 261 | let body = db.body(def); |
262 | visit_scope(db, crate_def_map, &body.item_scope, cb); | 262 | visit_body(db, &body, cb); |
263 | } | 263 | } |
264 | ModuleDefId::ConstId(it) => { | 264 | ModuleDefId::ConstId(it) => { |
265 | let def = it.into(); | 265 | let def = it.into(); |
266 | cb(def); | 266 | cb(def); |
267 | let body = db.body(def); | 267 | let body = db.body(def); |
268 | visit_scope(db, crate_def_map, &body.item_scope, cb); | 268 | visit_body(db, &body, cb); |
269 | } | 269 | } |
270 | ModuleDefId::StaticId(it) => { | 270 | ModuleDefId::StaticId(it) => { |
271 | let def = it.into(); | 271 | let def = it.into(); |
272 | cb(def); | 272 | cb(def); |
273 | let body = db.body(def); | 273 | let body = db.body(def); |
274 | visit_scope(db, crate_def_map, &body.item_scope, cb); | 274 | visit_body(db, &body, cb); |
275 | } | 275 | } |
276 | ModuleDefId::TraitId(it) => { | 276 | ModuleDefId::TraitId(it) => { |
277 | let trait_data = db.trait_data(it); | 277 | let trait_data = db.trait_data(it); |
@@ -288,6 +288,14 @@ fn visit_module( | |||
288 | } | 288 | } |
289 | } | 289 | } |
290 | } | 290 | } |
291 | |||
292 | fn visit_body(db: &TestDB, body: &Body, cb: &mut dyn FnMut(DefWithBodyId)) { | ||
293 | for def_map in body.block_scopes.iter().filter_map(|block| db.block_def_map(*block)) { | ||
294 | for (mod_id, _) in def_map.modules() { | ||
295 | visit_module(db, &def_map, mod_id, cb); | ||
296 | } | ||
297 | } | ||
298 | } | ||
291 | } | 299 | } |
292 | 300 | ||
293 | fn ellipsize(mut text: String, max_len: usize) -> String { | 301 | fn ellipsize(mut text: String, max_len: usize) -> String { |