change usages of explicit_item_bounds to bound_explicit_item_bounds
This commit is contained in:
parent
a57fa08f48
commit
0892a7380b
13 changed files with 75 additions and 49 deletions
|
@ -319,9 +319,12 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
|
|||
selftys: vec![],
|
||||
};
|
||||
let prohibit_opaque = tcx
|
||||
.explicit_item_bounds(def_id)
|
||||
.iter()
|
||||
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
|
||||
.bound_explicit_item_bounds(def_id.to_def_id())
|
||||
.transpose_iter()
|
||||
.try_for_each(|bound| {
|
||||
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
|
||||
predicate.visit_with(&mut visitor)
|
||||
});
|
||||
|
||||
if let Some(ty) = prohibit_opaque.break_value() {
|
||||
visitor.visit_item(&item);
|
||||
|
|
|
@ -360,7 +360,10 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
tcx,
|
||||
param_env,
|
||||
item_def_id,
|
||||
tcx.explicit_item_bounds(item_def_id).to_vec(),
|
||||
tcx.bound_explicit_item_bounds(item_def_id.to_def_id())
|
||||
.transpose_iter()
|
||||
.map(|bound| bound.map_bound(|b| *b).subst_identity())
|
||||
.collect::<Vec<_>>(),
|
||||
&FxIndexSet::default(),
|
||||
gat_def_id.def_id,
|
||||
gat_generics,
|
||||
|
@ -1122,10 +1125,11 @@ 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().explicit_item_bounds(item.def_id);
|
||||
let bounds = wfcx.tcx().bound_explicit_item_bounds(item.def_id);
|
||||
|
||||
debug!("check_associated_type_bounds: bounds={:?}", bounds);
|
||||
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
|
||||
let wf_obligations = bounds.transpose_iter().flat_map(|b| {
|
||||
let (bound, bound_span) = b.map_bound(|b| *b).subst_identity();
|
||||
let normalized_bound = wfcx.normalize(span, None, bound);
|
||||
traits::wf::predicate_obligations(
|
||||
wfcx.infcx,
|
||||
|
|
|
@ -130,9 +130,10 @@ pub(super) fn item_bounds(
|
|||
tcx: TyCtxt<'_>,
|
||||
def_id: DefId,
|
||||
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
|
||||
let bounds = tcx.mk_predicates_from_iter(util::elaborate(
|
||||
tcx,
|
||||
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
|
||||
));
|
||||
ty::EarlyBinder(bounds)
|
||||
tcx.bound_explicit_item_bounds(def_id).map_bound(|bounds| {
|
||||
tcx.mk_predicates_from_iter(util::elaborate(
|
||||
tcx,
|
||||
bounds.iter().map(|&(bound, _span)| bound),
|
||||
))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -571,7 +571,8 @@ fn check_must_not_suspend_ty<'tcx>(
|
|||
// FIXME: support adding the attribute to TAITs
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||
let mut has_emitted = false;
|
||||
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
|
||||
for bound in fcx.tcx.bound_explicit_item_bounds(def).transpose_iter() {
|
||||
let predicate = bound.map_bound(|&(predicate, _)| predicate).subst_identity();
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
|
||||
predicate.kind().skip_binder()
|
||||
|
|
|
@ -74,7 +74,9 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
|||
// For every projection predicate in the opaque type's explicit bounds,
|
||||
// check that the type that we're assigning actually satisfies the bounds
|
||||
// of the associated type.
|
||||
for &(pred, pred_span) in cx.tcx.explicit_item_bounds(def_id) {
|
||||
for bound in cx.tcx.bound_explicit_item_bounds(def_id).transpose_iter() {
|
||||
let (pred, pred_span) = bound.map_bound(|b| *b).subst_identity();
|
||||
|
||||
// Liberate bound regions in the predicate since we
|
||||
// don't actually care about lifetimes in this check.
|
||||
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
|
||||
|
|
|
@ -254,23 +254,29 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
}
|
||||
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||
elaborate(cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned())
|
||||
// We only care about self bounds for the impl-trait
|
||||
.filter_only_self()
|
||||
.find_map(|(pred, _span)| {
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||
ref poly_trait_predicate,
|
||||
)) = pred.kind().skip_binder()
|
||||
{
|
||||
let def_id = poly_trait_predicate.trait_ref.def_id;
|
||||
elaborate(
|
||||
cx.tcx,
|
||||
cx.tcx
|
||||
.bound_explicit_item_bounds(def)
|
||||
.transpose_iter()
|
||||
.map(|bound| bound.map_bound(|b| *b).subst_identity()),
|
||||
)
|
||||
// We only care about self bounds for the impl-trait
|
||||
.filter_only_self()
|
||||
.find_map(|(pred, _span)| {
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||
ref poly_trait_predicate,
|
||||
)) = pred.kind().skip_binder()
|
||||
{
|
||||
let def_id = poly_trait_predicate.trait_ref.def_id;
|
||||
|
||||
is_def_must_use(cx, def_id, span)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
|
||||
is_def_must_use(cx, def_id, span)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
|
||||
}
|
||||
ty::Dynamic(binders, _, _) => binders.iter().find_map(|predicate| {
|
||||
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder()
|
||||
|
|
|
@ -1611,7 +1611,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
|
||||
let future_trait = self.require_lang_item(LangItem::Future, None);
|
||||
|
||||
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
||||
self.bound_explicit_item_bounds(*def_id).skip_binder().iter().any(|(predicate, _)| {
|
||||
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
|
||||
return false;
|
||||
};
|
||||
|
|
|
@ -1800,7 +1800,9 @@ fn check_must_not_suspend_ty<'tcx>(
|
|||
// FIXME: support adding the attribute to TAITs
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||
let mut has_emitted = false;
|
||||
for &(predicate, _) in tcx.explicit_item_bounds(def) {
|
||||
for bound in tcx.bound_explicit_item_bounds(def).transpose_iter() {
|
||||
let predicate = bound.map_bound(|&(pred, _)| pred).subst_identity();
|
||||
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
|
||||
predicate.kind().skip_binder()
|
||||
|
|
|
@ -269,7 +269,7 @@ where
|
|||
// and are visited by shallow visitors.
|
||||
self.visit_predicates(ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: tcx.explicit_item_bounds(def_id),
|
||||
predicates: tcx.bound_explicit_item_bounds(def_id).skip_binder(),
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
@ -1784,7 +1784,10 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
|||
fn bounds(&mut self) -> &mut Self {
|
||||
self.visit_predicates(ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: self.tcx.explicit_item_bounds(self.item_def_id),
|
||||
predicates: self
|
||||
.tcx
|
||||
.bound_explicit_item_bounds(self.item_def_id.to_def_id())
|
||||
.skip_binder(),
|
||||
});
|
||||
self
|
||||
}
|
||||
|
|
|
@ -297,8 +297,9 @@ fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span
|
|||
tcx.associated_items(trait_def_id)
|
||||
.in_definition_order()
|
||||
.filter(|item| item.kind == ty::AssocKind::Type)
|
||||
.flat_map(|item| tcx.explicit_item_bounds(item.def_id))
|
||||
.filter_map(|pred_span| predicate_references_self(tcx, *pred_span))
|
||||
.flat_map(|item| tcx.bound_explicit_item_bounds(item.def_id).transpose_iter())
|
||||
.map(|bound| bound.map_bound(|b| *b).subst_identity())
|
||||
.filter_map(|pred_span| predicate_references_self(tcx, pred_span))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue