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 <[email protected]>
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

crates/ra_hir_def/src/body/lower.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
22
//! representation.
33
4-
use hir_expand::{
5-
either::Either,
6-
name::{self, AsName, Name},
7-
};
4+
use either::Either;
5+
use hir_expand::name::{self, AsName, Name};
86
use ra_arena::Arena;
97
use ra_syntax::{
108
ast::{
@@ -74,7 +72,7 @@ where
7472
mode: BindingAnnotation::Unannotated,
7573
subpat: None,
7674
},
77-
Either::B(ptr),
75+
Either::Right(ptr),
7876
);
7977
self.body.params.push(param_pat);
8078
}
@@ -94,7 +92,7 @@ where
9492
}
9593

9694
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
97-
let ptr = Either::A(ptr);
95+
let ptr = Either::Left(ptr);
9896
let id = self.body.exprs.alloc(expr);
9997
let src = self.expander.to_source(ptr);
10098
self.source_map.expr_map.insert(src, id);
@@ -107,7 +105,7 @@ where
107105
self.body.exprs.alloc(expr)
108106
}
109107
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);
111109
let id = self.body.exprs.alloc(expr);
112110
let src = self.expander.to_source(ptr);
113111
self.source_map.expr_map.insert(src, id);
@@ -277,7 +275,7 @@ where
277275
ast::Expr::ParenExpr(e) => {
278276
let inner = self.collect_expr_opt(e.expr());
279277
// 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));
281279
self.source_map.expr_map.insert(src, inner);
282280
inner
283281
}
@@ -550,7 +548,7 @@ where
550548
ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,
551549
};
552550
let ptr = AstPtr::new(&pat);
553-
self.alloc_pat(pattern, Either::A(ptr))
551+
self.alloc_pat(pattern, Either::Left(ptr))
554552
}
555553

556554
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {

crates/ra_hir_def/src/docs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use std::sync::Arc;
77

8-
use hir_expand::either::Either;
8+
use either::Either;
99
use ra_syntax::ast;
1010

1111
use crate::{
@@ -46,8 +46,8 @@ impl Documentation {
4646
AttrDefId::StructFieldId(it) => {
4747
let src = it.parent.child_source(db);
4848
match &src.value[it.local_id] {
49-
Either::A(_tuple) => None,
50-
Either::B(record) => docs_from_ast(record),
49+
Either::Left(_tuple) => None,
50+
Either::Right(record) => docs_from_ast(record),
5151
}
5252
}
5353
AttrDefId::AdtId(it) => match it {

crates/ra_hir_def/src/nameres.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ mod tests;
5757

5858
use std::sync::Arc;
5959

60+
use either::Either;
6061
use hir_expand::{
61-
ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile,
62-
MacroDefId,
62+
ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId,
6363
};
6464
use once_cell::sync::Lazy;
6565
use ra_arena::Arena;
@@ -287,10 +287,10 @@ impl ModuleData {
287287
) -> InFile<Either<ast::SourceFile, ast::Module>> {
288288
if let Some(file_id) = self.definition {
289289
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));
291291
}
292292
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)))
294294
}
295295

296296
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.

crates/ra_hir_def/src/nameres/raw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
88
use std::{ops::Index, sync::Arc};
99

10+
use either::Either;
1011
use hir_expand::{
1112
ast_id_map::AstIdMap,
1213
db::AstDatabase,
13-
either::Either,
1414
hygiene::Hygiene,
1515
name::{AsName, Name},
1616
};
@@ -324,7 +324,7 @@ impl RawItemsCollector {
324324
is_extern_crate: false,
325325
is_macro_use: false,
326326
};
327-
buf.push((import_data, Either::A(AstPtr::new(use_tree))));
327+
buf.push((import_data, Either::Left(AstPtr::new(use_tree))));
328328
},
329329
);
330330
for (import_data, ptr) in buf {
@@ -355,7 +355,7 @@ impl RawItemsCollector {
355355
current_module,
356356
attrs,
357357
import_data,
358-
Either::B(AstPtr::new(&extern_crate)),
358+
Either::Right(AstPtr::new(&extern_crate)),
359359
);
360360
}
361361
}

0 commit comments

Comments
 (0)