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_def/src/per_ns.rs | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 crates/ra_hir_def/src/per_ns.rs (limited to 'crates/ra_hir_def/src/per_ns.rs') 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), + } + } +} -- cgit v1.2.3 From 99af523b68d3056c0ee355821b9b8f3c6fb5f504 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 17:00:10 +0300 Subject: Cleanup --- crates/ra_hir_def/src/per_ns.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'crates/ra_hir_def/src/per_ns.rs') diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs index 717ed1ef9..06ef6c9fc 100644 --- a/crates/ra_hir_def/src/per_ns.rs +++ b/crates/ra_hir_def/src/per_ns.rs @@ -44,10 +44,6 @@ impl PerNs { 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 } @@ -56,14 +52,10 @@ impl PerNs { self.values } - pub fn get_macros(&self) -> Option { + pub fn take_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), -- cgit v1.2.3 From d87c16bea60f4972b0adf4dd69bbb9abcfca12d6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 21:00:50 +0300 Subject: hir_def is fully doc'ed! --- crates/ra_hir_def/src/per_ns.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/per_ns.rs') diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs index 06ef6c9fc..00e866bf9 100644 --- a/crates/ra_hir_def/src/per_ns.rs +++ b/crates/ra_hir_def/src/per_ns.rs @@ -1,4 +1,7 @@ -//! FIXME: write short doc here +//! In rust, it is possible to have a value, a type and a macro with the same +//! name without conflicts. +//! +//! `PerNs` (per namespace) captures this. use hir_expand::MacroDefId; -- cgit v1.2.3