From b05d6e53fb0e9a008dc2e1220b1201818e63ed2d Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Wed, 30 Oct 2019 18:50:10 +0300
Subject: push either to hir_expand

---
 crates/ra_hir_def/src/either.rs      | 54 ------------------------------------
 crates/ra_hir_def/src/hygiene.rs     |  6 ++--
 crates/ra_hir_def/src/lib.rs         |  1 -
 crates/ra_hir_def/src/nameres/raw.rs | 11 +++-----
 crates/ra_hir_def/src/path.rs        |  2 +-
 5 files changed, 7 insertions(+), 67 deletions(-)
 delete mode 100644 crates/ra_hir_def/src/either.rs

(limited to 'crates/ra_hir_def')

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 @@
-//! FIXME: write short doc here
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub enum Either<A, B> {
-    A(A),
-    B(B),
-}
-
-impl<A, B> Either<A, B> {
-    pub fn either<R, F1, F2>(self, f1: F1, f2: F2) -> R
-    where
-        F1: FnOnce(A) -> R,
-        F2: FnOnce(B) -> R,
-    {
-        match self {
-            Either::A(a) => f1(a),
-            Either::B(b) => f2(b),
-        }
-    }
-    pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V>
-    where
-        F1: FnOnce(A) -> U,
-        F2: FnOnce(B) -> V,
-    {
-        match self {
-            Either::A(a) => Either::A(f1(a)),
-            Either::B(b) => Either::B(f2(b)),
-        }
-    }
-    pub fn map_a<U, F>(self, f: F) -> Either<U, B>
-    where
-        F: FnOnce(A) -> U,
-    {
-        self.map(f, |it| it)
-    }
-    pub fn a(self) -> Option<A> {
-        match self {
-            Either::A(it) => Some(it),
-            Either::B(_) => None,
-        }
-    }
-    pub fn b(self) -> Option<B> {
-        match self {
-            Either::A(_) => None,
-            Either::B(it) => Some(it),
-        }
-    }
-    pub fn as_ref(&self) -> Either<&A, &B> {
-        match self {
-            Either::A(it) => Either::A(it),
-            Either::B(it) => Either::B(it),
-        }
-    }
-}
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 @@
 //! this moment, this is horribly incomplete and handles only `$crate`.
 // Should this be moved to `hir_expand`? Seems like it.
 
+use hir_expand::either::Either;
 use hir_expand::{db::AstDatabase, HirFileId};
 use ra_db::CrateId;
 use ra_syntax::ast;
 
-use crate::{
-    either::Either,
-    name::{AsName, Name},
-};
+use crate::name::{AsName, Name};
 
 #[derive(Debug)]
 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 @@
 //! actually true.
 
 pub mod db;
-pub mod either;
 pub mod attr;
 pub mod name;
 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 @@
 
 use std::{ops::Index, sync::Arc};
 
-use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase};
+use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase, either::Either};
 use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
 use ra_syntax::{
     ast::{self, AttrsOwner, NameOwner},
@@ -12,7 +12,6 @@ use ra_syntax::{
 use crate::{
     attr::Attr,
     db::DefDatabase2,
-    either::Either,
     hygiene::Hygiene,
     name::{AsName, Name},
     path::Path,
@@ -41,10 +40,8 @@ pub struct ImportSourceMap {
 type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
 type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>;
 
-impl ImportSourcePtr {
-    fn to_node(self, file: &SourceFile) -> ImportSource {
-        self.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax()))
-    }
+fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource {
+    ptr.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax()))
 }
 
 impl ImportSourceMap {
@@ -58,7 +55,7 @@ impl ImportSourceMap {
             ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
         };
 
-        self.map[import].to_node(&file)
+        to_node(self.map[import], &file)
     }
 }
 
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 @@
 
 use std::{iter, sync::Arc};
 
+use hir_expand::either::Either;
 use ra_db::CrateId;
 use ra_syntax::{
     ast::{self, NameOwner, TypeAscriptionOwner},
@@ -9,7 +10,6 @@ use ra_syntax::{
 };
 
 use crate::{
-    either::Either,
     hygiene::Hygiene,
     name::{self, AsName, Name},
     type_ref::TypeRef,
-- 
cgit v1.2.3