diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 35 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 28 |
2 files changed, 37 insertions, 26 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index 93e579bb0..f4fb768cd 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -47,6 +47,41 @@ pub(crate) enum BuiltinShadowMode { | |||
47 | /// Legacy macros can only be accessed through special methods like `get_legacy_macros`. | 47 | /// Legacy macros can only be accessed through special methods like `get_legacy_macros`. |
48 | /// Other methods will only resolve values, types and module scoped macros only. | 48 | /// Other methods will only resolve values, types and module scoped macros only. |
49 | impl ItemScope { | 49 | impl ItemScope { |
50 | pub fn push_res( | ||
51 | &mut self, | ||
52 | name: Name, | ||
53 | res: &Resolution, | ||
54 | import: Option<LocalImportId>, | ||
55 | ) -> bool { | ||
56 | let mut changed = false; | ||
57 | let existing = self.items.entry(name.clone()).or_default(); | ||
58 | |||
59 | if existing.def.types.is_none() && res.def.types.is_some() { | ||
60 | existing.def.types = res.def.types; | ||
61 | existing.import = import.or(res.import); | ||
62 | changed = true; | ||
63 | } | ||
64 | if existing.def.values.is_none() && res.def.values.is_some() { | ||
65 | existing.def.values = res.def.values; | ||
66 | existing.import = import.or(res.import); | ||
67 | changed = true; | ||
68 | } | ||
69 | if existing.def.macros.is_none() && res.def.macros.is_some() { | ||
70 | existing.def.macros = res.def.macros; | ||
71 | existing.import = import.or(res.import); | ||
72 | changed = true; | ||
73 | } | ||
74 | |||
75 | if existing.def.is_none() | ||
76 | && res.def.is_none() | ||
77 | && existing.import.is_none() | ||
78 | && res.import.is_some() | ||
79 | { | ||
80 | existing.import = res.import; | ||
81 | } | ||
82 | changed | ||
83 | } | ||
84 | |||
50 | pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a { | 85 | pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a { |
51 | //FIXME: shadowing | 86 | //FIXME: shadowing |
52 | self.items.iter().chain(BUILTIN_SCOPE.iter()) | 87 | self.items.iter().chain(BUILTIN_SCOPE.iter()) |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 17c7e691e..95c499ec9 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -467,34 +467,10 @@ where | |||
467 | // prevent stack overflows (but this shouldn't be possible) | 467 | // prevent stack overflows (but this shouldn't be possible) |
468 | panic!("infinite recursion in glob imports!"); | 468 | panic!("infinite recursion in glob imports!"); |
469 | } | 469 | } |
470 | let module_items = &mut self.def_map.modules[module_id].scope; | 470 | let scope = &mut self.def_map.modules[module_id].scope; |
471 | let mut changed = false; | 471 | let mut changed = false; |
472 | for (name, res) in resolutions { | 472 | for (name, res) in resolutions { |
473 | let existing = module_items.items.entry(name.clone()).or_default(); | 473 | changed |= scope.push_res(name.clone(), res, import); |
474 | |||
475 | if existing.def.types.is_none() && res.def.types.is_some() { | ||
476 | existing.def.types = res.def.types; | ||
477 | existing.import = import.or(res.import); | ||
478 | changed = true; | ||
479 | } | ||
480 | if existing.def.values.is_none() && res.def.values.is_some() { | ||
481 | existing.def.values = res.def.values; | ||
482 | existing.import = import.or(res.import); | ||
483 | changed = true; | ||
484 | } | ||
485 | if existing.def.macros.is_none() && res.def.macros.is_some() { | ||
486 | existing.def.macros = res.def.macros; | ||
487 | existing.import = import.or(res.import); | ||
488 | changed = true; | ||
489 | } | ||
490 | |||
491 | if existing.def.is_none() | ||
492 | && res.def.is_none() | ||
493 | && existing.import.is_none() | ||
494 | && res.import.is_some() | ||
495 | { | ||
496 | existing.import = res.import; | ||
497 | } | ||
498 | } | 474 | } |
499 | 475 | ||
500 | if !changed { | 476 | if !changed { |