diff options
Diffstat (limited to 'crates/ra_hir/src/mock.rs')
-rw-r--r-- | crates/ra_hir/src/mock.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 5ca870867..f1cad77c5 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -3,6 +3,7 @@ use std::{sync::Arc, panic}; | |||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use ra_db::{ | 4 | use ra_db::{ |
5 | FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa, | 5 | FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa, |
6 | Edition, | ||
6 | }; | 7 | }; |
7 | use relative_path::RelativePathBuf; | 8 | use relative_path::RelativePathBuf; |
8 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; | 9 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; |
@@ -58,12 +59,12 @@ impl MockDatabase { | |||
58 | pub fn set_crate_graph_from_fixture(&mut self, graph: CrateGraphFixture) { | 59 | pub fn set_crate_graph_from_fixture(&mut self, graph: CrateGraphFixture) { |
59 | let mut ids = FxHashMap::default(); | 60 | let mut ids = FxHashMap::default(); |
60 | let mut crate_graph = CrateGraph::default(); | 61 | let mut crate_graph = CrateGraph::default(); |
61 | for (crate_name, (crate_root, _)) in graph.0.iter() { | 62 | for (crate_name, (crate_root, edition, _)) in graph.0.iter() { |
62 | let crate_root = self.file_id_of(&crate_root); | 63 | let crate_root = self.file_id_of(&crate_root); |
63 | let crate_id = crate_graph.add_crate_root(crate_root); | 64 | let crate_id = crate_graph.add_crate_root(crate_root, *edition); |
64 | ids.insert(crate_name, crate_id); | 65 | ids.insert(crate_name, crate_id); |
65 | } | 66 | } |
66 | for (crate_name, (_, deps)) in graph.0.iter() { | 67 | for (crate_name, (_, _, deps)) in graph.0.iter() { |
67 | let from = ids[crate_name]; | 68 | let from = ids[crate_name]; |
68 | for dep in deps { | 69 | for dep in deps { |
69 | let to = ids[dep]; | 70 | let to = ids[dep]; |
@@ -144,7 +145,7 @@ impl MockDatabase { | |||
144 | 145 | ||
145 | if is_crate_root { | 146 | if is_crate_root { |
146 | let mut crate_graph = CrateGraph::default(); | 147 | let mut crate_graph = CrateGraph::default(); |
147 | crate_graph.add_crate_root(file_id); | 148 | crate_graph.add_crate_root(file_id, Edition::Edition2018); |
148 | self.set_crate_graph(Arc::new(crate_graph)); | 149 | self.set_crate_graph(Arc::new(crate_graph)); |
149 | } | 150 | } |
150 | file_id | 151 | file_id |
@@ -232,16 +233,19 @@ impl MockDatabase { | |||
232 | } | 233 | } |
233 | 234 | ||
234 | #[derive(Default)] | 235 | #[derive(Default)] |
235 | pub struct CrateGraphFixture(pub FxHashMap<String, (String, Vec<String>)>); | 236 | pub struct CrateGraphFixture(pub FxHashMap<String, (String, Edition, Vec<String>)>); |
236 | 237 | ||
237 | #[macro_export] | 238 | #[macro_export] |
238 | macro_rules! crate_graph { | 239 | macro_rules! crate_graph { |
239 | ($($crate_name:literal: ($crate_path:literal, [$($dep:literal),*]),)*) => {{ | 240 | ($($crate_name:literal: ($crate_path:literal, $($edition:literal,)? [$($dep:literal),*]),)*) => {{ |
240 | let mut res = $crate::mock::CrateGraphFixture::default(); | 241 | let mut res = $crate::mock::CrateGraphFixture::default(); |
241 | $( | 242 | $( |
243 | #[allow(unused_mut, unused_assignments)] | ||
244 | let mut edition = ra_db::Edition::Edition2018; | ||
245 | $(edition = ra_db::Edition::from_string($edition);)? | ||
242 | res.0.insert( | 246 | res.0.insert( |
243 | $crate_name.to_string(), | 247 | $crate_name.to_string(), |
244 | ($crate_path.to_string(), vec![$($dep.to_string()),*]) | 248 | ($crate_path.to_string(), edition, vec![$($dep.to_string()),*]) |
245 | ); | 249 | ); |
246 | )* | 250 | )* |
247 | res | 251 | res |