From 70839b7ef8217fd019ce5bd3a643a8a16f5fa829 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 13 Feb 2019 20:31:27 +0100 Subject: Make edition handling a bit nicer and allow specifying edition in crate_graph macro --- crates/ra_hir/src/mock.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/mock.rs') 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 { pub fn set_crate_graph_from_fixture(&mut self, graph: CrateGraphFixture) { let mut ids = FxHashMap::default(); let mut crate_graph = CrateGraph::default(); - for (crate_name, (crate_root, _)) in graph.0.iter() { + for (crate_name, (crate_root, edition, _)) in graph.0.iter() { let crate_root = self.file_id_of(&crate_root); - let crate_id = crate_graph.add_crate_root(crate_root, Edition::Edition2018); + let crate_id = crate_graph.add_crate_root(crate_root, *edition); ids.insert(crate_name, crate_id); } - for (crate_name, (_, deps)) in graph.0.iter() { + for (crate_name, (_, _, deps)) in graph.0.iter() { let from = ids[crate_name]; for dep in deps { let to = ids[dep]; @@ -233,16 +233,19 @@ impl MockDatabase { } #[derive(Default)] -pub struct CrateGraphFixture(pub FxHashMap)>); +pub struct CrateGraphFixture(pub FxHashMap)>); #[macro_export] macro_rules! crate_graph { - ($($crate_name:literal: ($crate_path:literal, [$($dep:literal),*]),)*) => {{ + ($($crate_name:literal: ($crate_path:literal, $($edition:literal,)? [$($dep:literal),*]),)*) => {{ let mut res = $crate::mock::CrateGraphFixture::default(); $( + #[allow(unused_mut, unused_assignments)] + let mut edition = ra_db::Edition::Edition2018; + $(edition = ra_db::Edition::from_string($edition);)? res.0.insert( $crate_name.to_string(), - ($crate_path.to_string(), vec![$($dep.to_string()),*]) + ($crate_path.to_string(), edition, vec![$($dep.to_string()),*]) ); )* res -- cgit v1.2.3