diff options
-rw-r--r-- | crates/ra_db/src/input.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 14 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 9 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 6 |
5 files changed, 28 insertions, 25 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index aa535ac4d..e45a510b3 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -62,6 +62,15 @@ pub enum Edition { | |||
62 | Edition2015, | 62 | Edition2015, |
63 | } | 63 | } |
64 | 64 | ||
65 | impl Edition { | ||
66 | pub fn from_string(s: &str) -> Edition { | ||
67 | match s { | ||
68 | "2015" => Edition::Edition2015, | ||
69 | "2018" | _ => Edition::Edition2018, | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
65 | #[derive(Debug, Clone, PartialEq, Eq)] | 74 | #[derive(Debug, Clone, PartialEq, Eq)] |
66 | struct CrateData { | 75 | struct CrateData { |
67 | file_id: FileId, | 76 | file_id: FileId, |
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); |
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index e28aca259..81cb506b7 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -4,6 +4,7 @@ use cargo_metadata::{MetadataCommand, CargoOpt}; | |||
4 | use ra_arena::{Arena, RawId, impl_arena_id}; | 4 | use ra_arena::{Arena, RawId, impl_arena_id}; |
5 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
6 | use failure::format_err; | 6 | use failure::format_err; |
7 | use ra_db::Edition; | ||
7 | 8 | ||
8 | use crate::Result; | 9 | use crate::Result; |
9 | 10 | ||
@@ -35,7 +36,7 @@ struct PackageData { | |||
35 | targets: Vec<Target>, | 36 | targets: Vec<Target>, |
36 | is_member: bool, | 37 | is_member: bool, |
37 | dependencies: Vec<PackageDependency>, | 38 | dependencies: Vec<PackageDependency>, |
38 | edition: String, | 39 | edition: Edition, |
39 | } | 40 | } |
40 | 41 | ||
41 | #[derive(Debug, Clone)] | 42 | #[derive(Debug, Clone)] |
@@ -85,8 +86,8 @@ impl Package { | |||
85 | pub fn root(self, ws: &CargoWorkspace) -> &Path { | 86 | pub fn root(self, ws: &CargoWorkspace) -> &Path { |
86 | ws.packages[self].manifest.parent().unwrap() | 87 | ws.packages[self].manifest.parent().unwrap() |
87 | } | 88 | } |
88 | pub fn edition(self, ws: &CargoWorkspace) -> &str { | 89 | pub fn edition(self, ws: &CargoWorkspace) -> Edition { |
89 | &ws.packages[self].edition | 90 | ws.packages[self].edition |
90 | } | 91 | } |
91 | pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a { | 92 | pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a { |
92 | ws.packages[self].targets.iter().cloned() | 93 | ws.packages[self].targets.iter().cloned() |
@@ -139,7 +140,7 @@ impl CargoWorkspace { | |||
139 | manifest: meta_pkg.manifest_path.clone(), | 140 | manifest: meta_pkg.manifest_path.clone(), |
140 | targets: Vec::new(), | 141 | targets: Vec::new(), |
141 | is_member, | 142 | is_member, |
142 | edition: meta_pkg.edition, | 143 | edition: Edition::from_string(&meta_pkg.edition), |
143 | dependencies: Vec::new(), | 144 | dependencies: Vec::new(), |
144 | }); | 145 | }); |
145 | let pkg_data = &mut packages[pkg]; | 146 | let pkg_data = &mut packages[pkg]; |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index e5c93fd85..1b18ac836 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -63,11 +63,7 @@ impl ProjectWorkspace { | |||
63 | for tgt in pkg.targets(&self.cargo) { | 63 | for tgt in pkg.targets(&self.cargo) { |
64 | let root = tgt.root(&self.cargo); | 64 | let root = tgt.root(&self.cargo); |
65 | if let Some(file_id) = load(root) { | 65 | if let Some(file_id) = load(root) { |
66 | let edition = if pkg.edition(&self.cargo) == "2015" { | 66 | let edition = pkg.edition(&self.cargo); |
67 | Edition::Edition2015 | ||
68 | } else { | ||
69 | Edition::Edition2018 | ||
70 | }; | ||
71 | let crate_id = crate_graph.add_crate_root(file_id, edition); | 67 | let crate_id = crate_graph.add_crate_root(file_id, edition); |
72 | if tgt.kind(&self.cargo) == TargetKind::Lib { | 68 | if tgt.kind(&self.cargo) == TargetKind::Lib { |
73 | lib_tgt = Some(crate_id); | 69 | lib_tgt = Some(crate_id); |