mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Replace ra_hir_expand::either
with crate
This commit is contained in:
parent
15f143f0c3
commit
009437f5d9
23 changed files with 69 additions and 112 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,12 +2,12 @@
|
|||
//!
|
||||
//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
|
||||
//! this moment, this is horribly incomplete and handles only `$crate`.
|
||||
use either::Either;
|
||||
use ra_db::CrateId;
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{
|
||||
db::AstDatabase,
|
||||
either::Either,
|
||||
name::{AsName, Name},
|
||||
HirFileId, HirFileIdRepr, MacroDefKind,
|
||||
};
|
||||
|
@ -41,9 +41,9 @@ impl Hygiene {
|
|||
pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
|
||||
if let Some(def_crate) = self.def_crate {
|
||||
if name_ref.text() == "$crate" {
|
||||
return Either::B(def_crate);
|
||||
return Either::Right(def_crate);
|
||||
}
|
||||
}
|
||||
Either::A(name_ref.as_name())
|
||||
Either::Left(name_ref.as_name())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
pub mod db;
|
||||
pub mod ast_id_map;
|
||||
pub mod either;
|
||||
pub mod name;
|
||||
pub mod hygiene;
|
||||
pub mod diagnostics;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue