1
Fork 0

add subst_identity_iter and subst_identity_iter_copied methods on EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls

This commit is contained in:
Kyle Matsuda 2023-04-17 17:19:08 -06:00
parent f3b279fcc5
commit e54854f6a9
12 changed files with 43 additions and 50 deletions

View file

@ -318,11 +318,10 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
tcx,
selftys: vec![],
};
let prohibit_opaque =
tcx.explicit_item_bounds(def_id).transpose_iter().try_for_each(|bound| {
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
predicate.visit_with(&mut visitor)
});
let prohibit_opaque = tcx
.explicit_item_bounds(def_id)
.subst_identity_iter_copied()
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
if let Some(ty) = prohibit_opaque.break_value() {
visitor.visit_item(&item);

View file

@ -361,8 +361,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
param_env,
item_def_id,
tcx.explicit_item_bounds(item_def_id)
.transpose_iter()
.map(|bound| bound.map_bound(|b| *b).subst_identity())
.subst_identity_iter_copied()
.collect::<Vec<_>>(),
&FxIndexSet::default(),
gat_def_id.def_id,
@ -1128,8 +1127,7 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
debug!("check_associated_type_bounds: bounds={:?}", bounds);
let wf_obligations = bounds.transpose_iter().flat_map(|b| {
let (bound, bound_span) = b.map_bound(|b| *b).subst_identity();
let wf_obligations = bounds.subst_identity_iter_copied().flat_map(|(bound, bound_span)| {
let normalized_bound = wfcx.normalize(span, None, bound);
traits::wf::predicate_obligations(
wfcx.infcx,

View file

@ -153,8 +153,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
let mut collector =
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id);
for pred in tcx.explicit_item_bounds(item_def_id).transpose_iter() {
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
for (pred, _) in tcx.explicit_item_bounds(item_def_id).subst_iter_copied(tcx, id_substs) {
debug!(?pred);
// We only ignore opaque type substs if the opaque type is the outermost type.