File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff 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+
4351fn check_at ( ra_fixture : & str , expect : Expect ) {
4452 let actual = block_def_map_at ( ra_fixture) ;
4553 expect. assert_eq ( & actual) ;
Original file line number Diff line number Diff 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]
137161fn legacy_macro_items ( ) {
138162 // Checks that legacy-scoped `macro_rules!` from parent namespaces are resolved and expanded
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments