diff options
author | Aleksey Kladov <[email protected]> | 2019-11-22 11:08:18 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-22 11:08:18 +0000 |
commit | 0861ac061ef5c8b5d7ed2a95ef30f4a17710229d (patch) | |
tree | f6422fb3ac2d657500767b4fe6283e00e80e0631 /crates/ra_db/src | |
parent | 2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 (diff) |
Cleanup errors
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r-- | crates/ra_db/src/input.rs | 46 |
1 files changed, 28 insertions, 18 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}; |