aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
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/ra_db
parent2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 (diff)
Cleanup errors
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/input.rs46
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
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};