From 009437f5d9949d2276aa26040e03af0ab328acf3 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 11:07:56 -0500 Subject: Replace `ra_hir_expand::either` with crate --- crates/ra_hir/Cargo.toml | 1 + crates/ra_hir/src/code_model.rs | 7 +++++-- crates/ra_hir/src/code_model/src.rs | 12 ++++++------ crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/source_binder.rs | 7 ++++--- 5 files changed, 17 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index e79361e7c..6ca9cc2e7 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml @@ -10,6 +10,7 @@ doctest = false [dependencies] log = "0.4.5" rustc-hash = "1.0" +either = "1.5" ra_syntax = { path = "../ra_syntax" } ra_db = { path = "../ra_db" } diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index dddac915b..5877afefa 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -4,6 +4,7 @@ pub(crate) mod src; use std::sync::Arc; +use either::Either; use hir_def::{ adt::VariantData, body::{Body, BodySourceMap}, @@ -30,7 +31,7 @@ use crate::{ db::{DefDatabase, HirDatabase}, ty::display::HirFormatter, ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, - CallableDef, Either, HirDisplay, InFile, Name, + CallableDef, HirDisplay, InFile, Name, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -905,7 +906,9 @@ impl Local { let (_body, source_map) = db.body_with_source_map(self.parent.into()); let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... let root = src.file_syntax(db); - src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) + src.map(|ast| { + ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root)) + }) } } diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 2cf210349..36cfbc8f1 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -1,10 +1,10 @@ //! FIXME: write short doc here +use either::Either; use hir_def::{ src::{HasChildSource, HasSource as _}, AstItemDef, Lookup, VariantId, }; -use hir_expand::either::Either; use ra_syntax::ast; use crate::{ @@ -27,8 +27,8 @@ impl Module { let def_map = db.crate_def_map(self.id.krate); let src = def_map[self.id.local_id].definition_source(db); src.map(|it| match it { - Either::A(it) => ModuleSource::SourceFile(it), - Either::B(it) => ModuleSource::Module(it), + Either::Left(it) => ModuleSource::SourceFile(it), + Either::Right(it) => ModuleSource::Module(it), }) } @@ -46,8 +46,8 @@ impl HasSource for StructField { let var = VariantId::from(self.parent); let src = var.child_source(db); src.map(|it| match it[self.id].clone() { - Either::A(it) => FieldSource::Pos(it), - Either::B(it) => FieldSource::Named(it), + Either::Left(it) => FieldSource::Pos(it), + Either::Right(it) => FieldSource::Named(it), }) } } @@ -126,6 +126,6 @@ impl HasSource for Import { let (_, source_map) = db.raw_items_with_source_map(src.file_id); let root = db.parse_or_expand(src.file_id).unwrap(); let ptr = source_map.get(self.id); - src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root))) + src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root))) } } diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 88d2f6e02..853760cb1 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -63,5 +63,5 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, + name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, }; diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 0df7a7cb4..28d41b647 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -7,6 +7,7 @@ //! purely for "IDE needs". use std::sync::Arc; +use either::Either; use hir_def::{ body::{ scope::{ExprScopes, ScopeId}, @@ -33,8 +34,8 @@ use crate::{ method_resolution::{self, implements_trait}, InEnvironment, TraitEnvironment, Ty, }, - Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, - GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, + Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam, + Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, }; fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option { @@ -349,7 +350,7 @@ impl SourceAnalyzer { // should switch to general reference search infra there. pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec { let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); - let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone()))); + let ptr = Either::Left(AstPtr::new(&ast::Pat::from(pat.clone()))); fn_def .syntax() .descendants() -- cgit v1.2.3