diff options
author | Florian Diebold <[email protected]> | 2019-02-10 21:34:29 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-02-13 19:10:46 +0000 |
commit | 3a9934e2c3280864877a90c5ced777bad898d73a (patch) | |
tree | b37994dc169b216a2d11a11bbe91503526d9b2dd /crates/ra_db | |
parent | 1526eb25c98fd16a9c0d114d0ed44e8fec1cc19c (diff) |
Keep track of crate edition
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/input.rs | 31 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 2 |
2 files changed, 20 insertions, 13 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 8decc65c5..76998ea30 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -56,15 +56,22 @@ pub struct CyclicDependencies; | |||
56 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 56 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
57 | pub struct CrateId(pub u32); | 57 | pub struct CrateId(pub u32); |
58 | 58 | ||
59 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
60 | pub enum Edition { | ||
61 | Edition2018, | ||
62 | Edition2015, | ||
63 | } | ||
64 | |||
59 | #[derive(Debug, Clone, PartialEq, Eq)] | 65 | #[derive(Debug, Clone, PartialEq, Eq)] |
60 | struct CrateData { | 66 | struct CrateData { |
61 | file_id: FileId, | 67 | file_id: FileId, |
68 | edition: Edition, | ||
62 | dependencies: Vec<Dependency>, | 69 | dependencies: Vec<Dependency>, |
63 | } | 70 | } |
64 | 71 | ||
65 | impl CrateData { | 72 | impl CrateData { |
66 | fn new(file_id: FileId) -> CrateData { | 73 | fn new(file_id: FileId, edition: Edition) -> CrateData { |
67 | CrateData { file_id, dependencies: Vec::new() } | 74 | CrateData { file_id, edition, dependencies: Vec::new() } |
68 | } | 75 | } |
69 | 76 | ||
70 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { | 77 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { |
@@ -85,9 +92,9 @@ impl Dependency { | |||
85 | } | 92 | } |
86 | 93 | ||
87 | impl CrateGraph { | 94 | impl CrateGraph { |
88 | pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId { | 95 | pub fn add_crate_root(&mut self, file_id: FileId, edition: Edition) -> CrateId { |
89 | let crate_id = CrateId(self.arena.len() as u32); | 96 | let crate_id = CrateId(self.arena.len() as u32); |
90 | let prev = self.arena.insert(crate_id, CrateData::new(file_id)); | 97 | let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition)); |
91 | assert!(prev.is_none()); | 98 | assert!(prev.is_none()); |
92 | crate_id | 99 | crate_id |
93 | } | 100 | } |
@@ -159,14 +166,14 @@ impl CrateGraph { | |||
159 | 166 | ||
160 | #[cfg(test)] | 167 | #[cfg(test)] |
161 | mod tests { | 168 | mod tests { |
162 | use super::{CrateGraph, FileId, SmolStr}; | 169 | use super::{CrateGraph, FileId, SmolStr, Edition::Edition2018}; |
163 | 170 | ||
164 | #[test] | 171 | #[test] |
165 | fn it_should_painc_because_of_cycle_dependencies() { | 172 | fn it_should_panic_because_of_cycle_dependencies() { |
166 | let mut graph = CrateGraph::default(); | 173 | let mut graph = CrateGraph::default(); |
167 | let crate1 = graph.add_crate_root(FileId(1u32)); | 174 | let crate1 = graph.add_crate_root(FileId(1u32), Edition2018); |
168 | let crate2 = graph.add_crate_root(FileId(2u32)); | 175 | let crate2 = graph.add_crate_root(FileId(2u32), Edition2018); |
169 | let crate3 = graph.add_crate_root(FileId(3u32)); | 176 | let crate3 = graph.add_crate_root(FileId(3u32), Edition2018); |
170 | assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); | 177 | assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); |
171 | assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); | 178 | assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); |
172 | assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err()); | 179 | assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err()); |
@@ -175,9 +182,9 @@ mod tests { | |||
175 | #[test] | 182 | #[test] |
176 | fn it_works() { | 183 | fn it_works() { |
177 | let mut graph = CrateGraph::default(); | 184 | let mut graph = CrateGraph::default(); |
178 | let crate1 = graph.add_crate_root(FileId(1u32)); | 185 | let crate1 = graph.add_crate_root(FileId(1u32), Edition2018); |
179 | let crate2 = graph.add_crate_root(FileId(2u32)); | 186 | let crate2 = graph.add_crate_root(FileId(2u32), Edition2018); |
180 | let crate3 = graph.add_crate_root(FileId(3u32)); | 187 | let crate3 = graph.add_crate_root(FileId(3u32), Edition2018); |
181 | assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); | 188 | assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); |
182 | assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); | 189 | assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); |
183 | } | 190 | } |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 31442713d..e006c6d27 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -14,7 +14,7 @@ pub use ::salsa as salsa; | |||
14 | pub use crate::{ | 14 | pub use crate::{ |
15 | cancellation::Canceled, | 15 | cancellation::Canceled, |
16 | input::{ | 16 | input::{ |
17 | FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, | 17 | FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, Edition, |
18 | }, | 18 | }, |
19 | loc2id::LocationIntener, | 19 | loc2id::LocationIntener, |
20 | }; | 20 | }; |