]> git.lizzy.rs Git - rust.git/commitdiff
Remove import from resolution
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 21 Dec 2019 16:22:48 +0000 (17:22 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 21 Dec 2019 16:26:28 +0000 (17:26 +0100)
crates/ra_hir_def/src/item_scope.rs
crates/ra_hir_def/src/nameres/collector.rs

index ad104bb3d718a2070fa34fd6a5d2b30e41776d86..8b70e13c46a9cfc134ea42d526734386c8c251c0 100644 (file)
@@ -30,7 +30,7 @@ pub struct ItemScope {
     BuiltinType::ALL
         .iter()
         .map(|(name, ty)| {
-            (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None })
+            (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: false })
         })
         .collect()
 });
@@ -54,7 +54,7 @@ pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)>
 
     pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ {
         self.entries()
-            .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None })
+            .filter_map(|(_name, res)| if !res.import { Some(res.def) } else { None })
             .flat_map(|per_ns| {
                 per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter())
             })
@@ -123,25 +123,21 @@ pub(crate) fn push_res(
 
         if existing.def.types.is_none() && res.def.types.is_some() {
             existing.def.types = res.def.types;
-            existing.import = import.or(res.import);
+            existing.import = import.is_some() || 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);
+            existing.import = import.is_some() || 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);
+            existing.import = import.is_some() || res.import;
             changed = true;
         }
 
-        if existing.def.is_none()
-            && res.def.is_none()
-            && existing.import.is_none()
-            && res.import.is_some()
-        {
+        if existing.def.is_none() && res.def.is_none() && !existing.import && res.import {
             existing.import = res.import;
         }
         changed
@@ -160,6 +156,5 @@ pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> {
 pub struct Resolution {
     /// None for unresolved
     pub def: PerNs,
-    /// ident by which this is imported into local scope.
-    pub(crate) import: Option<LocalImportId>,
+    pub(crate) import: bool,
 }
index 45199fa11496d05951bd0dd761f4479413903a5a..c2db5472b4d89d68543f07d4ebe0501049c1a8d0 100644 (file)
@@ -219,7 +219,7 @@ fn define_macro(
             self.update(
                 self.def_map.root,
                 None,
-                &[(name, Resolution { def: PerNs::macros(macro_), import: None })],
+                &[(name, Resolution { def: PerNs::macros(macro_), import: false })],
             );
         }
     }
@@ -404,7 +404,7 @@ fn record_resolved_import(&mut self, directive: &ImportDirective) {
                             let variant = EnumVariantId { parent: e, local_id };
                             let res = Resolution {
                                 def: PerNs::both(variant.into(), variant.into()),
-                                import: Some(import_id),
+                                import: true,
                             };
                             (name, res)
                         })
@@ -431,7 +431,7 @@ fn record_resolved_import(&mut self, directive: &ImportDirective) {
                         }
                     }
 
-                    let resolution = Resolution { def, import: Some(import_id) };
+                    let resolution = Resolution { def, import: true };
                     self.update(module_id, Some(import_id), &[(name, resolution)]);
                 }
                 None => tested_by!(bogus_paths),
@@ -719,7 +719,7 @@ fn push_child_module(
             def: PerNs::types(
                 ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(),
             ),
-            import: None,
+            import: false,
         };
         self.def_collector.update(self.module_id, None, &[(name, resolution)]);
         res
@@ -791,7 +791,7 @@ fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) {
                 PerNs::types(def.into())
             }
         };
-        let resolution = Resolution { def, import: None };
+        let resolution = Resolution { def, import: false };
         self.def_collector.update(self.module_id, None, &[(name, resolution)])
     }