From 6bdd5fa461ba0f3f3697339ffb560c577e3b0cc6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 16:53:16 +0300 Subject: Privatise nameres --- crates/ra_hir/src/code_model.rs | 2 +- crates/ra_hir_def/src/lib.rs | 5 +- crates/ra_hir_def/src/nameres.rs | 6 +- crates/ra_hir_def/src/nameres/collector.rs | 3 +- crates/ra_hir_def/src/nameres/path_resolution.rs | 3 +- crates/ra_hir_def/src/nameres/per_ns.rs | 74 ------------------------ crates/ra_hir_def/src/per_ns.rs | 74 ++++++++++++++++++++++++ crates/ra_hir_def/src/resolver.rs | 3 +- 8 files changed, 86 insertions(+), 84 deletions(-) delete mode 100644 crates/ra_hir_def/src/nameres/per_ns.rs create mode 100644 crates/ra_hir_def/src/per_ns.rs diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 2442fb6a5..cd178bf88 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -9,7 +9,7 @@ use hir_def::{ body::scope::ExprScopes, builtin_type::BuiltinType, docs::Documentation, - nameres::per_ns::PerNs, + per_ns::PerNs, resolver::{HasResolver, TypeNs}, type_ref::TypeRef, ContainerId, HasModule, ImplId, LocalEnumVariantId, LocalImportId, LocalModuleId, diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 2cfe68701..11ae9cdc0 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -21,17 +21,16 @@ pub mod resolver; pub mod data; pub mod lang_item; pub mod docs; +pub mod per_ns; mod trace; +mod nameres; #[cfg(test)] mod test_db; #[cfg(test)] mod marks; -// FIXME: this should be private -pub mod nameres; - use std::hash::{Hash, Hasher}; use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source}; diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index d82356bbd..3b2e99647 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -47,8 +47,7 @@ //! path and, upon success, we run macro expansion and "collect module" phase on //! the result -pub mod raw; -pub mod per_ns; +pub(crate) mod raw; mod collector; mod mod_resolution; mod path_resolution; @@ -72,8 +71,9 @@ use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ builtin_type::BuiltinType, db::DefDatabase, - nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs}, + nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode}, path::Path, + per_ns::PerNs, AstId, FunctionId, ImplId, LocalImportId, LocalModuleId, ModuleDefId, ModuleId, TraitId, }; diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 5f7697f63..b02364e86 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -16,9 +16,10 @@ use crate::{ db::DefDatabase, nameres::{ diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, - per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode, + raw, CrateDefMap, ModuleData, Resolution, ResolveMode, }, path::{Path, PathKind}, + per_ns::PerNs, AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, StructOrUnionId, TraitId, TypeAliasLoc, UnionId, diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 93b441f96..9455f22bb 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs @@ -16,8 +16,9 @@ use test_utils::tested_by; use crate::{ db::DefDatabase, - nameres::{per_ns::PerNs, CrateDefMap}, + nameres::CrateDefMap, path::{Path, PathKind}, + per_ns::PerNs, AdtId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, }; diff --git a/crates/ra_hir_def/src/nameres/per_ns.rs b/crates/ra_hir_def/src/nameres/per_ns.rs deleted file mode 100644 index 717ed1ef9..000000000 --- a/crates/ra_hir_def/src/nameres/per_ns.rs +++ /dev/null @@ -1,74 +0,0 @@ -//! FIXME: write short doc here - -use hir_expand::MacroDefId; - -use crate::ModuleDefId; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct PerNs { - pub types: Option, - pub values: Option, - /// Since macros has different type, many methods simply ignore it. - /// We can only use special method like `get_macros` to access it. - pub macros: Option, -} - -impl Default for PerNs { - fn default() -> Self { - PerNs { types: None, values: None, macros: None } - } -} - -impl PerNs { - pub fn none() -> PerNs { - PerNs { types: None, values: None, macros: None } - } - - pub fn values(t: ModuleDefId) -> PerNs { - PerNs { types: None, values: Some(t), macros: None } - } - - pub fn types(t: ModuleDefId) -> PerNs { - PerNs { types: Some(t), values: None, macros: None } - } - - pub fn both(types: ModuleDefId, values: ModuleDefId) -> PerNs { - PerNs { types: Some(types), values: Some(values), macros: None } - } - - pub fn macros(macro_: MacroDefId) -> PerNs { - PerNs { types: None, values: None, macros: Some(macro_) } - } - - pub fn is_none(&self) -> bool { - self.types.is_none() && self.values.is_none() && self.macros.is_none() - } - - pub fn is_all(&self) -> bool { - self.types.is_some() && self.values.is_some() && self.macros.is_some() - } - - pub fn take_types(self) -> Option { - self.types - } - - pub fn take_values(self) -> Option { - self.values - } - - pub fn get_macros(&self) -> Option { - self.macros - } - - pub fn only_macros(&self) -> PerNs { - PerNs { types: None, values: None, macros: self.macros } - } - - pub fn or(self, other: PerNs) -> PerNs { - PerNs { - types: self.types.or(other.types), - values: self.values.or(other.values), - macros: self.macros.or(other.macros), - } - } -} diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs new file mode 100644 index 000000000..717ed1ef9 --- /dev/null +++ b/crates/ra_hir_def/src/per_ns.rs @@ -0,0 +1,74 @@ +//! FIXME: write short doc here + +use hir_expand::MacroDefId; + +use crate::ModuleDefId; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct PerNs { + pub types: Option, + pub values: Option, + /// Since macros has different type, many methods simply ignore it. + /// We can only use special method like `get_macros` to access it. + pub macros: Option, +} + +impl Default for PerNs { + fn default() -> Self { + PerNs { types: None, values: None, macros: None } + } +} + +impl PerNs { + pub fn none() -> PerNs { + PerNs { types: None, values: None, macros: None } + } + + pub fn values(t: ModuleDefId) -> PerNs { + PerNs { types: None, values: Some(t), macros: None } + } + + pub fn types(t: ModuleDefId) -> PerNs { + PerNs { types: Some(t), values: None, macros: None } + } + + pub fn both(types: ModuleDefId, values: ModuleDefId) -> PerNs { + PerNs { types: Some(types), values: Some(values), macros: None } + } + + pub fn macros(macro_: MacroDefId) -> PerNs { + PerNs { types: None, values: None, macros: Some(macro_) } + } + + pub fn is_none(&self) -> bool { + self.types.is_none() && self.values.is_none() && self.macros.is_none() + } + + pub fn is_all(&self) -> bool { + self.types.is_some() && self.values.is_some() && self.macros.is_some() + } + + pub fn take_types(self) -> Option { + self.types + } + + pub fn take_values(self) -> Option { + self.values + } + + pub fn get_macros(&self) -> Option { + self.macros + } + + pub fn only_macros(&self) -> PerNs { + PerNs { types: None, values: None, macros: self.macros } + } + + pub fn or(self, other: PerNs) -> PerNs { + PerNs { + types: self.types.or(other.types), + values: self.values.or(other.values), + macros: self.macros.or(other.macros), + } + } +} diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index e64face7e..b56de44dd 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -14,8 +14,9 @@ use crate::{ db::DefDatabase, expr::{ExprId, PatId}, generics::GenericParams, - nameres::{per_ns::PerNs, CrateDefMap}, + nameres::CrateDefMap, path::{Path, PathKind}, + per_ns::PerNs, AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, -- cgit v1.2.3