diff options
author | ice1000 <[email protected]> | 2019-12-03 16:07:56 +0000 |
---|---|---|
committer | ice1000 <[email protected]> | 2019-12-03 16:07:56 +0000 |
commit | 009437f5d9949d2276aa26040e03af0ab328acf3 (patch) | |
tree | 74a889d70e201d6997c6baf179261ab3ed8bf23c /crates/ra_hir_expand | |
parent | 15f143f0c33cbd382a2ad7a407d9601cb843d164 (diff) |
Replace `ra_hir_expand::either` with crate
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/either.rs | 54 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/hygiene.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 1 |
4 files changed, 4 insertions, 58 deletions
diff --git a/crates/ra_hir_expand/Cargo.toml b/crates/ra_hir_expand/Cargo.toml index c60152a79..3ae4376dc 100644 --- a/crates/ra_hir_expand/Cargo.toml +++ b/crates/ra_hir_expand/Cargo.toml | |||
@@ -9,6 +9,7 @@ doctest = false | |||
9 | 9 | ||
10 | [dependencies] | 10 | [dependencies] |
11 | log = "0.4.5" | 11 | log = "0.4.5" |
12 | either = "1.5" | ||
12 | 13 | ||
13 | ra_arena = { path = "../ra_arena" } | 14 | ra_arena = { path = "../ra_arena" } |
14 | ra_db = { path = "../ra_db" } | 15 | ra_db = { path = "../ra_db" } |
diff --git a/crates/ra_hir_expand/src/either.rs b/crates/ra_hir_expand/src/either.rs deleted file mode 100644 index 83583ef8b..000000000 --- a/crates/ra_hir_expand/src/either.rs +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
4 | pub enum Either<A, B> { | ||
5 | A(A), | ||
6 | B(B), | ||
7 | } | ||
8 | |||
9 | impl<A, B> Either<A, B> { | ||
10 | pub fn either<R, F1, F2>(self, f1: F1, f2: F2) -> R | ||
11 | where | ||
12 | F1: FnOnce(A) -> R, | ||
13 | F2: FnOnce(B) -> R, | ||
14 | { | ||
15 | match self { | ||
16 | Either::A(a) => f1(a), | ||
17 | Either::B(b) => f2(b), | ||
18 | } | ||
19 | } | ||
20 | pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V> | ||
21 | where | ||
22 | F1: FnOnce(A) -> U, | ||
23 | F2: FnOnce(B) -> V, | ||
24 | { | ||
25 | match self { | ||
26 | Either::A(a) => Either::A(f1(a)), | ||
27 | Either::B(b) => Either::B(f2(b)), | ||
28 | } | ||
29 | } | ||
30 | pub fn map_a<U, F>(self, f: F) -> Either<U, B> | ||
31 | where | ||
32 | F: FnOnce(A) -> U, | ||
33 | { | ||
34 | self.map(f, |it| it) | ||
35 | } | ||
36 | pub fn a(self) -> Option<A> { | ||
37 | match self { | ||
38 | Either::A(it) => Some(it), | ||
39 | Either::B(_) => None, | ||
40 | } | ||
41 | } | ||
42 | pub fn b(self) -> Option<B> { | ||
43 | match self { | ||
44 | Either::A(_) => None, | ||
45 | Either::B(it) => Some(it), | ||
46 | } | ||
47 | } | ||
48 | pub fn as_ref(&self) -> Either<&A, &B> { | ||
49 | match self { | ||
50 | Either::A(it) => Either::A(it), | ||
51 | Either::B(it) => Either::B(it), | ||
52 | } | ||
53 | } | ||
54 | } | ||
diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs index 379562a2c..64c8b06c6 100644 --- a/crates/ra_hir_expand/src/hygiene.rs +++ b/crates/ra_hir_expand/src/hygiene.rs | |||
@@ -2,12 +2,12 @@ | |||
2 | //! | 2 | //! |
3 | //! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at | 3 | //! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at |
4 | //! this moment, this is horribly incomplete and handles only `$crate`. | 4 | //! this moment, this is horribly incomplete and handles only `$crate`. |
5 | use either::Either; | ||
5 | use ra_db::CrateId; | 6 | use ra_db::CrateId; |
6 | use ra_syntax::ast; | 7 | use ra_syntax::ast; |
7 | 8 | ||
8 | use crate::{ | 9 | use crate::{ |
9 | db::AstDatabase, | 10 | db::AstDatabase, |
10 | either::Either, | ||
11 | name::{AsName, Name}, | 11 | name::{AsName, Name}, |
12 | HirFileId, HirFileIdRepr, MacroDefKind, | 12 | HirFileId, HirFileIdRepr, MacroDefKind, |
13 | }; | 13 | }; |
@@ -41,9 +41,9 @@ impl Hygiene { | |||
41 | pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { | 41 | pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { |
42 | if let Some(def_crate) = self.def_crate { | 42 | if let Some(def_crate) = self.def_crate { |
43 | if name_ref.text() == "$crate" { | 43 | if name_ref.text() == "$crate" { |
44 | return Either::B(def_crate); | 44 | return Either::Right(def_crate); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | Either::A(name_ref.as_name()) | 47 | Either::Left(name_ref.as_name()) |
48 | } | 48 | } |
49 | } | 49 | } |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index fb88d2ac2..3be9bdf86 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | pub mod db; | 7 | pub mod db; |
8 | pub mod ast_id_map; | 8 | pub mod ast_id_map; |
9 | pub mod either; | ||
10 | pub mod name; | 9 | pub mod name; |
11 | pub mod hygiene; | 10 | pub mod hygiene; |
12 | pub mod diagnostics; | 11 | pub mod diagnostics; |