Skip to content

Commit 9e5fa74

Browse files
committed
Simplify
1 parent b38fcde commit 9e5fa74

File tree

7 files changed

+44
-52
lines changed

7 files changed

+44
-52
lines changed

crates/hir-ty/src/method_resolution.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -867,33 +867,28 @@ fn iterate_method_candidates_with_autoref(
867867
return ControlFlow::Continue(());
868868
}
869869

870-
iterate_method_candidates_by_receiver(
871-
receiver_ty,
872-
first_adjustment.clone(),
873-
db,
874-
env.clone(),
875-
traits_in_scope,
876-
visible_from_module,
877-
name,
878-
&mut callback,
879-
)?;
870+
let iterate_method_candidates_by_receiver = |receiver_ty, first_adjustment| {
871+
iterate_method_candidates_by_receiver(
872+
receiver_ty,
873+
first_adjustment,
874+
db,
875+
env.clone(),
876+
traits_in_scope,
877+
visible_from_module,
878+
name,
879+
&mut callback,
880+
)
881+
};
882+
883+
iterate_method_candidates_by_receiver(receiver_ty, first_adjustment.clone())?;
880884

881885
let refed = Canonical {
882886
value: TyKind::Ref(Mutability::Not, static_lifetime(), receiver_ty.value.clone())
883887
.intern(Interner),
884888
binders: receiver_ty.binders.clone(),
885889
};
886890

887-
iterate_method_candidates_by_receiver(
888-
&refed,
889-
first_adjustment.with_autoref(Mutability::Not),
890-
db,
891-
env.clone(),
892-
traits_in_scope,
893-
visible_from_module,
894-
name,
895-
&mut callback,
896-
)?;
891+
iterate_method_candidates_by_receiver(&refed, first_adjustment.with_autoref(Mutability::Not))?;
897892

898893
let ref_muted = Canonical {
899894
value: TyKind::Ref(Mutability::Mut, static_lifetime(), receiver_ty.value.clone())
@@ -904,12 +899,6 @@ fn iterate_method_candidates_with_autoref(
904899
iterate_method_candidates_by_receiver(
905900
&ref_muted,
906901
first_adjustment.with_autoref(Mutability::Mut),
907-
db,
908-
env,
909-
traits_in_scope,
910-
visible_from_module,
911-
name,
912-
&mut callback,
913902
)
914903
}
915904

crates/hir/src/lib.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,12 +3339,10 @@ impl Type {
33393339
.map(move |ty| self.derived(ty))
33403340
}
33413341

3342-
pub fn iterate_method_candidates<T>(
3342+
pub fn iterate_method_candidates_with_traits<T>(
33433343
&self,
33443344
db: &dyn HirDatabase,
33453345
scope: &SemanticsScope<'_>,
3346-
// FIXME this can be retrieved from `scope`, except autoimport uses this
3347-
// to specify a different set, so the method needs to be split
33483346
traits_in_scope: &FxHashSet<TraitId>,
33493347
with_local_impls: Option<Module>,
33503348
name: Option<&Name>,
@@ -3372,6 +3370,24 @@ impl Type {
33723370
slot
33733371
}
33743372

3373+
pub fn iterate_method_candidates<T>(
3374+
&self,
3375+
db: &dyn HirDatabase,
3376+
scope: &SemanticsScope<'_>,
3377+
with_local_impls: Option<Module>,
3378+
name: Option<&Name>,
3379+
mut callback: impl FnMut(Function) -> Option<T>,
3380+
) -> Option<T> {
3381+
self.iterate_method_candidates_with_traits(
3382+
db,
3383+
scope,
3384+
&scope.visible_traits().0,
3385+
with_local_impls,
3386+
name,
3387+
callback,
3388+
)
3389+
}
3390+
33753391
fn iterate_method_candidates_dyn(
33763392
&self,
33773393
db: &dyn HirDatabase,

crates/hir/src/semantics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ impl<'a> SemanticsScope<'a> {
16731673
}
16741674
}
16751675

1676+
#[derive(Debug)]
16761677
pub struct VisibleTraits(pub FxHashSet<TraitId>);
16771678

16781679
impl ops::Deref for VisibleTraits {

crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,12 @@ fn is_ref_and_impls_iter_method(
157157
let iter_trait = FamousDefs(sema, krate).core_iter_Iterator()?;
158158

159159
let has_wanted_method = ty
160-
.iterate_method_candidates(
161-
sema.db,
162-
&scope,
163-
&scope.visible_traits().0,
164-
None,
165-
Some(&wanted_method),
166-
|func| {
167-
if func.ret_type(sema.db).impls_trait(sema.db, iter_trait, &[]) {
168-
return Some(());
169-
}
170-
None
171-
},
172-
)
160+
.iterate_method_candidates(sema.db, &scope, None, Some(&wanted_method), |func| {
161+
if func.ret_type(sema.db).impls_trait(sema.db, iter_trait, &[]) {
162+
return Some(());
163+
}
164+
None
165+
})
173166
.is_some();
174167
if !has_wanted_method {
175168
return None;

crates/ide-assists/src/handlers/generate_is_empty_from_len.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,7 @@ fn get_impl_method(
9595

9696
let scope = ctx.sema.scope(impl_.syntax())?;
9797
let ty = impl_def.self_ty(db);
98-
ty.iterate_method_candidates(
99-
db,
100-
&scope,
101-
&scope.visible_traits().0,
102-
None,
103-
Some(fn_name),
104-
|func| Some(func),
105-
)
98+
ty.iterate_method_candidates(db, &scope, None, Some(fn_name), |func| Some(func))
10699
}
107100

108101
#[cfg(test)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn complete_methods(
122122
mut f: impl FnMut(hir::Function),
123123
) {
124124
let mut seen_methods = FxHashSet::default();
125-
receiver.iterate_method_candidates(
125+
receiver.iterate_method_candidates_with_traits(
126126
ctx.db,
127127
&ctx.scope,
128128
&ctx.traits_in_scope(),

crates/ide-db/src/imports/import_assets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ fn trait_applicable_items(
528528
},
529529
)
530530
} else {
531-
trait_candidate.receiver_ty.iterate_method_candidates(
531+
trait_candidate.receiver_ty.iterate_method_candidates_with_traits(
532532
db,
533533
scope,
534534
&trait_candidates,

0 commit comments

Comments
 (0)