diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/mock.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 14 |
2 files changed, 13 insertions, 16 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 145ed39a1..f1cad77c5 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -59,12 +59,12 @@ impl MockDatabase { | |||
59 | pub fn set_crate_graph_from_fixture(&mut self, graph: CrateGraphFixture) { | 59 | pub fn set_crate_graph_from_fixture(&mut self, graph: CrateGraphFixture) { |
60 | let mut ids = FxHashMap::default(); | 60 | let mut ids = FxHashMap::default(); |
61 | let mut crate_graph = CrateGraph::default(); | 61 | let mut crate_graph = CrateGraph::default(); |
62 | for (crate_name, (crate_root, _)) in graph.0.iter() { | 62 | for (crate_name, (crate_root, edition, _)) in graph.0.iter() { |
63 | let crate_root = self.file_id_of(&crate_root); | 63 | let crate_root = self.file_id_of(&crate_root); |
64 | let crate_id = crate_graph.add_crate_root(crate_root, Edition::Edition2018); | 64 | let crate_id = crate_graph.add_crate_root(crate_root, *edition); |
65 | ids.insert(crate_name, crate_id); | 65 | ids.insert(crate_name, crate_id); |
66 | } | 66 | } |
67 | for (crate_name, (_, deps)) in graph.0.iter() { | 67 | for (crate_name, (_, _, deps)) in graph.0.iter() { |
68 | let from = ids[crate_name]; | 68 | let from = ids[crate_name]; |
69 | for dep in deps { | 69 | for dep in deps { |
70 | let to = ids[dep]; | 70 | let to = ids[dep]; |
@@ -233,16 +233,19 @@ impl MockDatabase { | |||
233 | } | 233 | } |
234 | 234 | ||
235 | #[derive(Default)] | 235 | #[derive(Default)] |
236 | pub struct CrateGraphFixture(pub FxHashMap<String, (String, Vec<String>)>); | 236 | pub struct CrateGraphFixture(pub FxHashMap<String, (String, Edition, Vec<String>)>); |
237 | 237 | ||
238 | #[macro_export] | 238 | #[macro_export] |
239 | macro_rules! crate_graph { | 239 | macro_rules! crate_graph { |
240 | ($($crate_name:literal: ($crate_path:literal, [$($dep:literal),*]),)*) => {{ | 240 | ($($crate_name:literal: ($crate_path:literal, $($edition:literal,)? [$($dep:literal),*]),)*) => {{ |
241 | let mut res = $crate::mock::CrateGraphFixture::default(); | 241 | let mut res = $crate::mock::CrateGraphFixture::default(); |
242 | $( | 242 | $( |
243 | #[allow(unused_mut, unused_assignments)] | ||
244 | let mut edition = ra_db::Edition::Edition2018; | ||
245 | $(edition = ra_db::Edition::from_string($edition);)? | ||
243 | res.0.insert( | 246 | res.0.insert( |
244 | $crate_name.to_string(), | 247 | $crate_name.to_string(), |
245 | ($crate_path.to_string(), vec![$($dep.to_string()),*]) | 248 | ($crate_path.to_string(), edition, vec![$($dep.to_string()),*]) |
246 | ); | 249 | ); |
247 | )* | 250 | )* |
248 | res | 251 | res |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index bee475c3a..e764e0855 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -267,7 +267,6 @@ fn glob_across_crates() { | |||
267 | 267 | ||
268 | #[test] | 268 | #[test] |
269 | fn edition_2015_imports() { | 269 | fn edition_2015_imports() { |
270 | use ra_db::{CrateGraph, Edition}; | ||
271 | let mut db = MockDatabase::with_files( | 270 | let mut db = MockDatabase::with_files( |
272 | " | 271 | " |
273 | //- /main.rs | 272 | //- /main.rs |
@@ -285,17 +284,12 @@ fn edition_2015_imports() { | |||
285 | struct FromLib; | 284 | struct FromLib; |
286 | ", | 285 | ", |
287 | ); | 286 | ); |
288 | let main_id = db.file_id_of("/main.rs"); | 287 | db.set_crate_graph_from_fixture(crate_graph! { |
289 | let lib_id = db.file_id_of("/lib.rs"); | 288 | "main": ("/main.rs", "2015", ["other_crate"]), |
289 | "other_crate": ("/lib.rs", "2018", []), | ||
290 | }); | ||
290 | let foo_id = db.file_id_of("/foo.rs"); | 291 | let foo_id = db.file_id_of("/foo.rs"); |
291 | 292 | ||
292 | let mut crate_graph = CrateGraph::default(); | ||
293 | let main_crate = crate_graph.add_crate_root(main_id, Edition::Edition2015); | ||
294 | let lib_crate = crate_graph.add_crate_root(lib_id, Edition::Edition2018); | ||
295 | crate_graph.add_dep(main_crate, "other_crate".into(), lib_crate).unwrap(); | ||
296 | |||
297 | db.set_crate_graph(Arc::new(crate_graph)); | ||
298 | |||
299 | let module = crate::source_binder::module_from_file_id(&db, foo_id).unwrap(); | 293 | let module = crate::source_binder::module_from_file_id(&db, foo_id).unwrap(); |
300 | let krate = module.krate(&db).unwrap(); | 294 | let krate = module.krate(&db).unwrap(); |
301 | let item_map = db.item_map(krate); | 295 | let item_map = db.item_map(krate); |