diff options
author | Aleksey Kladov <[email protected]> | 2019-10-30 15:50:10 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-30 15:50:10 +0000 |
commit | b05d6e53fb0e9a008dc2e1220b1201818e63ed2d (patch) | |
tree | b3207114d918b50b17adc1db589454fed266eed7 /crates/ra_hir_def/src | |
parent | 0bc7d285189caaffc13e4d6856baf895f72ed80c (diff) |
push either to hir_expand
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/either.rs | 54 | ||||
-rw-r--r-- | crates/ra_hir_def/src/hygiene.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 2 |
5 files changed, 7 insertions, 67 deletions
diff --git a/crates/ra_hir_def/src/either.rs b/crates/ra_hir_def/src/either.rs deleted file mode 100644 index 83583ef8b..000000000 --- a/crates/ra_hir_def/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_def/src/hygiene.rs b/crates/ra_hir_def/src/hygiene.rs index e1ae58a3b..f51c46fcb 100644 --- a/crates/ra_hir_def/src/hygiene.rs +++ b/crates/ra_hir_def/src/hygiene.rs | |||
@@ -4,14 +4,12 @@ | |||
4 | //! this moment, this is horribly incomplete and handles only `$crate`. | 4 | //! this moment, this is horribly incomplete and handles only `$crate`. |
5 | // Should this be moved to `hir_expand`? Seems like it. | 5 | // Should this be moved to `hir_expand`? Seems like it. |
6 | 6 | ||
7 | use hir_expand::either::Either; | ||
7 | use hir_expand::{db::AstDatabase, HirFileId}; | 8 | use hir_expand::{db::AstDatabase, HirFileId}; |
8 | use ra_db::CrateId; | 9 | use ra_db::CrateId; |
9 | use ra_syntax::ast; | 10 | use ra_syntax::ast; |
10 | 11 | ||
11 | use crate::{ | 12 | use crate::name::{AsName, Name}; |
12 | either::Either, | ||
13 | name::{AsName, Name}, | ||
14 | }; | ||
15 | 13 | ||
16 | #[derive(Debug)] | 14 | #[derive(Debug)] |
17 | pub struct Hygiene { | 15 | pub struct Hygiene { |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 61ccdb30d..0de728dc1 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -8,7 +8,6 @@ | |||
8 | //! actually true. | 8 | //! actually true. |
9 | 9 | ||
10 | pub mod db; | 10 | pub mod db; |
11 | pub mod either; | ||
12 | pub mod attr; | 11 | pub mod attr; |
13 | pub mod name; | 12 | pub mod name; |
14 | pub mod path; | 13 | pub mod path; |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 636364628..f1896c0cc 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::{ops::Index, sync::Arc}; | 3 | use std::{ops::Index, sync::Arc}; |
4 | 4 | ||
5 | use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase}; | 5 | use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase, either::Either}; |
6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | ast::{self, AttrsOwner, NameOwner}, | 8 | ast::{self, AttrsOwner, NameOwner}, |
@@ -12,7 +12,6 @@ use ra_syntax::{ | |||
12 | use crate::{ | 12 | use crate::{ |
13 | attr::Attr, | 13 | attr::Attr, |
14 | db::DefDatabase2, | 14 | db::DefDatabase2, |
15 | either::Either, | ||
16 | hygiene::Hygiene, | 15 | hygiene::Hygiene, |
17 | name::{AsName, Name}, | 16 | name::{AsName, Name}, |
18 | path::Path, | 17 | path::Path, |
@@ -41,10 +40,8 @@ pub struct ImportSourceMap { | |||
41 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | 40 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
42 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; | 41 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; |
43 | 42 | ||
44 | impl ImportSourcePtr { | 43 | fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource { |
45 | fn to_node(self, file: &SourceFile) -> ImportSource { | 44 | ptr.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) |
46 | self.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) | ||
47 | } | ||
48 | } | 45 | } |
49 | 46 | ||
50 | impl ImportSourceMap { | 47 | impl ImportSourceMap { |
@@ -58,7 +55,7 @@ impl ImportSourceMap { | |||
58 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), | 55 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), |
59 | }; | 56 | }; |
60 | 57 | ||
61 | self.map[import].to_node(&file) | 58 | to_node(self.map[import], &file) |
62 | } | 59 | } |
63 | } | 60 | } |
64 | 61 | ||
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 39f394c3f..8d57e7761 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use std::{iter, sync::Arc}; | 3 | use std::{iter, sync::Arc}; |
4 | 4 | ||
5 | use hir_expand::either::Either; | ||
5 | use ra_db::CrateId; | 6 | use ra_db::CrateId; |
6 | use ra_syntax::{ | 7 | use ra_syntax::{ |
7 | ast::{self, NameOwner, TypeAscriptionOwner}, | 8 | ast::{self, NameOwner, TypeAscriptionOwner}, |
@@ -9,7 +10,6 @@ use ra_syntax::{ | |||
9 | }; | 10 | }; |
10 | 11 | ||
11 | use crate::{ | 12 | use crate::{ |
12 | either::Either, | ||
13 | hygiene::Hygiene, | 13 | hygiene::Hygiene, |
14 | name::{self, AsName, Name}, | 14 | name::{self, AsName, Name}, |
15 | type_ref::TypeRef, | 15 | type_ref::TypeRef, |