From 4772cb6b301917820eff62d36e2d6ec359420df3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 22 Jun 2021 20:56:52 +0300 Subject: minor: clarify naming --- crates/hir_def/src/item_scope.rs | 14 +++++++++----- crates/hir_def/src/nameres/collector.rs | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index 567ae5660..1b7cb7c8b 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -30,12 +30,16 @@ pub struct PerNsGlobImports { #[derive(Debug, Default, PartialEq, Eq)] pub struct ItemScope { + /// Defs visible in this scope. This includes `declarations`, but also + /// imports. types: FxHashMap, values: FxHashMap, macros: FxHashMap, unresolved: FxHashSet, - defs: Vec, + /// The defs declared in this scope. Each def has a single scope where it is + /// declared. + declarations: Vec, impls: Vec, unnamed_consts: Vec, /// Traits imported via `use Trait as _;`. @@ -89,7 +93,7 @@ impl ItemScope { } pub fn declarations(&self) -> impl Iterator + '_ { - self.defs.iter().copied() + self.declarations.iter().copied() } pub fn impls(&self) -> impl Iterator + ExactSizeIterator + '_ { @@ -150,8 +154,8 @@ impl ItemScope { .chain(self.unnamed_trait_imports.keys().copied()) } - pub(crate) fn define_def(&mut self, def: ModuleDefId) { - self.defs.push(def) + pub(crate) fn declare(&mut self, def: ModuleDefId) { + self.declarations.push(def) } pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option { @@ -311,7 +315,7 @@ impl ItemScope { values, macros, unresolved, - defs, + declarations: defs, impls, unnamed_consts, unnamed_trait_imports, diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 927a7b6e8..634e02205 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1506,7 +1506,7 @@ impl ModCollector<'_, '_> { } if let Some(DefData { id, name, visibility, has_constructor }) = def { - self.def_collector.def_map.modules[self.module_id].scope.define_def(id); + self.def_collector.def_map.modules[self.module_id].scope.declare(id); let vis = self .def_collector .def_map @@ -1627,7 +1627,7 @@ impl ModCollector<'_, '_> { modules[self.module_id].children.insert(name.clone(), res); let module = self.def_collector.def_map.module_id(res); let def: ModuleDefId = module.into(); - self.def_collector.def_map.modules[self.module_id].scope.define_def(def); + self.def_collector.def_map.modules[self.module_id].scope.declare(def); self.def_collector.update( self.module_id, &[(Some(name), PerNs::from_def(def, vis, false))], -- cgit v1.2.3