mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
change usages of explicit_item_bounds to bound_explicit_item_bounds
This commit is contained in:
parent
a57fa08f48
commit
0892a7380b
@ -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.bound_explicit_item_bounds(def_id).map_bound(|bounds| {
|
||||
tcx.mk_predicates_from_iter(util::elaborate(
|
||||
tcx,
|
||||
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
|
||||
));
|
||||
ty::EarlyBinder(bounds)
|
||||
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,7 +254,13 @@ 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())
|
||||
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)| {
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -421,9 +421,9 @@ fn clean_projection<'tcx>(
|
||||
if cx.tcx.is_impl_trait_in_trait(ty.skip_binder().def_id) {
|
||||
let bounds = cx
|
||||
.tcx
|
||||
.explicit_item_bounds(ty.skip_binder().def_id)
|
||||
.iter()
|
||||
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.skip_binder().substs))
|
||||
.bound_explicit_item_bounds(ty.skip_binder().def_id)
|
||||
.subst_iter_copied(cx.tcx, ty.skip_binder().substs)
|
||||
.map(|(pred, _)| pred)
|
||||
.collect::<Vec<_>>();
|
||||
return clean_middle_opaque_bounds(cx, bounds);
|
||||
}
|
||||
@ -1315,10 +1315,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
|
||||
}
|
||||
|
||||
if let ty::TraitContainer = assoc_item.container {
|
||||
let bounds = tcx.explicit_item_bounds(assoc_item.def_id);
|
||||
let bounds = tcx
|
||||
.bound_explicit_item_bounds(assoc_item.def_id)
|
||||
.transpose_iter()
|
||||
.map(|bound| bound.map_bound(|b| *b).subst_identity());
|
||||
let predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
|
||||
let predicates =
|
||||
tcx.arena.alloc_from_iter(bounds.into_iter().chain(predicates).copied());
|
||||
tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied()));
|
||||
let mut generics = clean_ty_generics(
|
||||
cx,
|
||||
tcx.generics_of(assoc_item.def_id),
|
||||
@ -1844,9 +1847,9 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
||||
// by looking up the bounds associated with the def_id.
|
||||
let bounds = cx
|
||||
.tcx
|
||||
.explicit_item_bounds(def_id)
|
||||
.iter()
|
||||
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, substs))
|
||||
.bound_explicit_item_bounds(def_id)
|
||||
.subst_iter_copied(cx.tcx, substs)
|
||||
.map(|(bound, _)| bound)
|
||||
.collect::<Vec<_>>();
|
||||
clean_middle_opaque_bounds(cx, bounds)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, FnDecl};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind};
|
||||
use rustc_middle::ty::{self, AliasTy, Clause, PredicateKind};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::{sym, Span};
|
||||
@ -64,10 +64,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||
}
|
||||
let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner());
|
||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
|
||||
let preds = cx.tcx.explicit_item_bounds(def_id);
|
||||
let preds = cx.tcx.bound_explicit_item_bounds(def_id);
|
||||
let mut is_future = false;
|
||||
for &(p, _span) in preds {
|
||||
let p = EarlyBinder(p).subst(cx.tcx, substs);
|
||||
for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
|
||||
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
|
||||
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
|
||||
is_future = true;
|
||||
|
@ -90,7 +90,8 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
|
||||
return false;
|
||||
}
|
||||
|
||||
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
|
||||
for bound in cx.tcx.bound_explicit_item_bounds(def_id).transpose_iter() {
|
||||
let (predicate, _span) = bound.map_bound(|b| *b).subst_identity();
|
||||
match predicate.kind().skip_binder() {
|
||||
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
|
||||
// and check substituions to find `U`.
|
||||
@ -267,7 +268,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
},
|
||||
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
||||
for (predicate, _) in cx.tcx.bound_explicit_item_bounds(*def_id).skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
|
||||
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user