aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/either.rs54
-rw-r--r--crates/ra_hir_def/src/hygiene.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs1
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs11
-rw-r--r--crates/ra_hir_def/src/path.rs2
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)]
4pub enum Either<A, B> {
5 A(A),
6 B(B),
7}
8
9impl<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
7use hir_expand::either::Either;
7use hir_expand::{db::AstDatabase, HirFileId}; 8use hir_expand::{db::AstDatabase, HirFileId};
8use ra_db::CrateId; 9use ra_db::CrateId;
9use ra_syntax::ast; 10use ra_syntax::ast;
10 11
11use crate::{ 12use crate::name::{AsName, Name};
12 either::Either,
13 name::{AsName, Name},
14};
15 13
16#[derive(Debug)] 14#[derive(Debug)]
17pub struct Hygiene { 15pub 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
10pub mod db; 10pub mod db;
11pub mod either;
12pub mod attr; 11pub mod attr;
13pub mod name; 12pub mod name;
14pub mod path; 13pub 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
3use std::{ops::Index, sync::Arc}; 3use std::{ops::Index, sync::Arc};
4 4
5use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase}; 5use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase, either::Either};
6use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 6use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
7use ra_syntax::{ 7use ra_syntax::{
8 ast::{self, AttrsOwner, NameOwner}, 8 ast::{self, AttrsOwner, NameOwner},
@@ -12,7 +12,6 @@ use ra_syntax::{
12use crate::{ 12use 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 {
41type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; 40type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
42type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; 41type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>;
43 42
44impl ImportSourcePtr { 43fn 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
50impl ImportSourceMap { 47impl 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
3use std::{iter, sync::Arc}; 3use std::{iter, sync::Arc};
4 4
5use hir_expand::either::Either;
5use ra_db::CrateId; 6use ra_db::CrateId;
6use ra_syntax::{ 7use ra_syntax::{
7 ast::{self, NameOwner, TypeAscriptionOwner}, 8 ast::{self, NameOwner, TypeAscriptionOwner},
@@ -9,7 +10,6 @@ use ra_syntax::{
9}; 10};
10 11
11use crate::{ 12use 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,