diff options
-rw-r--r-- | crates/ra_db/src/input.rs | 11 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 15 |
2 files changed, 16 insertions, 10 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index fb9a3297a..472a15f2b 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -13,7 +13,7 @@ use ra_syntax::SmolStr; | |||
13 | use rustc_hash::FxHashSet; | 13 | use rustc_hash::FxHashSet; |
14 | 14 | ||
15 | use crate::{RelativePath, RelativePathBuf}; | 15 | use crate::{RelativePath, RelativePathBuf}; |
16 | use std::str::FromStr; | 16 | use std::{error::Error, str::FromStr}; |
17 | 17 | ||
18 | /// `FileId` is an integer which uniquely identifies a file. File paths are | 18 | /// `FileId` is an integer which uniquely identifies a file. File paths are |
19 | /// messy and system-dependent, so most of the code should work directly with | 19 | /// messy and system-dependent, so most of the code should work directly with |
@@ -98,13 +98,18 @@ pub enum Edition { | |||
98 | Edition2015, | 98 | Edition2015, |
99 | } | 99 | } |
100 | 100 | ||
101 | #[derive(Debug)] | ||
102 | pub struct ParseEditionError { | ||
103 | pub msg: String, | ||
104 | } | ||
105 | |||
101 | impl FromStr for Edition { | 106 | impl FromStr for Edition { |
102 | type Err = String; | 107 | type Err = ParseEditionError; |
103 | fn from_str(s: &str) -> Result<Self, Self::Err> { | 108 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
104 | match s { | 109 | match s { |
105 | "2015" => Ok(Edition::Edition2015), | 110 | "2015" => Ok(Edition::Edition2015), |
106 | "2018" => Ok(Edition::Edition2018), | 111 | "2018" => Ok(Edition::Edition2018), |
107 | _ => Err(format! {"unknown edition: {}" , s}), | 112 | _ => Err(ParseEditionError { msg: format!("unknown edition: {}", s) }), |
108 | } | 113 | } |
109 | } | 114 | } |
110 | } | 115 | } |
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index ff96bf904..cf88911b7 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -141,20 +141,21 @@ impl CargoWorkspace { | |||
141 | let ws_members = &meta.workspace_members; | 141 | let ws_members = &meta.workspace_members; |
142 | 142 | ||
143 | for meta_pkg in meta.packages { | 143 | for meta_pkg in meta.packages { |
144 | let is_member = ws_members.contains(&meta_pkg.id); | 144 | let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg; |
145 | let name = meta_pkg.name; | 145 | let is_member = ws_members.contains(&id); |
146 | let edition = Edition::from_str(&edition) | ||
147 | .map_err(|e| (format!("metadata for package {} failed: {}", &name, e.msg)))?; | ||
146 | let pkg = packages.alloc(PackageData { | 148 | let pkg = packages.alloc(PackageData { |
147 | name: name.clone(), | 149 | name, |
148 | manifest: meta_pkg.manifest_path.clone(), | 150 | manifest: manifest_path, |
149 | targets: Vec::new(), | 151 | targets: Vec::new(), |
150 | is_member, | 152 | is_member, |
151 | edition: Edition::from_str(&meta_pkg.edition) | 153 | edition, |
152 | .unwrap_or_else(|e| panic!("unknown edition {} for package {:?}", e, &name)), | ||
153 | dependencies: Vec::new(), | 154 | dependencies: Vec::new(), |
154 | features: Vec::new(), | 155 | features: Vec::new(), |
155 | }); | 156 | }); |
156 | let pkg_data = &mut packages[pkg]; | 157 | let pkg_data = &mut packages[pkg]; |
157 | pkg_by_id.insert(meta_pkg.id.clone(), pkg); | 158 | pkg_by_id.insert(id, pkg); |
158 | for meta_tgt in meta_pkg.targets { | 159 | for meta_tgt in meta_pkg.targets { |
159 | let tgt = targets.alloc(TargetData { | 160 | let tgt = targets.alloc(TargetData { |
160 | pkg, | 161 | pkg, |