aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests.rs')
-rw-r--r--crates/hir_ty/src/tests.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs
index 7386a4e7b..0a4141e69 100644
--- a/crates/hir_ty/src/tests.rs
+++ b/crates/hir_ty/src/tests.rs
@@ -13,12 +13,13 @@ use std::{env, sync::Arc};
13use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; 13use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt};
14use expect_test::Expect; 14use expect_test::Expect;
15use hir_def::{ 15use 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,
20 keys, 20 keys,
21 nameres::DefMap, 21 nameres::DefMap,
22 src::HasSource,
22 AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, 23 AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
23}; 24};
24use hir_expand::{db::AstDatabase, InFile}; 25use hir_expand::{db::AstDatabase, InFile};
@@ -195,18 +196,15 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
195 defs.sort_by_key(|def| match def { 196 defs.sort_by_key(|def| match def {
196 DefWithBodyId::FunctionId(it) => { 197 DefWithBodyId::FunctionId(it) => {
197 let loc = it.lookup(&db); 198 let loc = it.lookup(&db);
198 let tree = db.item_tree(loc.id.file_id); 199 loc.source(&db).value.syntax().text_range().start()
199 tree.source(&db, loc.id).syntax().text_range().start()
200 } 200 }
201 DefWithBodyId::ConstId(it) => { 201 DefWithBodyId::ConstId(it) => {
202 let loc = it.lookup(&db); 202 let loc = it.lookup(&db);
203 let tree = db.item_tree(loc.id.file_id); 203 loc.source(&db).value.syntax().text_range().start()
204 tree.source(&db, loc.id).syntax().text_range().start()
205 } 204 }
206 DefWithBodyId::StaticId(it) => { 205 DefWithBodyId::StaticId(it) => {
207 let loc = it.lookup(&db); 206 let loc = it.lookup(&db);
208 let tree = db.item_tree(loc.id.file_id); 207 loc.source(&db).value.syntax().text_range().start()
209 tree.source(&db, loc.id).syntax().text_range().start()
210 } 208 }
211 }); 209 });
212 for def in defs { 210 for def in defs {
@@ -234,13 +232,13 @@ fn visit_module(
234 let def = it.into(); 232 let def = it.into();
235 cb(def); 233 cb(def);
236 let body = db.body(def); 234 let body = db.body(def);
237 visit_scope(db, crate_def_map, &body.item_scope, cb); 235 visit_body(db, &body, cb);
238 } 236 }
239 AssocItemId::ConstId(it) => { 237 AssocItemId::ConstId(it) => {
240 let def = it.into(); 238 let def = it.into();
241 cb(def); 239 cb(def);
242 let body = db.body(def); 240 let body = db.body(def);
243 visit_scope(db, crate_def_map, &body.item_scope, cb); 241 visit_body(db, &body, cb);
244 } 242 }
245 AssocItemId::TypeAliasId(_) => (), 243 AssocItemId::TypeAliasId(_) => (),
246 } 244 }
@@ -259,19 +257,19 @@ fn visit_module(
259 let def = it.into(); 257 let def = it.into();
260 cb(def); 258 cb(def);
261 let body = db.body(def); 259 let body = db.body(def);
262 visit_scope(db, crate_def_map, &body.item_scope, cb); 260 visit_body(db, &body, cb);
263 } 261 }
264 ModuleDefId::ConstId(it) => { 262 ModuleDefId::ConstId(it) => {
265 let def = it.into(); 263 let def = it.into();
266 cb(def); 264 cb(def);
267 let body = db.body(def); 265 let body = db.body(def);
268 visit_scope(db, crate_def_map, &body.item_scope, cb); 266 visit_body(db, &body, cb);
269 } 267 }
270 ModuleDefId::StaticId(it) => { 268 ModuleDefId::StaticId(it) => {
271 let def = it.into(); 269 let def = it.into();
272 cb(def); 270 cb(def);
273 let body = db.body(def); 271 let body = db.body(def);
274 visit_scope(db, crate_def_map, &body.item_scope, cb); 272 visit_body(db, &body, cb);
275 } 273 }
276 ModuleDefId::TraitId(it) => { 274 ModuleDefId::TraitId(it) => {
277 let trait_data = db.trait_data(it); 275 let trait_data = db.trait_data(it);
@@ -288,6 +286,14 @@ fn visit_module(
288 } 286 }
289 } 287 }
290 } 288 }
289
290 fn visit_body(db: &TestDB, body: &Body, cb: &mut dyn FnMut(DefWithBodyId)) {
291 for def_map in body.block_scopes.iter().filter_map(|block| db.block_def_map(*block)) {
292 for (mod_id, _) in def_map.modules() {
293 visit_module(db, &def_map, mod_id, cb);
294 }
295 }
296 }
291} 297}
292 298
293fn ellipsize(mut text: String, max_len: usize) -> String { 299fn ellipsize(mut text: String, max_len: usize) -> String {