diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4c5f9d2a5a..55cf3b7fec 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -5219,49 +5219,25 @@ impl Type { traits_in_scope: &FxHashSet, with_local_impls: Option, name: Option<&Name>, - callback: impl FnMut(Function) -> Option, + mut callback: impl FnMut(Function) -> Option, ) -> Option { - struct Callback { - f: F, - slot: Option, - } - impl MethodCandidateCallback for &'_ mut Callback - where - F: FnMut(Function) -> Option, - { - 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( @@ -5361,39 +5337,10 @@ impl Type { traits_in_scope: &FxHashSet, with_local_impls: Option, name: Option<&Name>, - callback: impl FnMut(AssocItem) -> Option, + mut callback: impl FnMut(AssocItem) -> Option, ) -> Option { - struct Callback { - f: F, - slot: Option, - } - impl PathCandidateCallback for &'_ mut Callback - where - F: FnMut(AssocItem) -> Option, - { - 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 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 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/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs index e9eb3fc842..f748ce9ad6 100644 --- a/crates/ide-completion/src/completions/expr.rs +++ b/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.