From 7b7d051e8102529eb75c64281e368b84a1e0989d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 21 Apr 2021 17:57:45 +0200 Subject: Add failing local items test --- crates/hir_def/src/body/tests.rs | 8 ++++++++ crates/hir_def/src/body/tests/block.rs | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'crates/hir_def/src/body') diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs index 63f5fe88d..3e8f16306 100644 --- a/crates/hir_def/src/body/tests.rs +++ b/crates/hir_def/src/body/tests.rs @@ -40,6 +40,14 @@ fn block_def_map_at(ra_fixture: &str) -> String { module.def_map(&db).dump(&db) } +fn check_block_scopes_at(ra_fixture: &str, expect: Expect) { + let (db, position) = crate::test_db::TestDB::with_position(ra_fixture); + + let module = db.module_at_position(position); + let actual = module.def_map(&db).dump_block_scopes(&db); + expect.assert_eq(&actual); +} + fn check_at(ra_fixture: &str, expect: Expect) { let actual = block_def_map_at(ra_fixture); expect.assert_eq(&actual); diff --git a/crates/hir_def/src/body/tests/block.rs b/crates/hir_def/src/body/tests/block.rs index 3b6ba4cde..bc3d0f138 100644 --- a/crates/hir_def/src/body/tests/block.rs +++ b/crates/hir_def/src/body/tests/block.rs @@ -133,6 +133,30 @@ struct Struct {} ); } +#[test] +fn nested_module_scoping() { + check_block_scopes_at( + r#" +fn f() { + mod module { + struct Struct {} + fn f() { + use self::Struct; + $0 + } + } +} + "#, + expect![[r#" + BlockId(1) in ModuleId { krate: CrateId(0), block: Some(BlockId(0)), local_id: Idx::(0) } + BlockId(0) in ModuleId { krate: CrateId(0), block: None, local_id: Idx::(0) } + crate scope + "#]], + ); + // FIXME: The module nesting here is wrong! + // The first block map should be located in module #1 (`mod module`), not #0 (BlockId(0) root module) +} + #[test] fn legacy_macro_items() { // Checks that legacy-scoped `macro_rules!` from parent namespaces are resolved and expanded -- cgit v1.2.3