diff options
author | Aleksey Kladov <[email protected]> | 2019-11-22 11:12:45 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-22 11:12:45 +0000 |
commit | f4b1fb1554b639374adeffa50d4719f834a0d475 (patch) | |
tree | ce2e04a611618bdd47bd81b6f15fcdf324308913 /crates/ra_db | |
parent | 0861ac061ef5c8b5d7ed2a95ef30f4a17710229d (diff) |
Reorder
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/input.rs | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 777e63442..b6d851776 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -80,16 +80,16 @@ pub struct CrateGraph { | |||
80 | arena: FxHashMap<CrateId, CrateData>, | 80 | arena: FxHashMap<CrateId, CrateData>, |
81 | } | 81 | } |
82 | 82 | ||
83 | #[derive(Debug)] | ||
84 | pub struct CyclicDependencies; | ||
85 | |||
86 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 83 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
87 | pub struct CrateId(pub u32); | 84 | pub struct CrateId(pub u32); |
88 | 85 | ||
89 | impl CrateId { | 86 | #[derive(Debug, Clone, PartialEq, Eq)] |
90 | pub fn shift(self, amount: u32) -> CrateId { | 87 | struct CrateData { |
91 | CrateId(self.0 + amount) | 88 | file_id: FileId, |
92 | } | 89 | edition: Edition, |
90 | cfg_options: CfgOptions, | ||
91 | env: Env, | ||
92 | dependencies: Vec<Dependency>, | ||
93 | } | 93 | } |
94 | 94 | ||
95 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 95 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -104,36 +104,11 @@ pub struct Env { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | #[derive(Debug, Clone, PartialEq, Eq)] | 106 | #[derive(Debug, Clone, PartialEq, Eq)] |
107 | struct CrateData { | ||
108 | file_id: FileId, | ||
109 | edition: Edition, | ||
110 | dependencies: Vec<Dependency>, | ||
111 | cfg_options: CfgOptions, | ||
112 | env: Env, | ||
113 | } | ||
114 | |||
115 | impl CrateData { | ||
116 | fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions, env: Env) -> CrateData { | ||
117 | CrateData { file_id, edition, dependencies: Vec::new(), cfg_options, env } | ||
118 | } | ||
119 | |||
120 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { | ||
121 | self.dependencies.push(Dependency { name, crate_id }) | ||
122 | } | ||
123 | } | ||
124 | |||
125 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
126 | pub struct Dependency { | 107 | pub struct Dependency { |
127 | pub crate_id: CrateId, | 108 | pub crate_id: CrateId, |
128 | pub name: SmolStr, | 109 | pub name: SmolStr, |
129 | } | 110 | } |
130 | 111 | ||
131 | impl Dependency { | ||
132 | pub fn crate_id(&self) -> CrateId { | ||
133 | self.crate_id | ||
134 | } | ||
135 | } | ||
136 | |||
137 | impl CrateGraph { | 112 | impl CrateGraph { |
138 | pub fn add_crate_root( | 113 | pub fn add_crate_root( |
139 | &mut self, | 114 | &mut self, |
@@ -158,9 +133,9 @@ impl CrateGraph { | |||
158 | from: CrateId, | 133 | from: CrateId, |
159 | name: SmolStr, | 134 | name: SmolStr, |
160 | to: CrateId, | 135 | to: CrateId, |
161 | ) -> Result<(), CyclicDependencies> { | 136 | ) -> Result<(), CyclicDependenciesError> { |
162 | if self.dfs_find(from, to, &mut FxHashSet::default()) { | 137 | if self.dfs_find(from, to, &mut FxHashSet::default()) { |
163 | return Err(CyclicDependencies); | 138 | return Err(CyclicDependenciesError); |
164 | } | 139 | } |
165 | self.arena.get_mut(&from).unwrap().add_dep(name, to); | 140 | self.arena.get_mut(&from).unwrap().add_dep(name, to); |
166 | Ok(()) | 141 | Ok(()) |
@@ -231,9 +206,20 @@ impl CrateGraph { | |||
231 | } | 206 | } |
232 | } | 207 | } |
233 | 208 | ||
234 | #[derive(Debug)] | 209 | impl CrateId { |
235 | pub struct ParseEditionError { | 210 | pub fn shift(self, amount: u32) -> CrateId { |
236 | invalid_input: String, | 211 | CrateId(self.0 + amount) |
212 | } | ||
213 | } | ||
214 | |||
215 | impl CrateData { | ||
216 | fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions, env: Env) -> CrateData { | ||
217 | CrateData { file_id, edition, dependencies: Vec::new(), cfg_options, env } | ||
218 | } | ||
219 | |||
220 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { | ||
221 | self.dependencies.push(Dependency { name, crate_id }) | ||
222 | } | ||
237 | } | 223 | } |
238 | 224 | ||
239 | impl FromStr for Edition { | 225 | impl FromStr for Edition { |
@@ -249,6 +235,17 @@ impl FromStr for Edition { | |||
249 | } | 235 | } |
250 | } | 236 | } |
251 | 237 | ||
238 | impl Dependency { | ||
239 | pub fn crate_id(&self) -> CrateId { | ||
240 | self.crate_id | ||
241 | } | ||
242 | } | ||
243 | |||
244 | #[derive(Debug)] | ||
245 | pub struct ParseEditionError { | ||
246 | invalid_input: String, | ||
247 | } | ||
248 | |||
252 | impl fmt::Display for ParseEditionError { | 249 | impl fmt::Display for ParseEditionError { |
253 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 250 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
254 | write!(f, "invalid edition: {:?}", self.invalid_input) | 251 | write!(f, "invalid edition: {:?}", self.invalid_input) |
@@ -257,6 +254,9 @@ impl fmt::Display for ParseEditionError { | |||
257 | 254 | ||
258 | impl std::error::Error for ParseEditionError {} | 255 | impl std::error::Error for ParseEditionError {} |
259 | 256 | ||
257 | #[derive(Debug)] | ||
258 | pub struct CyclicDependenciesError; | ||
259 | |||
260 | #[cfg(test)] | 260 | #[cfg(test)] |
261 | mod tests { | 261 | mod tests { |
262 | use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr}; | 262 | use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr}; |