aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs3
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs3
-rw-r--r--crates/ra_hir_def/src/nameres/per_ns.rs74
3 files changed, 4 insertions, 76 deletions
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::{
16 db::DefDatabase, 16 db::DefDatabase,
17 nameres::{ 17 nameres::{
18 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, 18 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
19 per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode, 19 raw, CrateDefMap, ModuleData, Resolution, ResolveMode,
20 }, 20 },
21 path::{Path, PathKind}, 21 path::{Path, PathKind},
22 per_ns::PerNs,
22 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, 23 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId,
23 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, 24 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId,
24 StructOrUnionId, TraitId, TypeAliasLoc, UnionId, 25 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;
16 16
17use crate::{ 17use crate::{
18 db::DefDatabase, 18 db::DefDatabase,
19 nameres::{per_ns::PerNs, CrateDefMap}, 19 nameres::CrateDefMap,
20 path::{Path, PathKind}, 20 path::{Path, PathKind},
21 per_ns::PerNs,
21 AdtId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, 22 AdtId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
22}; 23};
23 24
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 @@
1//! FIXME: write short doc here
2
3use hir_expand::MacroDefId;
4
5use crate::ModuleDefId;
6
7#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8pub struct PerNs {
9 pub types: Option<ModuleDefId>,
10 pub values: Option<ModuleDefId>,
11 /// Since macros has different type, many methods simply ignore it.
12 /// We can only use special method like `get_macros` to access it.
13 pub macros: Option<MacroDefId>,
14}
15
16impl Default for PerNs {
17 fn default() -> Self {
18 PerNs { types: None, values: None, macros: None }
19 }
20}
21
22impl PerNs {
23 pub fn none() -> PerNs {
24 PerNs { types: None, values: None, macros: None }
25 }
26
27 pub fn values(t: ModuleDefId) -> PerNs {
28 PerNs { types: None, values: Some(t), macros: None }
29 }
30
31 pub fn types(t: ModuleDefId) -> PerNs {
32 PerNs { types: Some(t), values: None, macros: None }
33 }
34
35 pub fn both(types: ModuleDefId, values: ModuleDefId) -> PerNs {
36 PerNs { types: Some(types), values: Some(values), macros: None }
37 }
38
39 pub fn macros(macro_: MacroDefId) -> PerNs {
40 PerNs { types: None, values: None, macros: Some(macro_) }
41 }
42
43 pub fn is_none(&self) -> bool {
44 self.types.is_none() && self.values.is_none() && self.macros.is_none()
45 }
46
47 pub fn is_all(&self) -> bool {
48 self.types.is_some() && self.values.is_some() && self.macros.is_some()
49 }
50
51 pub fn take_types(self) -> Option<ModuleDefId> {
52 self.types
53 }
54
55 pub fn take_values(self) -> Option<ModuleDefId> {
56 self.values
57 }
58
59 pub fn get_macros(&self) -> Option<MacroDefId> {
60 self.macros
61 }
62
63 pub fn only_macros(&self) -> PerNs {
64 PerNs { types: None, values: None, macros: self.macros }
65 }
66
67 pub fn or(self, other: PerNs) -> PerNs {
68 PerNs {
69 types: self.types.or(other.types),
70 values: self.values.or(other.values),
71 macros: self.macros.or(other.macros),
72 }
73 }
74}