aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/collector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres/collector.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 41becf8df..fd8245113 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -6,7 +6,7 @@
6use hir_expand::{ 6use hir_expand::{
7 builtin_macro::find_builtin_macro, 7 builtin_macro::find_builtin_macro,
8 name::{self, AsName, Name}, 8 name::{self, AsName, Name},
9 HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFileKind, 9 HirFileId, MacroCallId, MacroDefId, MacroDefKind, MacroFileKind,
10}; 10};
11use ra_cfg::CfgOptions; 11use ra_cfg::CfgOptions;
12use ra_db::{CrateId, FileId}; 12use ra_db::{CrateId, FileId};
@@ -25,7 +25,7 @@ use crate::{
25 per_ns::PerNs, 25 per_ns::PerNs,
26 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, 26 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId,
27 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, 27 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId,
28 StructOrUnionId, TraitId, TypeAliasLoc, UnionId, 28 TraitId, TypeAliasLoc, UnionId,
29}; 29};
30 30
31pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 31pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@@ -37,7 +37,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C
37 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); 37 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
38 def_map.extern_prelude.insert( 38 def_map.extern_prelude.insert(
39 dep.as_name(), 39 dep.as_name(),
40 ModuleId { krate: dep.crate_id, module_id: dep_def_map.root }.into(), 40 ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(),
41 ); 41 );
42 42
43 // look for the prelude 43 // look for the prelude
@@ -323,7 +323,7 @@ where
323 tested_by!(glob_across_crates); 323 tested_by!(glob_across_crates);
324 // glob import from other crate => we can just import everything once 324 // glob import from other crate => we can just import everything once
325 let item_map = self.db.crate_def_map(m.krate); 325 let item_map = self.db.crate_def_map(m.krate);
326 let scope = &item_map[m.module_id].scope; 326 let scope = &item_map[m.local_id].scope;
327 327
328 // Module scoped macros is included 328 // Module scoped macros is included
329 let items = scope 329 let items = scope
@@ -337,7 +337,7 @@ where
337 // glob import from same crate => we do an initial 337 // glob import from same crate => we do an initial
338 // import, and then need to propagate any further 338 // import, and then need to propagate any further
339 // additions 339 // additions
340 let scope = &self.def_map[m.module_id].scope; 340 let scope = &self.def_map[m.local_id].scope;
341 341
342 // Module scoped macros is included 342 // Module scoped macros is included
343 let items = scope 343 let items = scope
@@ -349,7 +349,7 @@ where
349 self.update(module_id, Some(import_id), &items); 349 self.update(module_id, Some(import_id), &items);
350 // record the glob import in case we add further items 350 // record the glob import in case we add further items
351 self.glob_imports 351 self.glob_imports
352 .entry(m.module_id) 352 .entry(m.local_id)
353 .or_default() 353 .or_default()
354 .push((module_id, import_id)); 354 .push((module_id, import_id));
355 } 355 }
@@ -362,7 +362,7 @@ where
362 .variants 362 .variants
363 .iter() 363 .iter()
364 .filter_map(|(local_id, variant_data)| { 364 .filter_map(|(local_id, variant_data)| {
365 let name = variant_data.name.clone()?; 365 let name = variant_data.name.clone();
366 let variant = EnumVariantId { parent: e, local_id }; 366 let variant = EnumVariantId { parent: e, local_id };
367 let res = Resolution { 367 let res = Resolution {
368 def: PerNs::both(variant.into(), variant.into()), 368 def: PerNs::both(variant.into(), variant.into()),
@@ -480,7 +480,7 @@ where
480 ); 480 );
481 481
482 if let Some(def) = resolved_res.resolved_def.take_macros() { 482 if let Some(def) = resolved_res.resolved_def.take_macros() {
483 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id }); 483 let call_id = def.as_call_id(self.db, *ast_id);
484 resolved.push((*module_id, call_id, def)); 484 resolved.push((*module_id, call_id, def));
485 res = ReachedFixedPoint::No; 485 res = ReachedFixedPoint::No;
486 return false; 486 return false;
@@ -590,7 +590,7 @@ where
590 raw::RawItemKind::Impl(imp) => { 590 raw::RawItemKind::Impl(imp) => {
591 let module = ModuleId { 591 let module = ModuleId {
592 krate: self.def_collector.def_map.krate, 592 krate: self.def_collector.def_map.krate,
593 module_id: self.module_id, 593 local_id: self.module_id,
594 }; 594 };
595 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); 595 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
596 let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id); 596 let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id);
@@ -673,7 +673,7 @@ where
673 modules[self.module_id].children.insert(name.clone(), res); 673 modules[self.module_id].children.insert(name.clone(), res);
674 let resolution = Resolution { 674 let resolution = Resolution {
675 def: PerNs::types( 675 def: PerNs::types(
676 ModuleId { krate: self.def_collector.def_map.krate, module_id: res }.into(), 676 ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(),
677 ), 677 ),
678 import: None, 678 import: None,
679 }; 679 };
@@ -682,8 +682,7 @@ where
682 } 682 }
683 683
684 fn define_def(&mut self, def: &raw::DefData) { 684 fn define_def(&mut self, def: &raw::DefData) {
685 let module = 685 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
686 ModuleId { krate: self.def_collector.def_map.krate, module_id: self.module_id };
687 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); 686 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
688 687
689 let name = def.name.clone(); 688 let name = def.name.clone();
@@ -698,14 +697,12 @@ where
698 PerNs::values(def.into()) 697 PerNs::values(def.into())
699 } 698 }
700 raw::DefKind::Struct(ast_id) => { 699 raw::DefKind::Struct(ast_id) => {
701 let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); 700 let id = StructId::from_ast_id(ctx, ast_id).into();
702 let s = StructId(id).into(); 701 PerNs::both(id, id)
703 PerNs::both(s, s)
704 } 702 }
705 raw::DefKind::Union(ast_id) => { 703 raw::DefKind::Union(ast_id) => {
706 let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); 704 let id = UnionId::from_ast_id(ctx, ast_id).into();
707 let u = UnionId(id).into(); 705 PerNs::both(id, id)
708 PerNs::both(u, u)
709 } 706 }
710 raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), 707 raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()),
711 raw::DefKind::Const(ast_id) => { 708 raw::DefKind::Const(ast_id) => {
@@ -775,8 +772,7 @@ where
775 if let Some(macro_def) = mac.path.as_ident().and_then(|name| { 772 if let Some(macro_def) = mac.path.as_ident().and_then(|name| {
776 self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) 773 self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name)
777 }) { 774 }) {
778 let macro_call_id = 775 let macro_call_id = macro_def.as_call_id(self.def_collector.db, ast_id);
779 self.def_collector.db.intern_macro(MacroCallLoc { def: macro_def, ast_id });
780 776
781 self.def_collector.collect_macro_expansion(self.module_id, macro_call_id, macro_def); 777 self.def_collector.collect_macro_expansion(self.module_id, macro_call_id, macro_def);
782 return; 778 return;