Skip to content

Commit 96b9d5b

Browse files
bors[bot]ice1000
andauthored
Merge #2469
2469: Replace `ra_hir_expand::either` with crate r=matklad a=ice1000 As title. Co-authored-by: ice1000 <ice1000kotlin@foxmail.com>
2 parents 15f143f + 009437f commit 96b9d5b

File tree

23 files changed

+69
-112
lines changed

23 files changed

+69
-112
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_hir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ doctest = false
1010
[dependencies]
1111
log = "0.4.5"
1212
rustc-hash = "1.0"
13+
either = "1.5"
1314

1415
ra_syntax = { path = "../ra_syntax" }
1516
ra_db = { path = "../ra_db" }

crates/ra_hir/src/code_model.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub(crate) mod src;
44

55
use std::sync::Arc;
66

7+
use either::Either;
78
use hir_def::{
89
adt::VariantData,
910
body::{Body, BodySourceMap},
@@ -30,7 +31,7 @@ use crate::{
3031
db::{DefDatabase, HirDatabase},
3132
ty::display::HirFormatter,
3233
ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
33-
CallableDef, Either, HirDisplay, InFile, Name,
34+
CallableDef, HirDisplay, InFile, Name,
3435
};
3536

3637
/// hir::Crate describes a single crate. It's the main interface with which
@@ -905,7 +906,9 @@ impl Local {
905906
let (_body, source_map) = db.body_with_source_map(self.parent.into());
906907
let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
907908
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+
})
909912
}
910913
}
911914

crates/ra_hir/src/code_model/src.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! FIXME: write short doc here
22
3+
use either::Either;
34
use hir_def::{
45
src::{HasChildSource, HasSource as _},
56
AstItemDef, Lookup, VariantId,
67
};
7-
use hir_expand::either::Either;
88
use ra_syntax::ast;
99

1010
use crate::{
@@ -27,8 +27,8 @@ impl Module {
2727
let def_map = db.crate_def_map(self.id.krate);
2828
let src = def_map[self.id.local_id].definition_source(db);
2929
src.map(|it| match it {
30-
Either::A(it) => ModuleSource::SourceFile(it),
31-
Either::B(it) => ModuleSource::Module(it),
30+
Either::Left(it) => ModuleSource::SourceFile(it),
31+
Either::Right(it) => ModuleSource::Module(it),
3232
})
3333
}
3434

@@ -46,8 +46,8 @@ impl HasSource for StructField {
4646
let var = VariantId::from(self.parent);
4747
let src = var.child_source(db);
4848
src.map(|it| match it[self.id].clone() {
49-
Either::A(it) => FieldSource::Pos(it),
50-
Either::B(it) => FieldSource::Named(it),
49+
Either::Left(it) => FieldSource::Pos(it),
50+
Either::Right(it) => FieldSource::Named(it),
5151
})
5252
}
5353
}
@@ -126,6 +126,6 @@ impl HasSource for Import {
126126
let (_, source_map) = db.raw_items_with_source_map(src.file_id);
127127
let root = db.parse_or_expand(src.file_id).unwrap();
128128
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)))
130130
}
131131
}

crates/ra_hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ pub use hir_def::{
6363
type_ref::Mutability,
6464
};
6565
pub use hir_expand::{
66-
either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
66+
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
6767
};

crates/ra_hir/src/source_binder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! purely for "IDE needs".
88
use std::sync::Arc;
99

10+
use either::Either;
1011
use hir_def::{
1112
body::{
1213
scope::{ExprScopes, ScopeId},
@@ -33,8 +34,8 @@ use crate::{
3334
method_resolution::{self, implements_trait},
3435
InEnvironment, TraitEnvironment, Ty,
3536
},
36-
Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
37-
GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
37+
Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam,
38+
Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
3839
};
3940

4041
fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
@@ -349,7 +350,7 @@ impl SourceAnalyzer {
349350
// should switch to general reference search infra there.
350351
pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
351352
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())));
353354
fn_def
354355
.syntax()
355356
.descendants()

crates/ra_hir_def/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ doctest = false
1111
log = "0.4.5"
1212
once_cell = "1.0.1"
1313
rustc-hash = "1.0"
14+
either = "1.5"
1415

1516
ra_arena = { path = "../ra_arena" }
1617
ra_db = { path = "../ra_db" }

crates/ra_hir_def/src/adt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use std::sync::Arc;
44

5+
use either::Either;
56
use hir_expand::{
6-
either::Either,
77
name::{AsName, Name},
88
InFile,
99
};
@@ -184,7 +184,7 @@ fn lower_struct(
184184
ast::StructKind::Tuple(fl) => {
185185
for (i, fd) in fl.fields().enumerate() {
186186
trace.alloc(
187-
|| Either::A(fd.clone()),
187+
|| Either::Left(fd.clone()),
188188
|| StructFieldData {
189189
name: Name::new_tuple_field(i),
190190
type_ref: TypeRef::from_ast_opt(fd.type_ref()),
@@ -196,7 +196,7 @@ fn lower_struct(
196196
ast::StructKind::Record(fl) => {
197197
for fd in fl.fields() {
198198
trace.alloc(
199-
|| Either::B(fd.clone()),
199+
|| Either::Right(fd.clone()),
200200
|| StructFieldData {
201201
name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
202202
type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),

crates/ra_hir_def/src/attr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use std::{ops, sync::Arc};
44

5-
use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile};
5+
use either::Either;
6+
use hir_expand::{hygiene::Hygiene, AstId, InFile};
67
use mbe::ast_to_token_tree;
78
use ra_syntax::{
89
ast::{self, AstNode, AttrsOwner},
@@ -45,8 +46,8 @@ impl Attrs {
4546
AttrDefId::StructFieldId(it) => {
4647
let src = it.parent.child_source(db);
4748
match &src.value[it.local_id] {
48-
Either::A(_tuple) => Attrs::default(),
49-
Either::B(record) => Attrs::from_attrs_owner(db, src.with_value(record)),
49+
Either::Left(_tuple) => Attrs::default(),
50+
Either::Right(record) => Attrs::from_attrs_owner(db, src.with_value(record)),
5051
}
5152
}
5253
AttrDefId::EnumVariantId(var_id) => {

crates/ra_hir_def/src/body.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ pub mod scope;
55

66
use std::{ops::Index, sync::Arc};
77

8-
use hir_expand::{
9-
either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind,
10-
};
8+
use either::Either;
9+
use hir_expand::{hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind};
1110
use ra_arena::{map::ArenaMap, Arena};
1211
use ra_syntax::{ast, AstNode, AstPtr};
1312
use rustc_hash::FxHashMap;
@@ -210,7 +209,7 @@ impl BodySourceMap {
210209
}
211210

212211
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)));
214213
self.expr_map.get(&src).cloned()
215214
}
216215

@@ -219,7 +218,7 @@ impl BodySourceMap {
219218
}
220219

221220
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)));
223222
self.pat_map.get(&src).cloned()
224223
}
225224

0 commit comments

Comments
 (0)