1
Fork 0

Switch from for-loop to filter_map

This commit is contained in:
León Orell Valerian Liehr 2023-02-17 16:55:07 +01:00
parent b5e73bfe90
commit 3dc38fbc91
No known key found for this signature in database
GPG key ID: D17A07215F68E713

View file

@ -2232,41 +2232,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let param_env = tcx.param_env(block.owner.to_def_id()); let param_env = tcx.param_env(block.owner.to_def_id());
let cause = ObligationCause::misc(span, block.owner.def_id); let cause = ObligationCause::misc(span, block.owner.def_id);
let mut fulfillment_errors = Vec::new(); let mut fulfillment_errors = Vec::new();
let mut applicable_candidates = Vec::new(); let mut applicable_candidates: Vec<_> = candidates
.iter()
.filter_map(|&(impl_, (assoc_item, def_scope))| {
let ocx = ObligationCtxt::new(&infcx);
for &(impl_, (assoc_item, def_scope)) in &candidates { let impl_ty = tcx.type_of(impl_);
let ocx = ObligationCtxt::new(&infcx); let impl_substs = self.fresh_item_substs(impl_, &infcx);
let impl_ty = impl_ty.subst(tcx, impl_substs);
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
let impl_ty = tcx.type_of(impl_); // Check that the Self-types can be related.
let impl_substs = self.fresh_item_substs(impl_, &infcx); // FIXME(fmease): Should we use `eq` here?
let impl_ty = impl_ty.subst(tcx, impl_substs); ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
// Check that the Self-types can be related. // Check whether the impl imposes obligations we have to worry about.
// FIXME(fmease): Should we use `eq` here? let impl_bounds = tcx.predicates_of(impl_);
if ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err() { let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
continue;
}
// Check whether the impl imposes obligations we have to worry about. let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
let impl_bounds = tcx.predicates_of(impl_);
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds); let impl_obligations =
traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds);
let impl_obligations = ocx.register_obligations(impl_obligations);
traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds);
ocx.register_obligations(impl_obligations); let errors = ocx.select_where_possible();
if !errors.is_empty() {
fulfillment_errors = errors;
return None;
}
let errors = ocx.select_where_possible(); Some((assoc_item, def_scope))
if !errors.is_empty() { })
fulfillment_errors = errors; .collect();
continue;
}
applicable_candidates.push((assoc_item, def_scope));
}
if applicable_candidates.len() > 1 { if applicable_candidates.len() > 1 {
return Err(self.complain_about_ambiguous_inherent_assoc_type( return Err(self.complain_about_ambiguous_inherent_assoc_type(