Skip to content

Commit 1da0a27

Browse files
jonas-schievinkJonas Schievink
authored andcommitted
Use body.block_scopes in hir_ty tests
1 parent 0cb46a9 commit 1da0a27

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

crates/hir_ty/src/tests.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{env, sync::Arc};
1313
use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt};
1414
use expect_test::Expect;
1515
use hir_def::{
16-
body::{BodySourceMap, SyntheticSyntax},
16+
body::{Body, BodySourceMap, SyntheticSyntax},
1717
child_by_source::ChildBySource,
1818
db::DefDatabase,
1919
item_scope::ItemScope,
@@ -234,13 +234,13 @@ fn visit_module(
234234
let def = it.into();
235235
cb(def);
236236
let body = db.body(def);
237-
visit_scope(db, crate_def_map, &body.item_scope, cb);
237+
visit_body(db, &body, cb);
238238
}
239239
AssocItemId::ConstId(it) => {
240240
let def = it.into();
241241
cb(def);
242242
let body = db.body(def);
243-
visit_scope(db, crate_def_map, &body.item_scope, cb);
243+
visit_body(db, &body, cb);
244244
}
245245
AssocItemId::TypeAliasId(_) => (),
246246
}
@@ -259,19 +259,19 @@ fn visit_module(
259259
let def = it.into();
260260
cb(def);
261261
let body = db.body(def);
262-
visit_scope(db, crate_def_map, &body.item_scope, cb);
262+
visit_body(db, &body, cb);
263263
}
264264
ModuleDefId::ConstId(it) => {
265265
let def = it.into();
266266
cb(def);
267267
let body = db.body(def);
268-
visit_scope(db, crate_def_map, &body.item_scope, cb);
268+
visit_body(db, &body, cb);
269269
}
270270
ModuleDefId::StaticId(it) => {
271271
let def = it.into();
272272
cb(def);
273273
let body = db.body(def);
274-
visit_scope(db, crate_def_map, &body.item_scope, cb);
274+
visit_body(db, &body, cb);
275275
}
276276
ModuleDefId::TraitId(it) => {
277277
let trait_data = db.trait_data(it);
@@ -288,6 +288,14 @@ fn visit_module(
288288
}
289289
}
290290
}
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+
}
291299
}
292300

293301
fn ellipsize(mut text: String, max_len: usize) -> String {

0 commit comments

Comments
 (0)