Skip to content

Commit 04000c3

Browse files
committed
Auto merge of rust-lang#12077 - Veykril:neither, r=Veykril
minor: Remove `either` dependency from `ide_completion` bors r+
2 parents 6869491 + 8154365 commit 04000c3

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

Cargo.lock

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

crates/ide_completion/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ doctest = false
1313
cov-mark = "2.0.0-pre.1"
1414
itertools = "0.10.3"
1515
rustc-hash = "1.1.0"
16-
either = "1.6.1"
1716
once_cell = "1.10.0"
1817
smallvec = "1.8.0"
1918

crates/ide_completion/src/completions/dot.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Completes references after dot (fields and method calls).
22
3-
use either::Either;
43
use rustc_hash::FxHashSet;
54

65
use crate::{context::CompletionContext, patterns::ImmediateLocation, Completions};
@@ -20,10 +19,13 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
2019
if matches!(ctx.completion_location, Some(ImmediateLocation::MethodCall { .. })) {
2120
cov_mark::hit!(test_no_struct_field_completion_for_method_call);
2221
} else {
23-
complete_fields(ctx, &receiver_ty, |field, ty| match field {
24-
Either::Left(field) => acc.add_field(ctx, None, field, &ty),
25-
Either::Right(tuple_idx) => acc.add_tuple_field(ctx, None, tuple_idx, &ty),
26-
});
22+
complete_fields(
23+
acc,
24+
ctx,
25+
&receiver_ty,
26+
|acc, field, ty| acc.add_field(ctx, None, field, &ty),
27+
|acc, field, ty| acc.add_tuple_field(ctx, None, field, &ty),
28+
);
2729
}
2830
complete_methods(ctx, &receiver_ty, |func| acc.add_method(ctx, func, None, None));
2931
}
@@ -38,14 +40,13 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
3840
if let Some(func) = ctx.function_def.as_ref().and_then(|fn_| ctx.sema.to_def(fn_)) {
3941
if let Some(self_) = func.self_param(ctx.db) {
4042
let ty = self_.ty(ctx.db);
41-
complete_fields(ctx, &ty, |field, ty| match field {
42-
either::Either::Left(field) => {
43-
acc.add_field(ctx, Some(hir::known::SELF_PARAM), field, &ty)
44-
}
45-
either::Either::Right(tuple_idx) => {
46-
acc.add_tuple_field(ctx, Some(hir::known::SELF_PARAM), tuple_idx, &ty)
47-
}
48-
});
43+
complete_fields(
44+
acc,
45+
ctx,
46+
&ty,
47+
|acc, field, ty| acc.add_field(ctx, Some(hir::known::SELF_PARAM), field, &ty),
48+
|acc, field, ty| acc.add_tuple_field(ctx, Some(hir::known::SELF_PARAM), field, &ty),
49+
);
4950
complete_methods(ctx, &ty, |func| {
5051
acc.add_method(ctx, func, Some(hir::known::SELF_PARAM), None)
5152
});
@@ -54,17 +55,19 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
5455
}
5556

5657
fn complete_fields(
58+
acc: &mut Completions,
5759
ctx: &CompletionContext,
5860
receiver: &hir::Type,
59-
mut f: impl FnMut(Either<hir::Field, usize>, hir::Type),
61+
mut named_field: impl FnMut(&mut Completions, hir::Field, hir::Type),
62+
mut tuple_index: impl FnMut(&mut Completions, usize, hir::Type),
6063
) {
6164
for receiver in receiver.autoderef(ctx.db) {
6265
for (field, ty) in receiver.fields(ctx.db) {
63-
f(Either::Left(field), ty);
66+
named_field(acc, field, ty);
6467
}
6568
for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
6669
// Tuple fields are always public (tuple struct fields are handled above).
67-
f(Either::Right(i), ty);
70+
tuple_index(acc, i, ty);
6871
}
6972
}
7073
}

0 commit comments

Comments
 (0)