Skip to content

Commit 1adc805

Browse files
committed
Cleanup
1 parent 5303dc5 commit 1adc805

File tree

2 files changed

+46
-68
lines changed

2 files changed

+46
-68
lines changed

crates/hir/src/lib.rs

+46-67
Original file line numberDiff line numberDiff line change
@@ -5219,49 +5219,25 @@ impl Type {
52195219
traits_in_scope: &FxHashSet<TraitId>,
52205220
with_local_impls: Option<Module>,
52215221
name: Option<&Name>,
5222-
callback: impl FnMut(Function) -> Option<T>,
5222+
mut callback: impl FnMut(Function) -> Option<T>,
52235223
) -> Option<T> {
5224-
struct Callback<T, F> {
5225-
f: F,
5226-
slot: Option<T>,
5227-
}
5228-
impl<T, F> MethodCandidateCallback for &'_ mut Callback<T, F>
5229-
where
5230-
F: FnMut(Function) -> Option<T>,
5231-
{
5232-
fn on_inherent_method(&mut self, f: Function) -> ControlFlow<()> {
5233-
match (self.f)(f) {
5234-
it @ Some(_) => {
5235-
self.slot = it;
5236-
ControlFlow::Break(())
5237-
}
5238-
None => ControlFlow::Continue(()),
5239-
}
5240-
}
5241-
5242-
fn on_trait_method(&mut self, f: Function) -> ControlFlow<()> {
5243-
match (self.f)(f) {
5244-
it @ Some(_) => {
5245-
self.slot = it;
5246-
ControlFlow::Break(())
5247-
}
5248-
None => ControlFlow::Continue(()),
5249-
}
5250-
}
5251-
}
5252-
52535224
let _p = tracing::info_span!("iterate_method_candidates_with_traits").entered();
5254-
let mut callback = Callback { slot: None, f: callback };
5255-
5225+
let mut slot = None;
52565226
self.iterate_method_candidates_split_inherent(
52575227
db,
52585228
scope,
52595229
traits_in_scope,
52605230
with_local_impls,
52615231
name,
5262-
&mut callback,
5232+
|f| match callback(f) {
5233+
it @ Some(_) => {
5234+
slot = it;
5235+
ControlFlow::Break(())
5236+
}
5237+
None => ControlFlow::Continue(()),
5238+
},
52635239
);
5264-
callback.slot
5240+
slot
52655241
}
52665242

52675243
pub fn iterate_method_candidates<T>(
@@ -5361,49 +5337,26 @@ impl Type {
53615337
traits_in_scope: &FxHashSet<TraitId>,
53625338
with_local_impls: Option<Module>,
53635339
name: Option<&Name>,
5364-
callback: impl FnMut(AssocItem) -> Option<T>,
5340+
mut callback: impl FnMut(AssocItem) -> Option<T>,
53655341
) -> Option<T> {
5366-
struct Callback<T, F> {
5367-
f: F,
5368-
slot: Option<T>,
5369-
}
5370-
impl<T, F> PathCandidateCallback for &'_ mut Callback<T, F>
5371-
where
5372-
F: FnMut(AssocItem) -> Option<T>,
5373-
{
5374-
fn on_inherent_item(&mut self, item: AssocItem) -> ControlFlow<()> {
5375-
match (self.f)(item) {
5376-
it @ Some(_) => {
5377-
self.slot = it;
5378-
ControlFlow::Break(())
5379-
}
5380-
None => ControlFlow::Continue(()),
5381-
}
5382-
}
5383-
5384-
fn on_trait_item(&mut self, item: AssocItem) -> ControlFlow<()> {
5385-
match (self.f)(item) {
5386-
it @ Some(_) => {
5387-
self.slot = it;
5388-
ControlFlow::Break(())
5389-
}
5390-
None => ControlFlow::Continue(()),
5391-
}
5392-
}
5393-
}
5394-
53955342
let _p = tracing::info_span!("iterate_path_candidates").entered();
5396-
let mut callback = Callback { slot: None, f: callback };
5343+
let mut slot = None;
53975344

53985345
self.iterate_path_candidates_split_inherent(
53995346
db,
54005347
scope,
54015348
traits_in_scope,
54025349
with_local_impls,
54035350
name,
5404-
&mut callback,
5351+
|item| match callback(item) {
5352+
it @ Some(_) => {
5353+
slot = it;
5354+
ControlFlow::Break(())
5355+
}
5356+
None => ControlFlow::Continue(()),
5357+
},
54055358
);
5406-
callback.slot
5359+
slot
54075360
}
54085361

54095362
/// Iterates over inherent methods.
@@ -6167,8 +6120,34 @@ pub trait MethodCandidateCallback {
61676120
fn on_trait_method(&mut self, f: Function) -> ControlFlow<()>;
61686121
}
61696122

6123+
impl<F> MethodCandidateCallback for F
6124+
where
6125+
F: FnMut(Function) -> ControlFlow<()>,
6126+
{
6127+
fn on_inherent_method(&mut self, f: Function) -> ControlFlow<()> {
6128+
self(f)
6129+
}
6130+
6131+
fn on_trait_method(&mut self, f: Function) -> ControlFlow<()> {
6132+
self(f)
6133+
}
6134+
}
6135+
61706136
pub trait PathCandidateCallback {
61716137
fn on_inherent_item(&mut self, item: AssocItem) -> ControlFlow<()>;
61726138

61736139
fn on_trait_item(&mut self, item: AssocItem) -> ControlFlow<()>;
61746140
}
6141+
6142+
impl<F> PathCandidateCallback for F
6143+
where
6144+
F: FnMut(AssocItem) -> ControlFlow<()>,
6145+
{
6146+
fn on_inherent_item(&mut self, item: AssocItem) -> ControlFlow<()> {
6147+
self(item)
6148+
}
6149+
6150+
fn on_trait_item(&mut self, item: AssocItem) -> ControlFlow<()> {
6151+
self(item)
6152+
}
6153+
}

crates/ide-completion/src/completions/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ where
3030
ControlFlow::Continue(())
3131
}
3232

33-
#[allow(unstable_name_collisions)] // FIXME: Remove this when `is_none_or()` reaches stable.
3433
fn on_trait_item(&mut self, item: hir::AssocItem) -> ControlFlow<()> {
3534
// The excluded check needs to come before the `seen` test, so that if we see the same method twice,
3635
// once as inherent and once not, we will include it.

0 commit comments

Comments
 (0)