aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/item_scope.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/item_scope.rs')
-rw-r--r--crates/ra_hir_def/src/item_scope.rs35
1 files changed, 35 insertions, 0 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.
49impl ItemScope { 49impl 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())