diff options
author | Florian Diebold <[email protected]> | 2019-02-13 19:31:27 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-02-13 19:31:47 +0000 |
commit | 70839b7ef8217fd019ce5bd3a643a8a16f5fa829 (patch) | |
tree | d6888643048c0cf5738f4ddf756047ad138e500c /crates/ra_project_model/src | |
parent | d5ad38cbb87103d8713855e0ec705fd957249afd (diff) |
Make edition handling a bit nicer and allow specifying edition in crate_graph macro
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 9 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 6 |
2 files changed, 6 insertions, 9 deletions
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); |