From 1da0a27626559eb74d2398db314df2edca18de70 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 5 Mar 2021 14:53:32 +0100 Subject: Use `body.block_scopes` in `hir_ty` tests --- crates/hir_ty/src/tests.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/tests.rs') 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}; use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; use expect_test::Expect; use hir_def::{ - body::{BodySourceMap, SyntheticSyntax}, + body::{Body, BodySourceMap, SyntheticSyntax}, child_by_source::ChildBySource, db::DefDatabase, item_scope::ItemScope, @@ -234,13 +234,13 @@ fn visit_module( let def = it.into(); cb(def); let body = db.body(def); - visit_scope(db, crate_def_map, &body.item_scope, cb); + visit_body(db, &body, cb); } AssocItemId::ConstId(it) => { let def = it.into(); cb(def); let body = db.body(def); - visit_scope(db, crate_def_map, &body.item_scope, cb); + visit_body(db, &body, cb); } AssocItemId::TypeAliasId(_) => (), } @@ -259,19 +259,19 @@ fn visit_module( let def = it.into(); cb(def); let body = db.body(def); - visit_scope(db, crate_def_map, &body.item_scope, cb); + visit_body(db, &body, cb); } ModuleDefId::ConstId(it) => { let def = it.into(); cb(def); let body = db.body(def); - visit_scope(db, crate_def_map, &body.item_scope, cb); + visit_body(db, &body, cb); } ModuleDefId::StaticId(it) => { let def = it.into(); cb(def); let body = db.body(def); - visit_scope(db, crate_def_map, &body.item_scope, cb); + visit_body(db, &body, cb); } ModuleDefId::TraitId(it) => { let trait_data = db.trait_data(it); @@ -288,6 +288,14 @@ fn visit_module( } } } + + fn visit_body(db: &TestDB, body: &Body, cb: &mut dyn FnMut(DefWithBodyId)) { + for def_map in body.block_scopes.iter().filter_map(|block| db.block_def_map(*block)) { + for (mod_id, _) in def_map.modules() { + visit_module(db, &def_map, mod_id, cb); + } + } + } } fn ellipsize(mut text: String, max_len: usize) -> String { -- cgit v1.2.3