about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2025-01-01 15:21:49 +0100
committerLukas Wirth <lukastw97@gmail.com>2025-01-01 15:21:54 +0100
commitc15e36a8ded1459de96a413ff3d0cedd82c2bbfa (patch)
tree2b31982d8ef8ab3d3097b82dc7c3547f043ea0d6 /src
parentc84d09a7c37711533311f99397189de148a79a58 (diff)
downloadrust-c15e36a8ded1459de96a413ff3d0cedd82c2bbfa.tar.gz
rust-c15e36a8ded1459de96a413ff3d0cedd82c2bbfa.zip
Cleanup
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/lib.rs113
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs1
2 files changed, 46 insertions, 68 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs
index 4c5f9d2a5a1..55cf3b7fecc 100644
--- a/src/tools/rust-analyzer/crates/hir/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs
@@ -5219,49 +5219,25 @@ impl Type {
         traits_in_scope: &FxHashSet<TraitId>,
         with_local_impls: Option<Module>,
         name: Option<&Name>,
-        callback: impl FnMut(Function) -> Option<T>,
+        mut callback: impl FnMut(Function) -> Option<T>,
     ) -> Option<T> {
-        struct Callback<T, F> {
-            f: F,
-            slot: Option<T>,
-        }
-        impl<T, F> MethodCandidateCallback for &'_ mut Callback<T, F>
-        where
-            F: FnMut(Function) -> Option<T>,
-        {
-            fn on_inherent_method(&mut self, f: Function) -> ControlFlow<()> {
-                match (self.f)(f) {
-                    it @ Some(_) => {
-                        self.slot = it;
-                        ControlFlow::Break(())
-                    }
-                    None => ControlFlow::Continue(()),
-                }
-            }
-
-            fn on_trait_method(&mut self, f: Function) -> ControlFlow<()> {
-                match (self.f)(f) {
-                    it @ Some(_) => {
-                        self.slot = it;
-                        ControlFlow::Break(())
-                    }
-                    None => ControlFlow::Continue(()),
-                }
-            }
-        }
-
         let _p = tracing::info_span!("iterate_method_candidates_with_traits").entered();
-        let mut callback = Callback { slot: None, f: callback };
-
+        let mut slot = None;
         self.iterate_method_candidates_split_inherent(
             db,
             scope,
             traits_in_scope,
             with_local_impls,
             name,
-            &mut callback,
+            |f| match callback(f) {
+                it @ Some(_) => {
+                    slot = it;
+                    ControlFlow::Break(())
+                }
+                None => ControlFlow::Continue(()),
+            },
         );
-        callback.slot
+        slot
     }
 
     pub fn iterate_method_candidates<T>(
@@ -5361,39 +5337,10 @@ impl Type {
         traits_in_scope: &FxHashSet<TraitId>,
         with_local_impls: Option<Module>,
         name: Option<&Name>,
-        callback: impl FnMut(AssocItem) -> Option<T>,
+        mut callback: impl FnMut(AssocItem) -> Option<T>,
     ) -> Option<T> {
-        struct Callback<T, F> {
-            f: F,
-            slot: Option<T>,
-        }
-        impl<T, F> PathCandidateCallback for &'_ mut Callback<T, F>
-        where
-            F: FnMut(AssocItem) -> Option<T>,
-        {
-            fn on_inherent_item(&mut self, item: AssocItem) -> ControlFlow<()> {
-                match (self.f)(item) {
-                    it @ Some(_) => {
-                        self.slot = it;
-                        ControlFlow::Break(())
-                    }
-                    None => ControlFlow::Continue(()),
-                }
-            }
-
-            fn on_trait_item(&mut self, item: AssocItem) -> ControlFlow<()> {
-                match (self.f)(item) {
-                    it @ Some(_) => {
-                        self.slot = it;
-                        ControlFlow::Break(())
-                    }
-                    None => ControlFlow::Continue(()),
-                }
-            }
-        }
-
         let _p = tracing::info_span!("iterate_path_candidates").entered();
-        let mut callback = Callback { slot: None, f: callback };
+        let mut slot = None;
 
         self.iterate_path_candidates_split_inherent(
             db,
@@ -5401,9 +5348,15 @@ impl Type {
             traits_in_scope,
             with_local_impls,
             name,
-            &mut callback,
+            |item| match callback(item) {
+                it @ Some(_) => {
+                    slot = it;
+                    ControlFlow::Break(())
+                }
+                None => ControlFlow::Continue(()),
+            },
         );
-        callback.slot
+        slot
     }
 
     /// Iterates over inherent methods.
@@ -6167,8 +6120,34 @@ pub trait MethodCandidateCallback {
     fn on_trait_method(&mut self, f: Function) -> ControlFlow<()>;
 }
 
+impl<F> MethodCandidateCallback for F
+where
+    F: FnMut(Function) -> ControlFlow<()>,
+{
+    fn on_inherent_method(&mut self, f: Function) -> ControlFlow<()> {
+        self(f)
+    }
+
+    fn on_trait_method(&mut self, f: Function) -> ControlFlow<()> {
+        self(f)
+    }
+}
+
 pub trait PathCandidateCallback {
     fn on_inherent_item(&mut self, item: AssocItem) -> ControlFlow<()>;
 
     fn on_trait_item(&mut self, item: AssocItem) -> ControlFlow<()>;
 }
+
+impl<F> PathCandidateCallback for F
+where
+    F: FnMut(AssocItem) -> ControlFlow<()>,
+{
+    fn on_inherent_item(&mut self, item: AssocItem) -> ControlFlow<()> {
+        self(item)
+    }
+
+    fn on_trait_item(&mut self, item: AssocItem) -> ControlFlow<()> {
+        self(item)
+    }
+}
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs
index e9eb3fc8428..f748ce9ad63 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs
@@ -30,7 +30,6 @@ where
         ControlFlow::Continue(())
     }
 
-    #[allow(unstable_name_collisions)] // FIXME: Remove this when `is_none_or()` reaches stable.
     fn on_trait_item(&mut self, item: hir::AssocItem) -> ControlFlow<()> {
         // The excluded check needs to come before the `seen` test, so that if we see the same method twice,
         // once as inherent and once not, we will include it.