aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-09-30 00:38:16 +0100
committeruHOOCCOOHu <[email protected]>2019-10-02 19:28:02 +0100
commitd2ea776b8fbb5286a04dde75a9a8f8b14f12bfe9 (patch)
treed6ddac6dc88b327aaf956843dc53b3e635f699b9 /crates/ra_db
parentb1ed887d813bf5775a16624694939fdf836f97b1 (diff)
Enable CfgOptions `test` for workspace crates
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/input.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 5fd6edd78..23148096c 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -114,9 +114,8 @@ struct CrateData {
114} 114}
115 115
116impl CrateData { 116impl CrateData {
117 fn new(file_id: FileId, edition: Edition) -> CrateData { 117 fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions) -> CrateData {
118 // FIXME: cfg options 118 CrateData { file_id, edition, dependencies: Vec::new(), cfg_options }
119 CrateData { file_id, edition, dependencies: Vec::new(), cfg_options: CfgOptions::default() }
120 } 119 }
121 120
122 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { 121 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
@@ -137,9 +136,14 @@ impl Dependency {
137} 136}
138 137
139impl CrateGraph { 138impl CrateGraph {
140 pub fn add_crate_root(&mut self, file_id: FileId, edition: Edition) -> CrateId { 139 pub fn add_crate_root(
140 &mut self,
141 file_id: FileId,
142 edition: Edition,
143 cfg_options: CfgOptions,
144 ) -> CrateId {
141 let crate_id = CrateId(self.arena.len() as u32); 145 let crate_id = CrateId(self.arena.len() as u32);
142 let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition)); 146 let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition, cfg_options));
143 assert!(prev.is_none()); 147 assert!(prev.is_none());
144 crate_id 148 crate_id
145 } 149 }
@@ -228,14 +232,14 @@ impl CrateGraph {
228 232
229#[cfg(test)] 233#[cfg(test)]
230mod tests { 234mod tests {
231 use super::{CrateGraph, Edition::Edition2018, FileId, SmolStr}; 235 use super::{CfgOptions, CrateGraph, Edition::Edition2018, FileId, SmolStr};
232 236
233 #[test] 237 #[test]
234 fn it_should_panic_because_of_cycle_dependencies() { 238 fn it_should_panic_because_of_cycle_dependencies() {
235 let mut graph = CrateGraph::default(); 239 let mut graph = CrateGraph::default();
236 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018); 240 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default());
237 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018); 241 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default());
238 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018); 242 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default());
239 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); 243 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
240 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); 244 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
241 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err()); 245 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err());
@@ -244,9 +248,9 @@ mod tests {
244 #[test] 248 #[test]
245 fn it_works() { 249 fn it_works() {
246 let mut graph = CrateGraph::default(); 250 let mut graph = CrateGraph::default();
247 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018); 251 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default());
248 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018); 252 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default());
249 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018); 253 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default());
250 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); 254 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
251 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); 255 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
252 } 256 }