1
Fork 0

add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query

This commit is contained in:
Kyle Matsuda 2023-04-17 16:43:46 -06:00
parent 0892a7380b
commit f3b279fcc5
26 changed files with 49 additions and 56 deletions

View file

@ -318,10 +318,8 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
tcx,
selftys: vec![],
};
let prohibit_opaque = tcx
.bound_explicit_item_bounds(def_id.to_def_id())
.transpose_iter()
.try_for_each(|bound| {
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)
});

View file

@ -839,7 +839,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
});
self.types.insert(proj.def_id, (infer_ty, proj.substs));
// Recurse into bounds
for (pred, pred_span) in self.interner().bound_explicit_item_bounds(proj.def_id).subst_iter_copied(self.interner(), proj.substs) {
for (pred, pred_span) in self.interner().explicit_item_bounds(proj.def_id).subst_iter_copied(self.interner(), proj.substs) {
let pred = pred.fold_with(self);
let pred = self.ocx.normalize(
&ObligationCause::misc(self.span, self.body_id),
@ -2023,7 +2023,7 @@ pub(super) fn check_type_bounds<'tcx>(
};
let obligations: Vec<_> = tcx
.bound_explicit_item_bounds(trait_ty.def_id)
.explicit_item_bounds(trait_ty.def_id)
.subst_iter_copied(tcx, rebased_substs)
.map(|(concrete_ty_bound, span)| {
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);

View file

@ -360,7 +360,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
tcx,
param_env,
item_def_id,
tcx.bound_explicit_item_bounds(item_def_id.to_def_id())
tcx.explicit_item_bounds(item_def_id)
.transpose_iter()
.map(|bound| bound.map_bound(|b| *b).subst_identity())
.collect::<Vec<_>>(),
@ -1125,7 +1125,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
/// Assuming the defaults are used, check that all predicates (bounds on the
/// assoc type and where clauses on the trait) hold.
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) {
let bounds = wfcx.tcx().bound_explicit_item_bounds(item.def_id);
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| {
@ -1592,7 +1592,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
}
});
for (bound, bound_span) in tcx
.bound_explicit_item_bounds(opaque_ty.def_id)
.explicit_item_bounds(opaque_ty.def_id)
.subst_iter_copied(tcx, opaque_ty.substs)
{
let bound = self.wfcx.normalize(bound_span, None, bound);

View file

@ -79,14 +79,14 @@ fn opaque_type_bounds<'tcx>(
pub(super) fn explicit_item_bounds(
tcx: TyCtxt<'_>,
def_id: LocalDefId,
) -> &'_ [(ty::Predicate<'_>, Span)] {
) -> ty::EarlyBinder<&'_ [(ty::Predicate<'_>, Span)]> {
match tcx.opt_rpitit_info(def_id.to_def_id()) {
// RPITIT's bounds are the same as opaque type bounds, but with
// a projection self type.
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
let opaque_ty = item.expect_opaque_ty();
return opaque_type_bounds(
return ty::EarlyBinder(opaque_type_bounds(
tcx,
opaque_def_id.expect_local(),
opaque_ty.bounds,
@ -95,7 +95,7 @@ pub(super) fn explicit_item_bounds(
ty::InternalSubsts::identity_for_item(tcx, def_id),
),
item.span,
);
));
}
// These should have been fed!
Some(ty::ImplTraitInTraitData::Impl { .. }) => unreachable!(),
@ -103,7 +103,7 @@ pub(super) fn explicit_item_bounds(
}
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
match tcx.hir().get(hir_id) {
let bounds = match tcx.hir().get(hir_id) {
hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Type(bounds, _),
span,
@ -123,14 +123,15 @@ pub(super) fn explicit_item_bounds(
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
}
_ => bug!("item_bounds called on {:?}", def_id),
}
};
ty::EarlyBinder(bounds)
}
pub(super) fn item_bounds(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
tcx.bound_explicit_item_bounds(def_id).map_bound(|bounds| {
tcx.explicit_item_bounds(def_id).map_bound(|bounds| {
tcx.mk_predicates_from_iter(util::elaborate(
tcx,
bounds.iter().map(|&(bound, _span)| bound),

View file

@ -153,7 +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.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
for pred in tcx.explicit_item_bounds(item_def_id).transpose_iter() {
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
debug!(?pred);