aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-12 15:30:36 +0000
committerGitHub <[email protected]>2019-11-12 15:30:36 +0000
commit2549be750e4c611a582bc0845b1da71e131f1118 (patch)
treefec19f32a3b9dd7ced95281b291674ed7ee3a4cd /crates/ra_project_model
parent55f3ff241a2105d2903266703474acbd24a85e84 (diff)
parentdae087656abf5d120cd9c051bf4fc446fca101e1 (diff)
Merge #2217
2217: Implement FromStr for enum Edition r=matklad a=clemarescx Just did this as I came across the comment in the code asking for implementing `std::str::FromStr` for `input::Edition`. Not sure what was meant by "proper error handling" though, `panic!` with a descriptive message might not be it :sweat_smile: Co-authored-by: Metabaron <[email protected]>
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 28dadea9d..cf88911b7 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -1,6 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::path::{Path, PathBuf}; 3use std::path::{Path, PathBuf};
4use std::str::FromStr;
4 5
5use cargo_metadata::{CargoOpt, MetadataCommand}; 6use cargo_metadata::{CargoOpt, MetadataCommand};
6use ra_arena::{impl_arena_id, Arena, RawId}; 7use ra_arena::{impl_arena_id, Arena, RawId};
@@ -140,18 +141,21 @@ impl CargoWorkspace {
140 let ws_members = &meta.workspace_members; 141 let ws_members = &meta.workspace_members;
141 142
142 for meta_pkg in meta.packages { 143 for meta_pkg in meta.packages {
143 let is_member = ws_members.contains(&meta_pkg.id); 144 let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg;
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)))?;
144 let pkg = packages.alloc(PackageData { 148 let pkg = packages.alloc(PackageData {
145 name: meta_pkg.name, 149 name,
146 manifest: meta_pkg.manifest_path.clone(), 150 manifest: manifest_path,
147 targets: Vec::new(), 151 targets: Vec::new(),
148 is_member, 152 is_member,
149 edition: Edition::from_string(&meta_pkg.edition), 153 edition,
150 dependencies: Vec::new(), 154 dependencies: Vec::new(),
151 features: Vec::new(), 155 features: Vec::new(),
152 }); 156 });
153 let pkg_data = &mut packages[pkg]; 157 let pkg_data = &mut packages[pkg];
154 pkg_by_id.insert(meta_pkg.id.clone(), pkg); 158 pkg_by_id.insert(id, pkg);
155 for meta_tgt in meta_pkg.targets { 159 for meta_tgt in meta_pkg.targets {
156 let tgt = targets.alloc(TargetData { 160 let tgt = targets.alloc(TargetData {
157 pkg, 161 pkg,