Skip to content

Commit e9fea82

Browse files
Merge #8613
8613: skip: Add failing local items test r=jonas-schievink a=jonas-schievink This is currently broken due to the way ItemTree stores inner items. This test serves as a reminder until this gets fixed. bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents c7ae16e + 7b7d051 commit e9fea82

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

crates/hir_def/src/body/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ fn block_def_map_at(ra_fixture: &str) -> String {
4040
module.def_map(&db).dump(&db)
4141
}
4242

43+
fn check_block_scopes_at(ra_fixture: &str, expect: Expect) {
44+
let (db, position) = crate::test_db::TestDB::with_position(ra_fixture);
45+
46+
let module = db.module_at_position(position);
47+
let actual = module.def_map(&db).dump_block_scopes(&db);
48+
expect.assert_eq(&actual);
49+
}
50+
4351
fn check_at(ra_fixture: &str, expect: Expect) {
4452
let actual = block_def_map_at(ra_fixture);
4553
expect.assert_eq(&actual);

crates/hir_def/src/body/tests/block.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ struct Struct {}
133133
);
134134
}
135135

136+
#[test]
137+
fn nested_module_scoping() {
138+
check_block_scopes_at(
139+
r#"
140+
fn f() {
141+
mod module {
142+
struct Struct {}
143+
fn f() {
144+
use self::Struct;
145+
$0
146+
}
147+
}
148+
}
149+
"#,
150+
expect![[r#"
151+
BlockId(1) in ModuleId { krate: CrateId(0), block: Some(BlockId(0)), local_id: Idx::<ModuleData>(0) }
152+
BlockId(0) in ModuleId { krate: CrateId(0), block: None, local_id: Idx::<ModuleData>(0) }
153+
crate scope
154+
"#]],
155+
);
156+
// FIXME: The module nesting here is wrong!
157+
// The first block map should be located in module #1 (`mod module`), not #0 (BlockId(0) root module)
158+
}
159+
136160
#[test]
137161
fn legacy_macro_items() {
138162
// Checks that legacy-scoped `macro_rules!` from parent namespaces are resolved and expanded

crates/hir_def/src/nameres.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ impl DefMap {
410410
}
411411
}
412412

413+
pub fn dump_block_scopes(&self, db: &dyn DefDatabase) -> String {
414+
let mut buf = String::new();
415+
let mut arc;
416+
let mut current_map = self;
417+
while let Some(block) = &current_map.block {
418+
format_to!(buf, "{:?} in {:?}\n", block.block, block.parent);
419+
arc = block.parent.def_map(db);
420+
current_map = &*arc;
421+
}
422+
423+
format_to!(buf, "crate scope\n");
424+
buf
425+
}
426+
413427
fn shrink_to_fit(&mut self) {
414428
// Exhaustive match to require handling new fields.
415429
let Self {

0 commit comments

Comments
 (0)