Unnamed repository; edit this file 'description' to name the repository.
Minor refactorings
| -rw-r--r-- | crates/hir-ty/src/chalk_db.rs | 12 | ||||
| -rw-r--r-- | crates/hir-ty/src/method_resolution.rs | 12 |
2 files changed, 10 insertions, 14 deletions
diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs index 9dd3bddbd4..fb7d99711d 100644 --- a/crates/hir-ty/src/chalk_db.rs +++ b/crates/hir-ty/src/chalk_db.rs @@ -803,17 +803,17 @@ pub(crate) fn adt_variance_query( ) } +/// Returns instantiated predicates. pub(super) fn convert_where_clauses( db: &dyn HirDatabase, def: GenericDefId, substs: &Substitution, ) -> Vec<chalk_ir::QuantifiedWhereClause<Interner>> { - let generic_predicates = db.generic_predicates(def); - let mut result = Vec::with_capacity(generic_predicates.len()); - for pred in generic_predicates.iter() { - result.push(pred.clone().substitute(Interner, substs)); - } - result + db.generic_predicates(def) + .iter() + .cloned() + .map(|pred| pred.substitute(Interner, substs)) + .collect() } pub(super) fn generic_predicate_to_inline_bound( diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index 504dbe77d9..9fb7fdcc5f 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -742,9 +742,8 @@ fn find_matching_impl( actual_trait_ref: TraitRef, ) -> Option<(Arc<ImplData>, Substitution)> { let db = table.db; - loop { - let impl_ = impls.next()?; - let r = table.run_in_snapshot(|table| { + impls.find_map(|impl_| { + table.run_in_snapshot(|table| { let impl_data = db.impl_data(impl_); let impl_substs = TyBuilder::subst_for_def(db, impl_, None).fill_with_inference_vars(table).build(); @@ -762,11 +761,8 @@ fn find_matching_impl( .map(|b| b.cast(Interner)); let goal = crate::Goal::all(Interner, wcs); table.try_obligation(goal).map(|_| (impl_data, table.resolve_completely(impl_substs))) - }); - if r.is_some() { - break r; - } - } + }) + }) } fn is_inherent_impl_coherent( |