diff options
Diffstat (limited to 'crates/ra_hir/src/nameres/per_ns.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/per_ns.rs | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/crates/ra_hir/src/nameres/per_ns.rs b/crates/ra_hir/src/nameres/per_ns.rs deleted file mode 100644 index 0da6789de..000000000 --- a/crates/ra_hir/src/nameres/per_ns.rs +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use crate::{MacroDef, ModuleDef}; | ||
4 | |||
5 | #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
6 | pub enum Namespace { | ||
7 | Types, | ||
8 | Values, | ||
9 | // Note that only type inference uses this enum, and it doesn't care about macros. | ||
10 | // Macro, | ||
11 | } | ||
12 | |||
13 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
14 | pub struct PerNs { | ||
15 | pub types: Option<ModuleDef>, | ||
16 | pub values: Option<ModuleDef>, | ||
17 | /// Since macros has different type, many methods simply ignore it. | ||
18 | /// We can only use special method like `get_macros` to access it. | ||
19 | pub macros: Option<MacroDef>, | ||
20 | } | ||
21 | |||
22 | impl Default for PerNs { | ||
23 | fn default() -> Self { | ||
24 | PerNs { types: None, values: None, macros: None } | ||
25 | } | ||
26 | } | ||
27 | |||
28 | impl PerNs { | ||
29 | pub fn none() -> PerNs { | ||
30 | PerNs { types: None, values: None, macros: None } | ||
31 | } | ||
32 | |||
33 | pub fn values(t: ModuleDef) -> PerNs { | ||
34 | PerNs { types: None, values: Some(t), macros: None } | ||
35 | } | ||
36 | |||
37 | pub fn types(t: ModuleDef) -> PerNs { | ||
38 | PerNs { types: Some(t), values: None, macros: None } | ||
39 | } | ||
40 | |||
41 | pub fn both(types: ModuleDef, values: ModuleDef) -> PerNs { | ||
42 | PerNs { types: Some(types), values: Some(values), macros: None } | ||
43 | } | ||
44 | |||
45 | pub fn macros(macro_: MacroDef) -> PerNs { | ||
46 | PerNs { types: None, values: None, macros: Some(macro_) } | ||
47 | } | ||
48 | |||
49 | pub fn is_none(&self) -> bool { | ||
50 | self.types.is_none() && self.values.is_none() && self.macros.is_none() | ||
51 | } | ||
52 | |||
53 | pub fn is_all(&self) -> bool { | ||
54 | self.types.is_some() && self.values.is_some() && self.macros.is_some() | ||
55 | } | ||
56 | |||
57 | pub fn take_types(self) -> Option<ModuleDef> { | ||
58 | self.types | ||
59 | } | ||
60 | |||
61 | pub fn take_values(self) -> Option<ModuleDef> { | ||
62 | self.values | ||
63 | } | ||
64 | |||
65 | pub fn get_macros(&self) -> Option<MacroDef> { | ||
66 | self.macros | ||
67 | } | ||
68 | |||
69 | pub fn only_macros(&self) -> PerNs { | ||
70 | PerNs { types: None, values: None, macros: self.macros } | ||
71 | } | ||
72 | |||
73 | pub fn or(self, other: PerNs) -> PerNs { | ||
74 | PerNs { | ||
75 | types: self.types.or(other.types), | ||
76 | values: self.values.or(other.values), | ||
77 | macros: self.macros.or(other.macros), | ||
78 | } | ||
79 | } | ||
80 | } | ||