]> git.lizzy.rs Git - rust.git/blobdiff - crates/ra_hir_def/src/item_scope.rs
Move some code to scope
[rust.git] / crates / ra_hir_def / src / item_scope.rs
index 93e579bb0c2e761bb77c5db4c6c629f921cb1024..f4fb768cd3a6803c7c6706d8e21aa50a76511d37 100644 (file)
@@ -47,6 +47,41 @@ pub(crate) enum BuiltinShadowMode {
 /// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
 /// Other methods will only resolve values, types and module scoped macros only.
 impl ItemScope {
+    pub fn push_res(
+        &mut self,
+        name: Name,
+        res: &Resolution,
+        import: Option<LocalImportId>,
+    ) -> bool {
+        let mut changed = false;
+        let existing = self.items.entry(name.clone()).or_default();
+
+        if existing.def.types.is_none() && res.def.types.is_some() {
+            existing.def.types = res.def.types;
+            existing.import = import.or(res.import);
+            changed = true;
+        }
+        if existing.def.values.is_none() && res.def.values.is_some() {
+            existing.def.values = res.def.values;
+            existing.import = import.or(res.import);
+            changed = true;
+        }
+        if existing.def.macros.is_none() && res.def.macros.is_some() {
+            existing.def.macros = res.def.macros;
+            existing.import = import.or(res.import);
+            changed = true;
+        }
+
+        if existing.def.is_none()
+            && res.def.is_none()
+            && existing.import.is_none()
+            && res.import.is_some()
+        {
+            existing.import = res.import;
+        }
+        changed
+    }
+
     pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a {
         //FIXME: shadowing
         self.items.iter().chain(BUILTIN_SCOPE.iter())