aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-22 11:08:18 +0000
committerAleksey Kladov <[email protected]>2019-11-22 11:08:18 +0000
commit0861ac061ef5c8b5d7ed2a95ef30f4a17710229d (patch)
treef6422fb3ac2d657500767b4fe6283e00e80e0631 /crates
parent2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 (diff)
Cleanup errors
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/input.rs46
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs4
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
9use rustc_hash::FxHashMap; 9use std::{fmt, str::FromStr};
10 10
11use ra_cfg::CfgOptions; 11use ra_cfg::CfgOptions;
12use ra_syntax::SmolStr; 12use ra_syntax::SmolStr;
13use rustc_hash::FxHashMap;
13use rustc_hash::FxHashSet; 14use rustc_hash::FxHashSet;
14 15
15use crate::{RelativePath, RelativePathBuf}; 16use crate::{RelativePath, RelativePathBuf};
16use 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)]
102pub struct ParseEditionError {
103 pub msg: String,
104}
105
106impl 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)]
118pub struct Env { 102pub 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)]
235pub struct ParseEditionError {
236 invalid_input: String,
237}
238
239impl 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
252impl 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
258impl std::error::Error for ParseEditionError {}
259
250#[cfg(test)] 260#[cfg(test)]
251mod tests { 261mod 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
3use std::path::{Path, PathBuf}; 3use std::path::{Path, PathBuf};
4use std::str::FromStr;
5 4
6use cargo_metadata::{CargoOpt, MetadataCommand}; 5use cargo_metadata::{CargoOpt, MetadataCommand};
7use ra_arena::{impl_arena_id, Arena, RawId}; 6use 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,