aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 80b71e2d9..06b732215 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -105,8 +105,9 @@ where
105 module_id, 105 module_id,
106 file_id: file_id.into(), 106 file_id: file_id.into(),
107 raw_items: &raw_items, 107 raw_items: &raw_items,
108 parent_module: None,
108 } 109 }
109 .collect(None, raw_items.items()); 110 .collect(raw_items.items());
110 111
111 // main name resolution fixed-point loop. 112 // main name resolution fixed-point loop.
112 let mut i = 0; 113 let mut i = 0;
@@ -455,8 +456,14 @@ where
455 if !self.macro_stack_monitor.is_poison(macro_def_id) { 456 if !self.macro_stack_monitor.is_poison(macro_def_id) {
456 let file_id: HirFileId = macro_call_id.as_file(MacroFileKind::Items); 457 let file_id: HirFileId = macro_call_id.as_file(MacroFileKind::Items);
457 let raw_items = self.db.raw_items(file_id); 458 let raw_items = self.db.raw_items(file_id);
458 ModCollector { def_collector: &mut *self, file_id, module_id, raw_items: &raw_items } 459 ModCollector {
459 .collect(None, raw_items.items()); 460 def_collector: &mut *self,
461 file_id,
462 module_id,
463 raw_items: &raw_items,
464 parent_module: None,
465 }
466 .collect(raw_items.items());
460 } else { 467 } else {
461 log::error!("Too deep macro expansion: {:?}", macro_call_id); 468 log::error!("Too deep macro expansion: {:?}", macro_call_id);
462 self.def_map.poison_macros.insert(macro_def_id); 469 self.def_map.poison_macros.insert(macro_def_id);
@@ -476,16 +483,17 @@ struct ModCollector<'a, D> {
476 module_id: CrateModuleId, 483 module_id: CrateModuleId,
477 file_id: HirFileId, 484 file_id: HirFileId,
478 raw_items: &'a raw::RawItems, 485 raw_items: &'a raw::RawItems,
486 parent_module: Option<&'a Name>,
479} 487}
480 488
481impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> 489impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>>
482where 490where
483 DB: DefDatabase, 491 DB: DefDatabase,
484{ 492{
485 fn collect(&mut self, parent_module: Option<&Name>, items: &[raw::RawItem]) { 493 fn collect(&mut self, items: &[raw::RawItem]) {
486 for item in items { 494 for item in items {
487 match *item { 495 match *item {
488 raw::RawItem::Module(m) => self.collect_module(parent_module, &self.raw_items[m]), 496 raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]),
489 raw::RawItem::Import(import) => self.def_collector.unresolved_imports.push(( 497 raw::RawItem::Import(import) => self.def_collector.unresolved_imports.push((
490 self.module_id, 498 self.module_id,
491 import, 499 import,
@@ -497,7 +505,7 @@ where
497 } 505 }
498 } 506 }
499 507
500 fn collect_module(&mut self, _module: Option<&Name>, module: &raw::ModuleData) { 508 fn collect_module(&mut self, module: &raw::ModuleData) {
501 match module { 509 match module {
502 // inline module, just recurse 510 // inline module, just recurse
503 raw::ModuleData::Definition { name, items, ast_id } => { 511 raw::ModuleData::Definition { name, items, ast_id } => {
@@ -508,8 +516,9 @@ where
508 module_id, 516 module_id,
509 file_id: self.file_id, 517 file_id: self.file_id,
510 raw_items: self.raw_items, 518 raw_items: self.raw_items,
519 parent_module: Some(name),
511 } 520 }
512 .collect(Some(name), &*items); 521 .collect(&*items);
513 } 522 }
514 // out of line module, resolve, parse and recurse 523 // out of line module, resolve, parse and recurse
515 raw::ModuleData::Declaration { name, ast_id, attr_path } => { 524 raw::ModuleData::Declaration { name, ast_id, attr_path } => {
@@ -521,7 +530,7 @@ where
521 name, 530 name,
522 is_root, 531 is_root,
523 attr_path.as_ref(), 532 attr_path.as_ref(),
524 _module, 533 self.parent_module,
525 ) { 534 ) {
526 Ok(file_id) => { 535 Ok(file_id) => {
527 let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); 536 let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id));
@@ -531,8 +540,9 @@ where
531 module_id, 540 module_id,
532 file_id: file_id.into(), 541 file_id: file_id.into(),
533 raw_items: &raw_items, 542 raw_items: &raw_items,
543 parent_module: None,
534 } 544 }
535 .collect(None, raw_items.items()) 545 .collect(raw_items.items())
536 } 546 }
537 Err(candidate) => self.def_collector.def_map.diagnostics.push( 547 Err(candidate) => self.def_collector.def_map.diagnostics.push(
538 DefDiagnostic::UnresolvedModule { 548 DefDiagnostic::UnresolvedModule {