Skip to content

Commit 3dc38fb

Browse files
committed
Switch from for-loop to filter_map
1 parent b5e73bf commit 3dc38fb

File tree

1 file changed

+26
-27
lines changed
  • compiler/rustc_hir_analysis/src/astconv

1 file changed

+26
-27
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,41 +2232,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22322232
let param_env = tcx.param_env(block.owner.to_def_id());
22332233
let cause = ObligationCause::misc(span, block.owner.def_id);
22342234
let mut fulfillment_errors = Vec::new();
2235-
let mut applicable_candidates = Vec::new();
2236-
2237-
for &(impl_, (assoc_item, def_scope)) in &candidates {
2238-
let ocx = ObligationCtxt::new(&infcx);
2235+
let mut applicable_candidates: Vec<_> = candidates
2236+
.iter()
2237+
.filter_map(|&(impl_, (assoc_item, def_scope))| {
2238+
let ocx = ObligationCtxt::new(&infcx);
22392239

2240-
let impl_ty = tcx.type_of(impl_);
2241-
let impl_substs = self.fresh_item_substs(impl_, &infcx);
2242-
let impl_ty = impl_ty.subst(tcx, impl_substs);
2243-
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
2240+
let impl_ty = tcx.type_of(impl_);
2241+
let impl_substs = self.fresh_item_substs(impl_, &infcx);
2242+
let impl_ty = impl_ty.subst(tcx, impl_substs);
2243+
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
22442244

2245-
// Check that the Self-types can be related.
2246-
// FIXME(fmease): Should we use `eq` here?
2247-
if ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err() {
2248-
continue;
2249-
}
2245+
// Check that the Self-types can be related.
2246+
// FIXME(fmease): Should we use `eq` here?
2247+
ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
22502248

2251-
// Check whether the impl imposes obligations we have to worry about.
2252-
let impl_bounds = tcx.predicates_of(impl_);
2253-
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
2249+
// Check whether the impl imposes obligations we have to worry about.
2250+
let impl_bounds = tcx.predicates_of(impl_);
2251+
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
22542252

2255-
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
2253+
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
22562254

2257-
let impl_obligations =
2258-
traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds);
2255+
let impl_obligations =
2256+
traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds);
22592257

2260-
ocx.register_obligations(impl_obligations);
2258+
ocx.register_obligations(impl_obligations);
22612259

2262-
let errors = ocx.select_where_possible();
2263-
if !errors.is_empty() {
2264-
fulfillment_errors = errors;
2265-
continue;
2266-
}
2260+
let errors = ocx.select_where_possible();
2261+
if !errors.is_empty() {
2262+
fulfillment_errors = errors;
2263+
return None;
2264+
}
22672265

2268-
applicable_candidates.push((assoc_item, def_scope));
2269-
}
2266+
Some((assoc_item, def_scope))
2267+
})
2268+
.collect();
22702269

22712270
if applicable_candidates.len() > 1 {
22722271
return Err(self.complain_about_ambiguous_inherent_assoc_type(

0 commit comments

Comments
 (0)