diff options
author | Paul Daniel Faria <[email protected]> | 2020-06-25 17:42:12 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-06-25 17:42:12 +0100 |
commit | de9e964e4ac21897bd48adbe37f379d74422919f (patch) | |
tree | 75749d75444e360b89b3161623934e2f255ff643 /crates/ra_hir_def/src/per_ns.rs | |
parent | 0b657ddbfe9754afce9811c70a4e61e4ea9efeaf (diff) |
Track import type outside of , use enum rather than bool to improve readability
Diffstat (limited to 'crates/ra_hir_def/src/per_ns.rs')
-rw-r--r-- | crates/ra_hir_def/src/per_ns.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs index e5cbca71d..74665c588 100644 --- a/crates/ra_hir_def/src/per_ns.rs +++ b/crates/ra_hir_def/src/per_ns.rs | |||
@@ -9,7 +9,6 @@ use crate::{item_scope::ItemInNs, visibility::Visibility, ModuleDefId}; | |||
9 | 9 | ||
10 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 10 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
11 | pub struct PerNs { | 11 | pub struct PerNs { |
12 | pub from_glob: bool, | ||
13 | pub types: Option<(ModuleDefId, Visibility)>, | 12 | pub types: Option<(ModuleDefId, Visibility)>, |
14 | pub values: Option<(ModuleDefId, Visibility)>, | 13 | pub values: Option<(ModuleDefId, Visibility)>, |
15 | pub macros: Option<(MacroDefId, Visibility)>, | 14 | pub macros: Option<(MacroDefId, Visibility)>, |
@@ -17,29 +16,29 @@ pub struct PerNs { | |||
17 | 16 | ||
18 | impl Default for PerNs { | 17 | impl Default for PerNs { |
19 | fn default() -> Self { | 18 | fn default() -> Self { |
20 | PerNs { from_glob: false, types: None, values: None, macros: None } | 19 | PerNs { types: None, values: None, macros: None } |
21 | } | 20 | } |
22 | } | 21 | } |
23 | 22 | ||
24 | impl PerNs { | 23 | impl PerNs { |
25 | pub fn none() -> PerNs { | 24 | pub fn none() -> PerNs { |
26 | PerNs { from_glob: false, types: None, values: None, macros: None } | 25 | PerNs { types: None, values: None, macros: None } |
27 | } | 26 | } |
28 | 27 | ||
29 | pub fn values(t: ModuleDefId, v: Visibility) -> PerNs { | 28 | pub fn values(t: ModuleDefId, v: Visibility) -> PerNs { |
30 | PerNs { from_glob: false, types: None, values: Some((t, v)), macros: None } | 29 | PerNs { types: None, values: Some((t, v)), macros: None } |
31 | } | 30 | } |
32 | 31 | ||
33 | pub fn types(t: ModuleDefId, v: Visibility) -> PerNs { | 32 | pub fn types(t: ModuleDefId, v: Visibility) -> PerNs { |
34 | PerNs { from_glob: false, types: Some((t, v)), values: None, macros: None } | 33 | PerNs { types: Some((t, v)), values: None, macros: None } |
35 | } | 34 | } |
36 | 35 | ||
37 | pub fn both(types: ModuleDefId, values: ModuleDefId, v: Visibility) -> PerNs { | 36 | pub fn both(types: ModuleDefId, values: ModuleDefId, v: Visibility) -> PerNs { |
38 | PerNs { from_glob: false, types: Some((types, v)), values: Some((values, v)), macros: None } | 37 | PerNs { types: Some((types, v)), values: Some((values, v)), macros: None } |
39 | } | 38 | } |
40 | 39 | ||
41 | pub fn macros(macro_: MacroDefId, v: Visibility) -> PerNs { | 40 | pub fn macros(macro_: MacroDefId, v: Visibility) -> PerNs { |
42 | PerNs { from_glob: false, types: None, values: None, macros: Some((macro_, v)) } | 41 | PerNs { types: None, values: None, macros: Some((macro_, v)) } |
43 | } | 42 | } |
44 | 43 | ||
45 | pub fn is_none(&self) -> bool { | 44 | pub fn is_none(&self) -> bool { |
@@ -64,7 +63,6 @@ impl PerNs { | |||
64 | 63 | ||
65 | pub fn filter_visibility(self, mut f: impl FnMut(Visibility) -> bool) -> PerNs { | 64 | pub fn filter_visibility(self, mut f: impl FnMut(Visibility) -> bool) -> PerNs { |
66 | PerNs { | 65 | PerNs { |
67 | from_glob: self.from_glob, | ||
68 | types: self.types.filter(|(_, v)| f(*v)), | 66 | types: self.types.filter(|(_, v)| f(*v)), |
69 | values: self.values.filter(|(_, v)| f(*v)), | 67 | values: self.values.filter(|(_, v)| f(*v)), |
70 | macros: self.macros.filter(|(_, v)| f(*v)), | 68 | macros: self.macros.filter(|(_, v)| f(*v)), |
@@ -73,7 +71,6 @@ impl PerNs { | |||
73 | 71 | ||
74 | pub fn with_visibility(self, vis: Visibility) -> PerNs { | 72 | pub fn with_visibility(self, vis: Visibility) -> PerNs { |
75 | PerNs { | 73 | PerNs { |
76 | from_glob: self.from_glob, | ||
77 | types: self.types.map(|(it, _)| (it, vis)), | 74 | types: self.types.map(|(it, _)| (it, vis)), |
78 | values: self.values.map(|(it, _)| (it, vis)), | 75 | values: self.values.map(|(it, _)| (it, vis)), |
79 | macros: self.macros.map(|(it, _)| (it, vis)), | 76 | macros: self.macros.map(|(it, _)| (it, vis)), |
@@ -82,7 +79,6 @@ impl PerNs { | |||
82 | 79 | ||
83 | pub fn or(self, other: PerNs) -> PerNs { | 80 | pub fn or(self, other: PerNs) -> PerNs { |
84 | PerNs { | 81 | PerNs { |
85 | from_glob: self.from_glob, | ||
86 | types: self.types.or(other.types), | 82 | types: self.types.or(other.types), |
87 | values: self.values.or(other.values), | 83 | values: self.values.or(other.values), |
88 | macros: self.macros.or(other.macros), | 84 | macros: self.macros.or(other.macros), |
@@ -96,8 +92,4 @@ impl PerNs { | |||
96 | .chain(self.values.map(|it| ItemInNs::Values(it.0)).into_iter()) | 92 | .chain(self.values.map(|it| ItemInNs::Values(it.0)).into_iter()) |
97 | .chain(self.macros.map(|it| ItemInNs::Macros(it.0)).into_iter()) | 93 | .chain(self.macros.map(|it| ItemInNs::Macros(it.0)).into_iter()) |
98 | } | 94 | } |
99 | |||
100 | pub fn from_glob(self, from_glob: bool) -> PerNs { | ||
101 | PerNs { from_glob, ..self } | ||
102 | } | ||
103 | } | 95 | } |