From 973b5cf7e20842711d59a810b268796b26241382 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 15:04:33 +0100 Subject: Revert "Merge #2629" This reverts commit cdc9d682b066b110e0a44e5f8f1c574b38c16ba9, reversing changes made to 90ef070db3dce0a7acb9cd11d0b0d72de13c9d79. --- crates/ra_hir_def/src/nameres/collector.rs | 46 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'crates/ra_hir_def/src/nameres/collector.rs') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 9419461a8..45199fa11 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -26,7 +26,8 @@ use crate::{ path::{ModPath, PathKind}, per_ns::PerNs, AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, - LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, + LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, + TypeAliasLoc, UnionLoc, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { @@ -92,7 +93,7 @@ impl PartialResolvedImport { #[derive(Clone, Debug, Eq, PartialEq)] struct ImportDirective { module_id: LocalModuleId, - import_id: raw::LocalImportId, + import_id: LocalImportId, import: raw::ImportData, status: PartialResolvedImport, } @@ -109,7 +110,7 @@ struct MacroDirective { struct DefCollector<'a, DB> { db: &'a DB, def_map: CrateDefMap, - glob_imports: FxHashMap>, + glob_imports: FxHashMap>, unresolved_imports: Vec, resolved_imports: Vec, unexpanded_macros: Vec, @@ -217,7 +218,8 @@ where if export { self.update( self.def_map.root, - &[(name, Resolution { def: PerNs::macros(macro_), declaration: false })], + None, + &[(name, Resolution { def: PerNs::macros(macro_), import: None })], ); } } @@ -372,7 +374,7 @@ where // Module scoped macros is included let items = scope.collect_resolutions(); - self.update(module_id, &items); + self.update(module_id, Some(import_id), &items); } else { // glob import from same crate => we do an initial // import, and then need to propagate any further @@ -382,7 +384,7 @@ where // Module scoped macros is included let items = scope.collect_resolutions(); - self.update(module_id, &items); + self.update(module_id, Some(import_id), &items); // record the glob import in case we add further items let glob = self.glob_imports.entry(m.local_id).or_default(); if !glob.iter().any(|it| *it == (module_id, import_id)) { @@ -402,12 +404,12 @@ where let variant = EnumVariantId { parent: e, local_id }; let res = Resolution { def: PerNs::both(variant.into(), variant.into()), - declaration: false, + import: Some(import_id), }; (name, res) }) .collect::>(); - self.update(module_id, &resolutions); + self.update(module_id, Some(import_id), &resolutions); } Some(d) => { log::debug!("glob import {:?} from non-module/enum {:?}", import, d); @@ -429,21 +431,27 @@ where } } - let resolution = Resolution { def, declaration: false }; - self.update(module_id, &[(name, resolution)]); + let resolution = Resolution { def, import: Some(import_id) }; + self.update(module_id, Some(import_id), &[(name, resolution)]); } None => tested_by!(bogus_paths), } } } - fn update(&mut self, module_id: LocalModuleId, resolutions: &[(Name, Resolution)]) { - self.update_recursive(module_id, resolutions, 0) + fn update( + &mut self, + module_id: LocalModuleId, + import: Option, + resolutions: &[(Name, Resolution)], + ) { + self.update_recursive(module_id, import, resolutions, 0) } fn update_recursive( &mut self, module_id: LocalModuleId, + import: Option, resolutions: &[(Name, Resolution)], depth: usize, ) { @@ -454,7 +462,7 @@ where let scope = &mut self.def_map.modules[module_id].scope; let mut changed = false; for (name, res) in resolutions { - changed |= scope.push_res(name.clone(), res, depth == 0 && res.declaration); + changed |= scope.push_res(name.clone(), res, import); } if !changed { @@ -467,9 +475,9 @@ where .flat_map(|v| v.iter()) .cloned() .collect::>(); - for (glob_importing_module, _glob_import) in glob_imports { + for (glob_importing_module, glob_import) in glob_imports { // We pass the glob import so that the tracked import in those modules is that glob import - self.update_recursive(glob_importing_module, resolutions, depth + 1); + self.update_recursive(glob_importing_module, Some(glob_import), resolutions, depth + 1); } } @@ -711,9 +719,9 @@ where def: PerNs::types( ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), ), - declaration: true, + import: None, }; - self.def_collector.update(self.module_id, &[(name, resolution)]); + self.def_collector.update(self.module_id, None, &[(name, resolution)]); res } @@ -783,8 +791,8 @@ where PerNs::types(def.into()) } }; - let resolution = Resolution { def, declaration: true }; - self.def_collector.update(self.module_id, &[(name, resolution)]) + let resolution = Resolution { def, import: None }; + self.def_collector.update(self.module_id, None, &[(name, resolution)]) } fn collect_derives(&mut self, attrs: &Attrs, def: &raw::DefData) { -- cgit v1.2.3