aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorice1000 <[email protected]>2019-12-03 16:07:56 +0000
committerice1000 <[email protected]>2019-12-03 16:07:56 +0000
commit009437f5d9949d2276aa26040e03af0ab328acf3 (patch)
tree74a889d70e201d6997c6baf179261ab3ed8bf23c
parent15f143f0c33cbd382a2ad7a407d9601cb843d164 (diff)
Replace `ra_hir_expand::either` with crate
-rw-r--r--Cargo.lock4
-rw-r--r--crates/ra_hir/Cargo.toml1
-rw-r--r--crates/ra_hir/src/code_model.rs7
-rw-r--r--crates/ra_hir/src/code_model/src.rs12
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs7
-rw-r--r--crates/ra_hir_def/Cargo.toml1
-rw-r--r--crates/ra_hir_def/src/adt.rs6
-rw-r--r--crates/ra_hir_def/src/attr.rs7
-rw-r--r--crates/ra_hir_def/src/body.rs9
-rw-r--r--crates/ra_hir_def/src/body/lower.rs16
-rw-r--r--crates/ra_hir_def/src/docs.rs6
-rw-r--r--crates/ra_hir_def/src/nameres.rs8
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs6
-rw-r--r--crates/ra_hir_def/src/path.rs10
-rw-r--r--crates/ra_hir_expand/Cargo.toml1
-rw-r--r--crates/ra_hir_expand/src/either.rs54
-rw-r--r--crates/ra_hir_expand/src/hygiene.rs6
-rw-r--r--crates/ra_hir_expand/src/lib.rs1
-rw-r--r--crates/ra_hir_ty/src/expr.rs4
-rw-r--r--crates/ra_ide/Cargo.toml1
-rw-r--r--crates/ra_ide/src/completion/complete_path.rs5
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs7
23 files changed, 69 insertions, 112 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 57cfde978..23c9e2543 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -944,6 +944,7 @@ dependencies = [
944name = "ra_hir" 944name = "ra_hir"
945version = "0.1.0" 945version = "0.1.0"
946dependencies = [ 946dependencies = [
947 "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
947 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 948 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
948 "ra_db 0.1.0", 949 "ra_db 0.1.0",
949 "ra_hir_def 0.1.0", 950 "ra_hir_def 0.1.0",
@@ -957,6 +958,7 @@ dependencies = [
957name = "ra_hir_def" 958name = "ra_hir_def"
958version = "0.1.0" 959version = "0.1.0"
959dependencies = [ 960dependencies = [
961 "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
960 "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 962 "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
961 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 963 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
962 "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 964 "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -976,6 +978,7 @@ dependencies = [
976name = "ra_hir_expand" 978name = "ra_hir_expand"
977version = "0.1.0" 979version = "0.1.0"
978dependencies = [ 980dependencies = [
981 "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
979 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 982 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
980 "ra_arena 0.1.0", 983 "ra_arena 0.1.0",
981 "ra_db 0.1.0", 984 "ra_db 0.1.0",
@@ -1012,6 +1015,7 @@ dependencies = [
1012name = "ra_ide" 1015name = "ra_ide"
1013version = "0.1.0" 1016version = "0.1.0"
1014dependencies = [ 1017dependencies = [
1018 "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
1015 "format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 1019 "format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
1016 "fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 1020 "fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
1017 "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 1021 "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
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
10[dependencies] 10[dependencies]
11log = "0.4.5" 11log = "0.4.5"
12rustc-hash = "1.0" 12rustc-hash = "1.0"
13either = "1.5"
13 14
14ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
15ra_db = { path = "../ra_db" } 16ra_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;
4 4
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use either::Either;
7use hir_def::{ 8use hir_def::{
8 adt::VariantData, 9 adt::VariantData,
9 body::{Body, BodySourceMap}, 10 body::{Body, BodySourceMap},
@@ -30,7 +31,7 @@ use crate::{
30 db::{DefDatabase, HirDatabase}, 31 db::{DefDatabase, HirDatabase},
31 ty::display::HirFormatter, 32 ty::display::HirFormatter,
32 ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, 33 ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
33 CallableDef, Either, HirDisplay, InFile, Name, 34 CallableDef, HirDisplay, InFile, Name,
34}; 35};
35 36
36/// hir::Crate describes a single crate. It's the main interface with which 37/// hir::Crate describes a single crate. It's the main interface with which
@@ -905,7 +906,9 @@ impl Local {
905 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 906 let (_body, source_map) = db.body_with_source_map(self.parent.into());
906 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... 907 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
907 let root = src.file_syntax(db); 908 let root = src.file_syntax(db);
908 src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) 909 src.map(|ast| {
910 ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root))
911 })
909 } 912 }
910} 913}
911 914
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 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use either::Either;
3use hir_def::{ 4use hir_def::{
4 src::{HasChildSource, HasSource as _}, 5 src::{HasChildSource, HasSource as _},
5 AstItemDef, Lookup, VariantId, 6 AstItemDef, Lookup, VariantId,
6}; 7};
7use hir_expand::either::Either;
8use ra_syntax::ast; 8use ra_syntax::ast;
9 9
10use crate::{ 10use crate::{
@@ -27,8 +27,8 @@ impl Module {
27 let def_map = db.crate_def_map(self.id.krate); 27 let def_map = db.crate_def_map(self.id.krate);
28 let src = def_map[self.id.local_id].definition_source(db); 28 let src = def_map[self.id.local_id].definition_source(db);
29 src.map(|it| match it { 29 src.map(|it| match it {
30 Either::A(it) => ModuleSource::SourceFile(it), 30 Either::Left(it) => ModuleSource::SourceFile(it),
31 Either::B(it) => ModuleSource::Module(it), 31 Either::Right(it) => ModuleSource::Module(it),
32 }) 32 })
33 } 33 }
34 34
@@ -46,8 +46,8 @@ impl HasSource for StructField {
46 let var = VariantId::from(self.parent); 46 let var = VariantId::from(self.parent);
47 let src = var.child_source(db); 47 let src = var.child_source(db);
48 src.map(|it| match it[self.id].clone() { 48 src.map(|it| match it[self.id].clone() {
49 Either::A(it) => FieldSource::Pos(it), 49 Either::Left(it) => FieldSource::Pos(it),
50 Either::B(it) => FieldSource::Named(it), 50 Either::Right(it) => FieldSource::Named(it),
51 }) 51 })
52 } 52 }
53} 53}
@@ -126,6 +126,6 @@ impl HasSource for Import {
126 let (_, source_map) = db.raw_items_with_source_map(src.file_id); 126 let (_, source_map) = db.raw_items_with_source_map(src.file_id);
127 let root = db.parse_or_expand(src.file_id).unwrap(); 127 let root = db.parse_or_expand(src.file_id).unwrap();
128 let ptr = source_map.get(self.id); 128 let ptr = source_map.get(self.id);
129 src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root))) 129 src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root)))
130 } 130 }
131} 131}
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::{
63 type_ref::Mutability, 63 type_ref::Mutability,
64}; 64};
65pub use hir_expand::{ 65pub use hir_expand::{
66 either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, 66 name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
67}; 67};
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 @@
7//! purely for "IDE needs". 7//! purely for "IDE needs".
8use std::sync::Arc; 8use std::sync::Arc;
9 9
10use either::Either;
10use hir_def::{ 11use hir_def::{
11 body::{ 12 body::{
12 scope::{ExprScopes, ScopeId}, 13 scope::{ExprScopes, ScopeId},
@@ -33,8 +34,8 @@ use crate::{
33 method_resolution::{self, implements_trait}, 34 method_resolution::{self, implements_trait},
34 InEnvironment, TraitEnvironment, Ty, 35 InEnvironment, TraitEnvironment, Ty,
35 }, 36 },
36 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 37 Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam,
37 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, 38 Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
38}; 39};
39 40
40fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { 41fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
@@ -349,7 +350,7 @@ impl SourceAnalyzer {
349 // should switch to general reference search infra there. 350 // should switch to general reference search infra there.
350 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { 351 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
351 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); 352 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
352 let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone()))); 353 let ptr = Either::Left(AstPtr::new(&ast::Pat::from(pat.clone())));
353 fn_def 354 fn_def
354 .syntax() 355 .syntax()
355 .descendants() 356 .descendants()
diff --git a/crates/ra_hir_def/Cargo.toml b/crates/ra_hir_def/Cargo.toml
index 7e65f4c1d..cf3a446fc 100644
--- a/crates/ra_hir_def/Cargo.toml
+++ b/crates/ra_hir_def/Cargo.toml
@@ -11,6 +11,7 @@ doctest = false
11log = "0.4.5" 11log = "0.4.5"
12once_cell = "1.0.1" 12once_cell = "1.0.1"
13rustc-hash = "1.0" 13rustc-hash = "1.0"
14either = "1.5"
14 15
15ra_arena = { path = "../ra_arena" } 16ra_arena = { path = "../ra_arena" }
16ra_db = { path = "../ra_db" } 17ra_db = { path = "../ra_db" }
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 9ab829aab..db3e63ef8 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -2,8 +2,8 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use either::Either;
5use hir_expand::{ 6use hir_expand::{
6 either::Either,
7 name::{AsName, Name}, 7 name::{AsName, Name},
8 InFile, 8 InFile,
9}; 9};
@@ -184,7 +184,7 @@ fn lower_struct(
184 ast::StructKind::Tuple(fl) => { 184 ast::StructKind::Tuple(fl) => {
185 for (i, fd) in fl.fields().enumerate() { 185 for (i, fd) in fl.fields().enumerate() {
186 trace.alloc( 186 trace.alloc(
187 || Either::A(fd.clone()), 187 || Either::Left(fd.clone()),
188 || StructFieldData { 188 || StructFieldData {
189 name: Name::new_tuple_field(i), 189 name: Name::new_tuple_field(i),
190 type_ref: TypeRef::from_ast_opt(fd.type_ref()), 190 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
@@ -196,7 +196,7 @@ fn lower_struct(
196 ast::StructKind::Record(fl) => { 196 ast::StructKind::Record(fl) => {
197 for fd in fl.fields() { 197 for fd in fl.fields() {
198 trace.alloc( 198 trace.alloc(
199 || Either::B(fd.clone()), 199 || Either::Right(fd.clone()),
200 || StructFieldData { 200 || StructFieldData {
201 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 201 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
202 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), 202 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index bc7ade921..7f9a6e7ca 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -2,7 +2,8 @@
2 2
3use std::{ops, sync::Arc}; 3use std::{ops, sync::Arc};
4 4
5use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile}; 5use either::Either;
6use hir_expand::{hygiene::Hygiene, AstId, InFile};
6use mbe::ast_to_token_tree; 7use mbe::ast_to_token_tree;
7use ra_syntax::{ 8use ra_syntax::{
8 ast::{self, AstNode, AttrsOwner}, 9 ast::{self, AstNode, AttrsOwner},
@@ -45,8 +46,8 @@ impl Attrs {
45 AttrDefId::StructFieldId(it) => { 46 AttrDefId::StructFieldId(it) => {
46 let src = it.parent.child_source(db); 47 let src = it.parent.child_source(db);
47 match &src.value[it.local_id] { 48 match &src.value[it.local_id] {
48 Either::A(_tuple) => Attrs::default(), 49 Either::Left(_tuple) => Attrs::default(),
49 Either::B(record) => Attrs::from_attrs_owner(db, src.with_value(record)), 50 Either::Right(record) => Attrs::from_attrs_owner(db, src.with_value(record)),
50 } 51 }
51 } 52 }
52 AttrDefId::EnumVariantId(var_id) => { 53 AttrDefId::EnumVariantId(var_id) => {
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 239f35229..ef1816836 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -5,9 +5,8 @@ pub mod scope;
5 5
6use std::{ops::Index, sync::Arc}; 6use std::{ops::Index, sync::Arc};
7 7
8use hir_expand::{ 8use either::Either;
9 either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind, 9use hir_expand::{hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind};
10};
11use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
12use ra_syntax::{ast, AstNode, AstPtr}; 11use ra_syntax::{ast, AstNode, AstPtr};
13use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
@@ -210,7 +209,7 @@ impl BodySourceMap {
210 } 209 }
211 210
212 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { 211 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
213 let src = node.map(|it| Either::A(AstPtr::new(it))); 212 let src = node.map(|it| Either::Left(AstPtr::new(it)));
214 self.expr_map.get(&src).cloned() 213 self.expr_map.get(&src).cloned()
215 } 214 }
216 215
@@ -219,7 +218,7 @@ impl BodySourceMap {
219 } 218 }
220 219
221 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { 220 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
222 let src = node.map(|it| Either::A(AstPtr::new(it))); 221 let src = node.map(|it| Either::Left(AstPtr::new(it)));
223 self.pat_map.get(&src).cloned() 222 self.pat_map.get(&src).cloned()
224 } 223 }
225 224
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index be1eaa523..71c08f024 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -1,10 +1,8 @@
1//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` 1//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
2//! representation. 2//! representation.
3 3
4use hir_expand::{ 4use either::Either;
5 either::Either, 5use hir_expand::name::{self, AsName, Name};
6 name::{self, AsName, Name},
7};
8use ra_arena::Arena; 6use ra_arena::Arena;
9use ra_syntax::{ 7use ra_syntax::{
10 ast::{ 8 ast::{
@@ -74,7 +72,7 @@ where
74 mode: BindingAnnotation::Unannotated, 72 mode: BindingAnnotation::Unannotated,
75 subpat: None, 73 subpat: None,
76 }, 74 },
77 Either::B(ptr), 75 Either::Right(ptr),
78 ); 76 );
79 self.body.params.push(param_pat); 77 self.body.params.push(param_pat);
80 } 78 }
@@ -94,7 +92,7 @@ where
94 } 92 }
95 93
96 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { 94 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
97 let ptr = Either::A(ptr); 95 let ptr = Either::Left(ptr);
98 let id = self.body.exprs.alloc(expr); 96 let id = self.body.exprs.alloc(expr);
99 let src = self.expander.to_source(ptr); 97 let src = self.expander.to_source(ptr);
100 self.source_map.expr_map.insert(src, id); 98 self.source_map.expr_map.insert(src, id);
@@ -107,7 +105,7 @@ where
107 self.body.exprs.alloc(expr) 105 self.body.exprs.alloc(expr)
108 } 106 }
109 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { 107 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
110 let ptr = Either::B(ptr); 108 let ptr = Either::Right(ptr);
111 let id = self.body.exprs.alloc(expr); 109 let id = self.body.exprs.alloc(expr);
112 let src = self.expander.to_source(ptr); 110 let src = self.expander.to_source(ptr);
113 self.source_map.expr_map.insert(src, id); 111 self.source_map.expr_map.insert(src, id);
@@ -277,7 +275,7 @@ where
277 ast::Expr::ParenExpr(e) => { 275 ast::Expr::ParenExpr(e) => {
278 let inner = self.collect_expr_opt(e.expr()); 276 let inner = self.collect_expr_opt(e.expr());
279 // make the paren expr point to the inner expression as well 277 // make the paren expr point to the inner expression as well
280 let src = self.expander.to_source(Either::A(syntax_ptr)); 278 let src = self.expander.to_source(Either::Left(syntax_ptr));
281 self.source_map.expr_map.insert(src, inner); 279 self.source_map.expr_map.insert(src, inner);
282 inner 280 inner
283 } 281 }
@@ -550,7 +548,7 @@ where
550 ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing, 548 ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,
551 }; 549 };
552 let ptr = AstPtr::new(&pat); 550 let ptr = AstPtr::new(&pat);
553 self.alloc_pat(pattern, Either::A(ptr)) 551 self.alloc_pat(pattern, Either::Left(ptr))
554 } 552 }
555 553
556 fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId { 554 fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index ec944373d..3fc6d6934 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -5,7 +5,7 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_expand::either::Either; 8use either::Either;
9use ra_syntax::ast; 9use ra_syntax::ast;
10 10
11use crate::{ 11use crate::{
@@ -46,8 +46,8 @@ impl Documentation {
46 AttrDefId::StructFieldId(it) => { 46 AttrDefId::StructFieldId(it) => {
47 let src = it.parent.child_source(db); 47 let src = it.parent.child_source(db);
48 match &src.value[it.local_id] { 48 match &src.value[it.local_id] {
49 Either::A(_tuple) => None, 49 Either::Left(_tuple) => None,
50 Either::B(record) => docs_from_ast(record), 50 Either::Right(record) => docs_from_ast(record),
51 } 51 }
52 } 52 }
53 AttrDefId::AdtId(it) => match it { 53 AttrDefId::AdtId(it) => match it {
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 3e1521870..faf3566f4 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -57,9 +57,9 @@ mod tests;
57 57
58use std::sync::Arc; 58use std::sync::Arc;
59 59
60use either::Either;
60use hir_expand::{ 61use hir_expand::{
61 ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile, 62 ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId,
62 MacroDefId,
63}; 63};
64use once_cell::sync::Lazy; 64use once_cell::sync::Lazy;
65use ra_arena::Arena; 65use ra_arena::Arena;
@@ -287,10 +287,10 @@ impl ModuleData {
287 ) -> InFile<Either<ast::SourceFile, ast::Module>> { 287 ) -> InFile<Either<ast::SourceFile, ast::Module>> {
288 if let Some(file_id) = self.definition { 288 if let Some(file_id) = self.definition {
289 let sf = db.parse(file_id).tree(); 289 let sf = db.parse(file_id).tree();
290 return InFile::new(file_id.into(), Either::A(sf)); 290 return InFile::new(file_id.into(), Either::Left(sf));
291 } 291 }
292 let decl = self.declaration.unwrap(); 292 let decl = self.declaration.unwrap();
293 InFile::new(decl.file_id, Either::B(decl.to_node(db))) 293 InFile::new(decl.file_id, Either::Right(decl.to_node(db)))
294 } 294 }
295 295
296 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. 296 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 5196b67ca..de4e706c2 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -7,10 +7,10 @@
7 7
8use std::{ops::Index, sync::Arc}; 8use std::{ops::Index, sync::Arc};
9 9
10use either::Either;
10use hir_expand::{ 11use hir_expand::{
11 ast_id_map::AstIdMap, 12 ast_id_map::AstIdMap,
12 db::AstDatabase, 13 db::AstDatabase,
13 either::Either,
14 hygiene::Hygiene, 14 hygiene::Hygiene,
15 name::{AsName, Name}, 15 name::{AsName, Name},
16}; 16};
@@ -324,7 +324,7 @@ impl RawItemsCollector {
324 is_extern_crate: false, 324 is_extern_crate: false,
325 is_macro_use: false, 325 is_macro_use: false,
326 }; 326 };
327 buf.push((import_data, Either::A(AstPtr::new(use_tree)))); 327 buf.push((import_data, Either::Left(AstPtr::new(use_tree))));
328 }, 328 },
329 ); 329 );
330 for (import_data, ptr) in buf { 330 for (import_data, ptr) in buf {
@@ -355,7 +355,7 @@ impl RawItemsCollector {
355 current_module, 355 current_module,
356 attrs, 356 attrs,
357 import_data, 357 import_data,
358 Either::B(AstPtr::new(&extern_crate)), 358 Either::Right(AstPtr::new(&extern_crate)),
359 ); 359 );
360 } 360 }
361 } 361 }
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index ff252fe44..3030dcdf6 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -2,8 +2,8 @@
2 2
3use std::{iter, sync::Arc}; 3use std::{iter, sync::Arc};
4 4
5use either::Either;
5use hir_expand::{ 6use hir_expand::{
6 either::Either,
7 hygiene::Hygiene, 7 hygiene::Hygiene,
8 name::{self, AsName, Name}, 8 name::{self, AsName, Name},
9}; 9};
@@ -111,7 +111,7 @@ impl Path {
111 ast::PathSegmentKind::Name(name_ref) => { 111 ast::PathSegmentKind::Name(name_ref) => {
112 // FIXME: this should just return name 112 // FIXME: this should just return name
113 match hygiene.name_ref_to_name(name_ref) { 113 match hygiene.name_ref_to_name(name_ref) {
114 Either::A(name) => { 114 Either::Left(name) => {
115 let args = segment 115 let args = segment
116 .type_arg_list() 116 .type_arg_list()
117 .and_then(GenericArgs::from_ast) 117 .and_then(GenericArgs::from_ast)
@@ -125,7 +125,7 @@ impl Path {
125 let segment = PathSegment { name, args_and_bindings: args }; 125 let segment = PathSegment { name, args_and_bindings: args };
126 segments.push(segment); 126 segments.push(segment);
127 } 127 }
128 Either::B(crate_id) => { 128 Either::Right(crate_id) => {
129 kind = PathKind::DollarCrate(crate_id); 129 kind = PathKind::DollarCrate(crate_id);
130 break; 130 break;
131 } 131 }
@@ -347,7 +347,7 @@ fn convert_path(prefix: Option<Path>, path: ast::Path, hygiene: &Hygiene) -> Opt
347 let res = match segment.kind()? { 347 let res = match segment.kind()? {
348 ast::PathSegmentKind::Name(name_ref) => { 348 ast::PathSegmentKind::Name(name_ref) => {
349 match hygiene.name_ref_to_name(name_ref) { 349 match hygiene.name_ref_to_name(name_ref) {
350 Either::A(name) => { 350 Either::Left(name) => {
351 // no type args in use 351 // no type args in use
352 let mut res = prefix.unwrap_or_else(|| Path { 352 let mut res = prefix.unwrap_or_else(|| Path {
353 kind: PathKind::Plain, 353 kind: PathKind::Plain,
@@ -359,7 +359,7 @@ fn convert_path(prefix: Option<Path>, path: ast::Path, hygiene: &Hygiene) -> Opt
359 }); 359 });
360 res 360 res
361 } 361 }
362 Either::B(crate_id) => { 362 Either::Right(crate_id) => {
363 return Some(Path::from_simple_segments( 363 return Some(Path::from_simple_segments(
364 PathKind::DollarCrate(crate_id), 364 PathKind::DollarCrate(crate_id),
365 iter::empty(), 365 iter::empty(),
diff --git a/crates/ra_hir_expand/Cargo.toml b/crates/ra_hir_expand/Cargo.toml
index c60152a79..3ae4376dc 100644
--- a/crates/ra_hir_expand/Cargo.toml
+++ b/crates/ra_hir_expand/Cargo.toml
@@ -9,6 +9,7 @@ doctest = false
9 9
10[dependencies] 10[dependencies]
11log = "0.4.5" 11log = "0.4.5"
12either = "1.5"
12 13
13ra_arena = { path = "../ra_arena" } 14ra_arena = { path = "../ra_arena" }
14ra_db = { path = "../ra_db" } 15ra_db = { path = "../ra_db" }
diff --git a/crates/ra_hir_expand/src/either.rs b/crates/ra_hir_expand/src/either.rs
deleted file mode 100644
index 83583ef8b..000000000
--- a/crates/ra_hir_expand/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_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs
index 379562a2c..64c8b06c6 100644
--- a/crates/ra_hir_expand/src/hygiene.rs
+++ b/crates/ra_hir_expand/src/hygiene.rs
@@ -2,12 +2,12 @@
2//! 2//!
3//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at 3//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
4//! this moment, this is horribly incomplete and handles only `$crate`. 4//! this moment, this is horribly incomplete and handles only `$crate`.
5use either::Either;
5use ra_db::CrateId; 6use ra_db::CrateId;
6use ra_syntax::ast; 7use ra_syntax::ast;
7 8
8use crate::{ 9use crate::{
9 db::AstDatabase, 10 db::AstDatabase,
10 either::Either,
11 name::{AsName, Name}, 11 name::{AsName, Name},
12 HirFileId, HirFileIdRepr, MacroDefKind, 12 HirFileId, HirFileIdRepr, MacroDefKind,
13}; 13};
@@ -41,9 +41,9 @@ impl Hygiene {
41 pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { 41 pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
42 if let Some(def_crate) = self.def_crate { 42 if let Some(def_crate) = self.def_crate {
43 if name_ref.text() == "$crate" { 43 if name_ref.text() == "$crate" {
44 return Either::B(def_crate); 44 return Either::Right(def_crate);
45 } 45 }
46 } 46 }
47 Either::A(name_ref.as_name()) 47 Either::Left(name_ref.as_name())
48 } 48 }
49} 49}
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index fb88d2ac2..3be9bdf86 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -6,7 +6,6 @@
6 6
7pub mod db; 7pub mod db;
8pub mod ast_id_map; 8pub mod ast_id_map;
9pub mod either;
10pub mod name; 9pub mod name;
11pub mod hygiene; 10pub mod hygiene;
12pub mod diagnostics; 11pub mod diagnostics;
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 5c65f9370..d2bd64e5c 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -97,7 +97,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
97 let (_, source_map) = db.body_with_source_map(self.func.into()); 97 let (_, source_map) = db.body_with_source_map(self.func.into());
98 98
99 if let Some(source_ptr) = source_map.expr_syntax(id) { 99 if let Some(source_ptr) = source_map.expr_syntax(id) {
100 if let Some(expr) = source_ptr.value.a() { 100 if let Some(expr) = source_ptr.value.left() {
101 let root = source_ptr.file_syntax(db); 101 let root = source_ptr.file_syntax(db);
102 if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { 102 if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) {
103 if let Some(field_list) = record_lit.record_field_list() { 103 if let Some(field_list) = record_lit.record_field_list() {
@@ -142,7 +142,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
142 let (_, source_map) = db.body_with_source_map(self.func.into()); 142 let (_, source_map) = db.body_with_source_map(self.func.into());
143 143
144 if let Some(source_ptr) = source_map.expr_syntax(id) { 144 if let Some(source_ptr) = source_map.expr_syntax(id) {
145 if let Some(expr) = source_ptr.value.a() { 145 if let Some(expr) = source_ptr.value.left() {
146 self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); 146 self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr });
147 } 147 }
148 } 148 }
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index e6383dd35..e3439ae31 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -11,6 +11,7 @@ doctest = false
11wasm = [] 11wasm = []
12 12
13[dependencies] 13[dependencies]
14either = "1.5"
14format-buf = "1.0.0" 15format-buf = "1.0.0"
15itertools = "0.8.0" 16itertools = "0.8.0"
16join_to_string = "0.1.3" 17join_to_string = "0.1.3"
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs
index 89e0009a1..28f94e0a7 100644
--- a/crates/ra_ide/src/completion/complete_path.rs
+++ b/crates/ra_ide/src/completion/complete_path.rs
@@ -1,6 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{Adt, Either, HasSource, PathResolution}; 3use either::Either;
4use hir::{Adt, HasSource, PathResolution};
4use ra_syntax::AstNode; 5use ra_syntax::AstNode;
5use test_utils::tested_by; 6use test_utils::tested_by;
6 7
@@ -27,7 +28,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
27 } 28 }
28 if Some(module) == ctx.module { 29 if Some(module) == ctx.module {
29 if let Some(import) = import { 30 if let Some(import) = import {
30 if let Either::A(use_tree) = import.source(ctx.db).value { 31 if let Either::Left(use_tree) = import.source(ctx.db).value {
31 if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { 32 if use_tree.syntax().text_range().contains_inclusive(ctx.offset) {
32 // for `use self::foo<|>`, don't suggest `foo` as a completion 33 // for `use self::foo<|>`, don't suggest `foo` as a completion
33 tested_by!(dont_complete_current_use); 34 tested_by!(dont_complete_current_use);
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 61dca14ac..f920d3db6 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -1,6 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource}; 3use either::Either;
4use hir::{AssocItem, FieldSource, HasSource, InFile, ModuleSource};
4use ra_db::{FileId, SourceDatabase}; 5use ra_db::{FileId, SourceDatabase};
5use ra_syntax::{ 6use ra_syntax::{
6 ast::{self, DocCommentsOwner, NameOwner}, 7 ast::{self, DocCommentsOwner, NameOwner},
@@ -342,10 +343,10 @@ impl ToNav for hir::Local {
342 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 343 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
343 let src = self.source(db); 344 let src = self.source(db);
344 let (full_range, focus_range) = match src.value { 345 let (full_range, focus_range) = match src.value {
345 Either::A(it) => { 346 Either::Left(it) => {
346 (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) 347 (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
347 } 348 }
348 Either::B(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())), 349 Either::Right(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())),
349 }; 350 };
350 let name = match self.name(db) { 351 let name = match self.name(db) {
351 Some(it) => it.to_string().into(), 352 Some(it) => it.to_string().into(),