Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/collector.rs')
| -rw-r--r-- | crates/hir-def/src/nameres/collector.rs | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 06542b4b1e..97481ea7df 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -51,11 +51,11 @@ use crate::{ per_ns::PerNs, tt, visibility::{RawVisibility, Visibility}, - AdtId, AstId, AstIdWithPath, ConstLoc, EnumLoc, EnumVariantId, ExternBlockLoc, FunctionId, - FunctionLoc, ImplLoc, Intern, ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, - MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, - ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, - UnresolvedMacro, + AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId, + ExternBlockLoc, FunctionId, FunctionLoc, ImplLoc, Intern, ItemContainerId, LocalModuleId, + Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, ModuleDefId, + ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc, TraitLoc, + TypeAliasLoc, UnionLoc, UnresolvedMacro, }; static GLOB_RECURSION_LIMIT: Limit = Limit::new(100); @@ -274,8 +274,6 @@ impl DefCollector<'_> { let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; let item_tree = self.db.file_item_tree(file_id.into()); - let module_id = DefMap::ROOT; - let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate); let crate_data = Arc::get_mut(&mut self.def_map.data).unwrap(); @@ -285,10 +283,9 @@ impl DefCollector<'_> { for (name, dep) in &self.deps { if dep.is_prelude() { - crate_data.extern_prelude.insert( - name.clone(), - ModuleId { krate: dep.crate_id, block: None, local_id: DefMap::ROOT }, - ); + crate_data + .extern_prelude + .insert(name.clone(), CrateRootModuleId { krate: dep.crate_id }); } } @@ -374,7 +371,7 @@ impl DefCollector<'_> { ModCollector { def_collector: self, macro_depth: 0, - module_id, + module_id: DefMap::ROOT, tree_id: TreeId::new(file_id.into(), None), item_tree: &item_tree, mod_dir: ModDir::root(), @@ -384,8 +381,6 @@ impl DefCollector<'_> { fn seed_with_inner(&mut self, tree_id: TreeId) { let item_tree = tree_id.item_tree(self.db); - let module_id = DefMap::ROOT; - let is_cfg_enabled = item_tree .top_level_attrs(self.db, self.def_map.krate) .cfg() @@ -394,7 +389,7 @@ impl DefCollector<'_> { ModCollector { def_collector: self, macro_depth: 0, - module_id, + module_id: DefMap::ROOT, tree_id, item_tree: &item_tree, mod_dir: ModDir::root(), @@ -604,8 +599,6 @@ impl DefCollector<'_> { if self.def_map.block.is_some() { return; } - let crate_root = self.def_map.module_id(DefMap::ROOT); - let kind = def.kind.to_basedb_kind(); let (expander, kind) = match self.proc_macros.as_ref().map(|it| it.iter().find(|(n, _)| n == &def.name)) { @@ -614,7 +607,8 @@ impl DefCollector<'_> { }; let proc_macro_id = - ProcMacroLoc { container: crate_root, id, expander, kind }.intern(self.db); + ProcMacroLoc { container: self.def_map.crate_root(), id, expander, kind } + .intern(self.db); self.define_proc_macro(def.name.clone(), proc_macro_id); let crate_data = Arc::get_mut(&mut self.def_map.data).unwrap(); if let ProcMacroKind::CustomDerive { helpers } = def.kind { @@ -831,16 +825,12 @@ impl DefCollector<'_> { } } - fn resolve_extern_crate(&self, name: &Name) -> Option<ModuleId> { + fn resolve_extern_crate(&self, name: &Name) -> Option<CrateRootModuleId> { if *name == name!(self) { cov_mark::hit!(extern_crate_self_as); Some(self.def_map.crate_root()) } else { - self.deps.get(name).map(|dep| ModuleId { - krate: dep.crate_id, - block: None, - local_id: DefMap::ROOT, - }) + self.deps.get(name).map(|dep| CrateRootModuleId { krate: dep.crate_id }) } } @@ -883,10 +873,12 @@ impl DefCollector<'_> { { if let (Some(ModuleDefId::ModuleId(def)), Some(name)) = (def.take_types(), name) { - Arc::get_mut(&mut self.def_map.data) - .unwrap() - .extern_prelude - .insert(name.clone(), def); + if let Ok(def) = def.try_into() { + Arc::get_mut(&mut self.def_map.data) + .unwrap() + .extern_prelude + .insert(name.clone(), def); + } } } @@ -1791,13 +1783,11 @@ impl ModCollector<'_, '_> { let target_crate = match self.def_collector.resolve_extern_crate(&self.item_tree[extern_crate].name) { - Some(m) => { - if m == self.def_collector.def_map.module_id(self.module_id) { - cov_mark::hit!(ignore_macro_use_extern_crate_self); - return; - } - m.krate + Some(m) if m.krate == self.def_collector.def_map.krate => { + cov_mark::hit!(ignore_macro_use_extern_crate_self); + return; } + Some(m) => m.krate, None => return, }; |