]> git.lizzy.rs Git - rust.git/commitdiff
minor: Remove either dependency from `ide_completion`
authorLukas Wirth <lukastw97@gmail.com>
Mon, 25 Apr 2022 16:40:38 +0000 (18:40 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Mon, 25 Apr 2022 16:40:38 +0000 (18:40 +0200)
Cargo.lock
crates/ide_completion/Cargo.toml
crates/ide_completion/src/completions/dot.rs

index 1937b893621320cc1634ded8b8e25ded3962e948..38d1d0cd6a0c2d657118b9a50b2c9e35925408bd 100644 (file)
@@ -641,7 +641,6 @@ version = "0.0.0"
 dependencies = [
  "base_db",
  "cov-mark",
- "either",
  "expect-test",
  "hir",
  "ide_db",
index e088e3815aa99e80cbfae0811602b825be1cf6f9..8d9381e09af19cec16da24538ad3e769102956b0 100644 (file)
@@ -13,7 +13,6 @@ doctest = false
 cov-mark = "2.0.0-pre.1"
 itertools = "0.10.3"
 rustc-hash = "1.1.0"
-either = "1.6.1"
 once_cell = "1.10.0"
 smallvec = "1.8.0"
 
index c237a65bfe4903244815f265ae783d2868912513..9eb9da1b1b133befd1fda546e7686462f0af7d76 100644 (file)
@@ -1,6 +1,5 @@
 //! Completes references after dot (fields and method calls).
 
-use either::Either;
 use rustc_hash::FxHashSet;
 
 use crate::{context::CompletionContext, patterns::ImmediateLocation, Completions};
@@ -20,10 +19,13 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
     if matches!(ctx.completion_location, Some(ImmediateLocation::MethodCall { .. })) {
         cov_mark::hit!(test_no_struct_field_completion_for_method_call);
     } else {
-        complete_fields(ctx, &receiver_ty, |field, ty| match field {
-            Either::Left(field) => acc.add_field(ctx, None, field, &ty),
-            Either::Right(tuple_idx) => acc.add_tuple_field(ctx, None, tuple_idx, &ty),
-        });
+        complete_fields(
+            acc,
+            ctx,
+            &receiver_ty,
+            |acc, field, ty| acc.add_field(ctx, None, field, &ty),
+            |acc, field, ty| acc.add_tuple_field(ctx, None, field, &ty),
+        );
     }
     complete_methods(ctx, &receiver_ty, |func| acc.add_method(ctx, func, None, None));
 }
@@ -38,14 +40,13 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
     if let Some(func) = ctx.function_def.as_ref().and_then(|fn_| ctx.sema.to_def(fn_)) {
         if let Some(self_) = func.self_param(ctx.db) {
             let ty = self_.ty(ctx.db);
-            complete_fields(ctx, &ty, |field, ty| match field {
-                either::Either::Left(field) => {
-                    acc.add_field(ctx, Some(hir::known::SELF_PARAM), field, &ty)
-                }
-                either::Either::Right(tuple_idx) => {
-                    acc.add_tuple_field(ctx, Some(hir::known::SELF_PARAM), tuple_idx, &ty)
-                }
-            });
+            complete_fields(
+                acc,
+                ctx,
+                &ty,
+                |acc, field, ty| acc.add_field(ctx, Some(hir::known::SELF_PARAM), field, &ty),
+                |acc, field, ty| acc.add_tuple_field(ctx, Some(hir::known::SELF_PARAM), field, &ty),
+            );
             complete_methods(ctx, &ty, |func| {
                 acc.add_method(ctx, func, Some(hir::known::SELF_PARAM), None)
             });
@@ -54,17 +55,19 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
 }
 
 fn complete_fields(
+    acc: &mut Completions,
     ctx: &CompletionContext,
     receiver: &hir::Type,
-    mut f: impl FnMut(Either<hir::Field, usize>, hir::Type),
+    mut named_field: impl FnMut(&mut Completions, hir::Field, hir::Type),
+    mut tuple_index: impl FnMut(&mut Completions, usize, hir::Type),
 ) {
     for receiver in receiver.autoderef(ctx.db) {
         for (field, ty) in receiver.fields(ctx.db) {
-            f(Either::Left(field), ty);
+            named_field(acc, field, ty);
         }
         for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
             // Tuple fields are always public (tuple struct fields are handled above).
-            f(Either::Right(i), ty);
+            tuple_index(acc, i, ty);
         }
     }
 }