diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/input.rs | 46 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 4 |
2 files changed, 29 insertions, 21 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 0015d6b5e..777e63442 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -6,14 +6,14 @@ | |||
6 | //! actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how | 6 | //! actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how |
7 | //! actual IO is done and lowered to input. | 7 | //! actual IO is done and lowered to input. |
8 | 8 | ||
9 | use rustc_hash::FxHashMap; | 9 | use std::{fmt, str::FromStr}; |
10 | 10 | ||
11 | use ra_cfg::CfgOptions; | 11 | use ra_cfg::CfgOptions; |
12 | use ra_syntax::SmolStr; | 12 | use ra_syntax::SmolStr; |
13 | use rustc_hash::FxHashMap; | ||
13 | use rustc_hash::FxHashSet; | 14 | use rustc_hash::FxHashSet; |
14 | 15 | ||
15 | use crate::{RelativePath, RelativePathBuf}; | 16 | use crate::{RelativePath, RelativePathBuf}; |
16 | use std::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,22 +98,6 @@ pub enum Edition { | |||
98 | Edition2015, | 98 | Edition2015, |
99 | } | 99 | } |
100 | 100 | ||
101 | #[derive(Debug)] | ||
102 | pub struct ParseEditionError { | ||
103 | pub msg: String, | ||
104 | } | ||
105 | |||
106 | impl FromStr for Edition { | ||
107 | type Err = ParseEditionError; | ||
108 | fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
109 | match s { | ||
110 | "2015" => Ok(Edition::Edition2015), | ||
111 | "2018" => Ok(Edition::Edition2018), | ||
112 | _ => Err(ParseEditionError { msg: format!("unknown edition: {}", s) }), | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
117 | #[derive(Default, Debug, Clone, PartialEq, Eq)] | 101 | #[derive(Default, Debug, Clone, PartialEq, Eq)] |
118 | pub struct Env { | 102 | pub struct Env { |
119 | entries: FxHashMap<String, String>, | 103 | entries: FxHashMap<String, String>, |
@@ -247,6 +231,32 @@ impl CrateGraph { | |||
247 | } | 231 | } |
248 | } | 232 | } |
249 | 233 | ||
234 | #[derive(Debug)] | ||
235 | pub struct ParseEditionError { | ||
236 | invalid_input: String, | ||
237 | } | ||
238 | |||
239 | impl FromStr for Edition { | ||
240 | type Err = ParseEditionError; | ||
241 | |||
242 | fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
243 | let res = match s { | ||
244 | "2015" => Edition::Edition2015, | ||
245 | "2018" => Edition::Edition2018, | ||
246 | _ => Err(ParseEditionError { invalid_input: s.to_string() })?, | ||
247 | }; | ||
248 | Ok(res) | ||
249 | } | ||
250 | } | ||
251 | |||
252 | impl fmt::Display for ParseEditionError { | ||
253 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
254 | write!(f, "invalid edition: {:?}", self.invalid_input) | ||
255 | } | ||
256 | } | ||
257 | |||
258 | impl std::error::Error for ParseEditionError {} | ||
259 | |||
250 | #[cfg(test)] | 260 | #[cfg(test)] |
251 | mod tests { | 261 | mod tests { |
252 | use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr}; | 262 | use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr}; |
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index cf88911b7..c128e608d 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::path::{Path, PathBuf}; | 3 | use std::path::{Path, PathBuf}; |
4 | use std::str::FromStr; | ||
5 | 4 | ||
6 | use cargo_metadata::{CargoOpt, MetadataCommand}; | 5 | use cargo_metadata::{CargoOpt, MetadataCommand}; |
7 | use ra_arena::{impl_arena_id, Arena, RawId}; | 6 | use ra_arena::{impl_arena_id, Arena, RawId}; |
@@ -143,8 +142,7 @@ impl CargoWorkspace { | |||
143 | for meta_pkg in meta.packages { | 142 | for meta_pkg in meta.packages { |
144 | let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg; | 143 | let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg; |
145 | let is_member = ws_members.contains(&id); | 144 | let is_member = ws_members.contains(&id); |
146 | let edition = Edition::from_str(&edition) | 145 | let edition = edition.parse::<Edition>()?; |
147 | .map_err(|e| (format!("metadata for package {} failed: {}", &name, e.msg)))?; | ||
148 | let pkg = packages.alloc(PackageData { | 146 | let pkg = packages.alloc(PackageData { |
149 | name, | 147 | name, |
150 | manifest: manifest_path, | 148 | manifest: manifest_path, |