diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-21 14:08:10 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-21 14:08:10 +0000 |
commit | df45f28fedab9b0620ea038849ec8e93c3b4ab26 (patch) | |
tree | 7025977c0333378cd209dc47c1d160c7cdef206a /crates/ra_hir_def/src/nameres/collector.rs | |
parent | a1f4c988e47b7160b11070d18f50657b6fb9014c (diff) | |
parent | 973b5cf7e20842711d59a810b268796b26241382 (diff) |
Merge #2632
2632: Revert "Merge #2629" r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres/collector.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 46 |
1 files changed, 27 insertions, 19 deletions
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::{ | |||
26 | path::{ModPath, PathKind}, | 26 | path::{ModPath, PathKind}, |
27 | per_ns::PerNs, | 27 | per_ns::PerNs, |
28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, | 28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, |
29 | LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, | 29 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, |
30 | TypeAliasLoc, UnionLoc, | ||
30 | }; | 31 | }; |
31 | 32 | ||
32 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 33 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -92,7 +93,7 @@ impl PartialResolvedImport { | |||
92 | #[derive(Clone, Debug, Eq, PartialEq)] | 93 | #[derive(Clone, Debug, Eq, PartialEq)] |
93 | struct ImportDirective { | 94 | struct ImportDirective { |
94 | module_id: LocalModuleId, | 95 | module_id: LocalModuleId, |
95 | import_id: raw::LocalImportId, | 96 | import_id: LocalImportId, |
96 | import: raw::ImportData, | 97 | import: raw::ImportData, |
97 | status: PartialResolvedImport, | 98 | status: PartialResolvedImport, |
98 | } | 99 | } |
@@ -109,7 +110,7 @@ struct MacroDirective { | |||
109 | struct DefCollector<'a, DB> { | 110 | struct DefCollector<'a, DB> { |
110 | db: &'a DB, | 111 | db: &'a DB, |
111 | def_map: CrateDefMap, | 112 | def_map: CrateDefMap, |
112 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, raw::LocalImportId)>>, | 113 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, LocalImportId)>>, |
113 | unresolved_imports: Vec<ImportDirective>, | 114 | unresolved_imports: Vec<ImportDirective>, |
114 | resolved_imports: Vec<ImportDirective>, | 115 | resolved_imports: Vec<ImportDirective>, |
115 | unexpanded_macros: Vec<MacroDirective>, | 116 | unexpanded_macros: Vec<MacroDirective>, |
@@ -217,7 +218,8 @@ where | |||
217 | if export { | 218 | if export { |
218 | self.update( | 219 | self.update( |
219 | self.def_map.root, | 220 | self.def_map.root, |
220 | &[(name, Resolution { def: PerNs::macros(macro_), declaration: false })], | 221 | None, |
222 | &[(name, Resolution { def: PerNs::macros(macro_), import: None })], | ||
221 | ); | 223 | ); |
222 | } | 224 | } |
223 | } | 225 | } |
@@ -372,7 +374,7 @@ where | |||
372 | // Module scoped macros is included | 374 | // Module scoped macros is included |
373 | let items = scope.collect_resolutions(); | 375 | let items = scope.collect_resolutions(); |
374 | 376 | ||
375 | self.update(module_id, &items); | 377 | self.update(module_id, Some(import_id), &items); |
376 | } else { | 378 | } else { |
377 | // glob import from same crate => we do an initial | 379 | // glob import from same crate => we do an initial |
378 | // import, and then need to propagate any further | 380 | // import, and then need to propagate any further |
@@ -382,7 +384,7 @@ where | |||
382 | // Module scoped macros is included | 384 | // Module scoped macros is included |
383 | let items = scope.collect_resolutions(); | 385 | let items = scope.collect_resolutions(); |
384 | 386 | ||
385 | self.update(module_id, &items); | 387 | self.update(module_id, Some(import_id), &items); |
386 | // record the glob import in case we add further items | 388 | // record the glob import in case we add further items |
387 | let glob = self.glob_imports.entry(m.local_id).or_default(); | 389 | let glob = self.glob_imports.entry(m.local_id).or_default(); |
388 | if !glob.iter().any(|it| *it == (module_id, import_id)) { | 390 | if !glob.iter().any(|it| *it == (module_id, import_id)) { |
@@ -402,12 +404,12 @@ where | |||
402 | let variant = EnumVariantId { parent: e, local_id }; | 404 | let variant = EnumVariantId { parent: e, local_id }; |
403 | let res = Resolution { | 405 | let res = Resolution { |
404 | def: PerNs::both(variant.into(), variant.into()), | 406 | def: PerNs::both(variant.into(), variant.into()), |
405 | declaration: false, | 407 | import: Some(import_id), |
406 | }; | 408 | }; |
407 | (name, res) | 409 | (name, res) |
408 | }) | 410 | }) |
409 | .collect::<Vec<_>>(); | 411 | .collect::<Vec<_>>(); |
410 | self.update(module_id, &resolutions); | 412 | self.update(module_id, Some(import_id), &resolutions); |
411 | } | 413 | } |
412 | Some(d) => { | 414 | Some(d) => { |
413 | log::debug!("glob import {:?} from non-module/enum {:?}", import, d); | 415 | log::debug!("glob import {:?} from non-module/enum {:?}", import, d); |
@@ -429,21 +431,27 @@ where | |||
429 | } | 431 | } |
430 | } | 432 | } |
431 | 433 | ||
432 | let resolution = Resolution { def, declaration: false }; | 434 | let resolution = Resolution { def, import: Some(import_id) }; |
433 | self.update(module_id, &[(name, resolution)]); | 435 | self.update(module_id, Some(import_id), &[(name, resolution)]); |
434 | } | 436 | } |
435 | None => tested_by!(bogus_paths), | 437 | None => tested_by!(bogus_paths), |
436 | } | 438 | } |
437 | } | 439 | } |
438 | } | 440 | } |
439 | 441 | ||
440 | fn update(&mut self, module_id: LocalModuleId, resolutions: &[(Name, Resolution)]) { | 442 | fn update( |
441 | self.update_recursive(module_id, resolutions, 0) | 443 | &mut self, |
444 | module_id: LocalModuleId, | ||
445 | import: Option<LocalImportId>, | ||
446 | resolutions: &[(Name, Resolution)], | ||
447 | ) { | ||
448 | self.update_recursive(module_id, import, resolutions, 0) | ||
442 | } | 449 | } |
443 | 450 | ||
444 | fn update_recursive( | 451 | fn update_recursive( |
445 | &mut self, | 452 | &mut self, |
446 | module_id: LocalModuleId, | 453 | module_id: LocalModuleId, |
454 | import: Option<LocalImportId>, | ||
447 | resolutions: &[(Name, Resolution)], | 455 | resolutions: &[(Name, Resolution)], |
448 | depth: usize, | 456 | depth: usize, |
449 | ) { | 457 | ) { |
@@ -454,7 +462,7 @@ where | |||
454 | let scope = &mut self.def_map.modules[module_id].scope; | 462 | let scope = &mut self.def_map.modules[module_id].scope; |
455 | let mut changed = false; | 463 | let mut changed = false; |
456 | for (name, res) in resolutions { | 464 | for (name, res) in resolutions { |
457 | changed |= scope.push_res(name.clone(), res, depth == 0 && res.declaration); | 465 | changed |= scope.push_res(name.clone(), res, import); |
458 | } | 466 | } |
459 | 467 | ||
460 | if !changed { | 468 | if !changed { |
@@ -467,9 +475,9 @@ where | |||
467 | .flat_map(|v| v.iter()) | 475 | .flat_map(|v| v.iter()) |
468 | .cloned() | 476 | .cloned() |
469 | .collect::<Vec<_>>(); | 477 | .collect::<Vec<_>>(); |
470 | for (glob_importing_module, _glob_import) in glob_imports { | 478 | for (glob_importing_module, glob_import) in glob_imports { |
471 | // We pass the glob import so that the tracked import in those modules is that glob import | 479 | // We pass the glob import so that the tracked import in those modules is that glob import |
472 | self.update_recursive(glob_importing_module, resolutions, depth + 1); | 480 | self.update_recursive(glob_importing_module, Some(glob_import), resolutions, depth + 1); |
473 | } | 481 | } |
474 | } | 482 | } |
475 | 483 | ||
@@ -711,9 +719,9 @@ where | |||
711 | def: PerNs::types( | 719 | def: PerNs::types( |
712 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), | 720 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), |
713 | ), | 721 | ), |
714 | declaration: true, | 722 | import: None, |
715 | }; | 723 | }; |
716 | self.def_collector.update(self.module_id, &[(name, resolution)]); | 724 | self.def_collector.update(self.module_id, None, &[(name, resolution)]); |
717 | res | 725 | res |
718 | } | 726 | } |
719 | 727 | ||
@@ -783,8 +791,8 @@ where | |||
783 | PerNs::types(def.into()) | 791 | PerNs::types(def.into()) |
784 | } | 792 | } |
785 | }; | 793 | }; |
786 | let resolution = Resolution { def, declaration: true }; | 794 | let resolution = Resolution { def, import: None }; |
787 | self.def_collector.update(self.module_id, &[(name, resolution)]) | 795 | self.def_collector.update(self.module_id, None, &[(name, resolution)]) |
788 | } | 796 | } |
789 | 797 | ||
790 | fn collect_derives(&mut self, attrs: &Attrs, def: &raw::DefData) { | 798 | fn collect_derives(&mut self, attrs: &Attrs, def: &raw::DefData) { |