diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2023-02-17 16:55:07 +0100 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2023-02-19 18:35:35 +0100 |
| commit | 3dc38fbc9115f0e8cf61848938e05e1964ee29bf (patch) | |
| tree | 3930e5008da76b859f68df090d6e0c57dba1e3c4 | |
| parent | b5e73bfe90f7b4905829f1a6509b61ac5577ee07 (diff) | |
| download | rust-3dc38fbc9115f0e8cf61848938e05e1964ee29bf.tar.gz rust-3dc38fbc9115f0e8cf61848938e05e1964ee29bf.zip | |
Switch from for-loop to filter_map
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/mod.rs | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 43db8af7bac..c8ff609dea5 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2232,41 +2232,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let param_env = tcx.param_env(block.owner.to_def_id()); let cause = ObligationCause::misc(span, block.owner.def_id); let mut fulfillment_errors = Vec::new(); - let mut applicable_candidates = Vec::new(); - - for &(impl_, (assoc_item, def_scope)) in &candidates { - let ocx = ObligationCtxt::new(&infcx); + let mut applicable_candidates: Vec<_> = candidates + .iter() + .filter_map(|&(impl_, (assoc_item, def_scope))| { + let ocx = ObligationCtxt::new(&infcx); - let impl_ty = tcx.type_of(impl_); - 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_); + 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); - // Check that the Self-types can be related. - // FIXME(fmease): Should we use `eq` here? - if ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err() { - continue; - } + // Check that the Self-types can be related. + // FIXME(fmease): Should we use `eq` here? + ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?; - // Check whether the impl imposes obligations we have to worry about. - let impl_bounds = tcx.predicates_of(impl_); - let impl_bounds = impl_bounds.instantiate(tcx, impl_substs); + // Check whether the impl imposes obligations we have to worry about. + 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_bounds = ocx.normalize(&cause, param_env, impl_bounds); - let impl_obligations = - traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds); + let impl_obligations = + traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds); - ocx.register_obligations(impl_obligations); + ocx.register_obligations(impl_obligations); - let errors = ocx.select_where_possible(); - if !errors.is_empty() { - fulfillment_errors = errors; - continue; - } + let errors = ocx.select_where_possible(); + if !errors.is_empty() { + fulfillment_errors = errors; + return None; + } - applicable_candidates.push((assoc_item, def_scope)); - } + Some((assoc_item, def_scope)) + }) + .collect(); if applicable_candidates.len() > 1 { return Err(self.complain_about_ambiguous_inherent_assoc_type( |
