Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors
Switch to `EarlyBinder` for `explicit_item_bounds` Part of the work to finish https://github.com/rust-lang/rust/issues/105779. This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`. r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 😃)
This commit is contained in:
commit
297b222066
@ -702,7 +702,7 @@ fn suggest_borrow_fn_like(
|
|||||||
.copied()
|
.copied()
|
||||||
.find_map(find_fn_kind_from_did),
|
.find_map(find_fn_kind_from_did),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => tcx
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => tcx
|
||||||
.bound_explicit_item_bounds(def_id)
|
.explicit_item_bounds(def_id)
|
||||||
.subst_iter_copied(tcx, substs)
|
.subst_iter_copied(tcx, substs)
|
||||||
.find_map(find_fn_kind_from_did),
|
.find_map(find_fn_kind_from_did),
|
||||||
ty::Closure(_, substs) => match substs.as_closure().kind() {
|
ty::Closure(_, substs) => match substs.as_closure().kind() {
|
||||||
|
@ -320,7 +320,7 @@ fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
|
|||||||
};
|
};
|
||||||
let prohibit_opaque = tcx
|
let prohibit_opaque = tcx
|
||||||
.explicit_item_bounds(def_id)
|
.explicit_item_bounds(def_id)
|
||||||
.iter()
|
.subst_identity_iter_copied()
|
||||||
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
|
.try_for_each(|(predicate, _)| predicate.visit_with(&mut visitor));
|
||||||
|
|
||||||
if let Some(ty) = prohibit_opaque.break_value() {
|
if let Some(ty) = prohibit_opaque.break_value() {
|
||||||
|
@ -839,7 +839,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
|||||||
});
|
});
|
||||||
self.types.insert(proj.def_id, (infer_ty, proj.substs));
|
self.types.insert(proj.def_id, (infer_ty, proj.substs));
|
||||||
// Recurse into bounds
|
// 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 = pred.fold_with(self);
|
||||||
let pred = self.ocx.normalize(
|
let pred = self.ocx.normalize(
|
||||||
&ObligationCause::misc(self.span, self.body_id),
|
&ObligationCause::misc(self.span, self.body_id),
|
||||||
@ -2023,7 +2023,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let obligations: Vec<_> = 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)
|
.subst_iter_copied(tcx, rebased_substs)
|
||||||
.map(|(concrete_ty_bound, span)| {
|
.map(|(concrete_ty_bound, span)| {
|
||||||
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
|
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
|
||||||
|
@ -360,7 +360,9 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||||||
tcx,
|
tcx,
|
||||||
param_env,
|
param_env,
|
||||||
item_def_id,
|
item_def_id,
|
||||||
tcx.explicit_item_bounds(item_def_id).to_vec(),
|
tcx.explicit_item_bounds(item_def_id)
|
||||||
|
.subst_identity_iter_copied()
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
&FxIndexSet::default(),
|
&FxIndexSet::default(),
|
||||||
gat_def_id.def_id,
|
gat_def_id.def_id,
|
||||||
gat_generics,
|
gat_generics,
|
||||||
@ -1125,7 +1127,7 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
|
|||||||
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
|
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
|
||||||
|
|
||||||
debug!("check_associated_type_bounds: bounds={:?}", bounds);
|
debug!("check_associated_type_bounds: bounds={:?}", bounds);
|
||||||
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
|
let wf_obligations = bounds.subst_identity_iter_copied().flat_map(|(bound, bound_span)| {
|
||||||
let normalized_bound = wfcx.normalize(span, None, bound);
|
let normalized_bound = wfcx.normalize(span, None, bound);
|
||||||
traits::wf::predicate_obligations(
|
traits::wf::predicate_obligations(
|
||||||
wfcx.infcx,
|
wfcx.infcx,
|
||||||
@ -1588,7 +1590,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<!> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (bound, bound_span) in 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)
|
.subst_iter_copied(tcx, opaque_ty.substs)
|
||||||
{
|
{
|
||||||
let bound = self.wfcx.normalize(bound_span, None, bound);
|
let bound = self.wfcx.normalize(bound_span, None, bound);
|
||||||
|
@ -79,14 +79,14 @@ fn opaque_type_bounds<'tcx>(
|
|||||||
pub(super) fn explicit_item_bounds(
|
pub(super) fn explicit_item_bounds(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
) -> &'_ [(ty::Predicate<'_>, Span)] {
|
) -> ty::EarlyBinder<&'_ [(ty::Predicate<'_>, Span)]> {
|
||||||
match tcx.opt_rpitit_info(def_id.to_def_id()) {
|
match tcx.opt_rpitit_info(def_id.to_def_id()) {
|
||||||
// RPITIT's bounds are the same as opaque type bounds, but with
|
// RPITIT's bounds are the same as opaque type bounds, but with
|
||||||
// a projection self type.
|
// a projection self type.
|
||||||
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
|
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
|
||||||
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
|
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
|
||||||
let opaque_ty = item.expect_opaque_ty();
|
let opaque_ty = item.expect_opaque_ty();
|
||||||
return opaque_type_bounds(
|
return ty::EarlyBinder(opaque_type_bounds(
|
||||||
tcx,
|
tcx,
|
||||||
opaque_def_id.expect_local(),
|
opaque_def_id.expect_local(),
|
||||||
opaque_ty.bounds,
|
opaque_ty.bounds,
|
||||||
@ -95,7 +95,7 @@ pub(super) fn explicit_item_bounds(
|
|||||||
ty::InternalSubsts::identity_for_item(tcx, def_id),
|
ty::InternalSubsts::identity_for_item(tcx, def_id),
|
||||||
),
|
),
|
||||||
item.span,
|
item.span,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
// These should have been fed!
|
// These should have been fed!
|
||||||
Some(ty::ImplTraitInTraitData::Impl { .. }) => unreachable!(),
|
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);
|
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 {
|
hir::Node::TraitItem(hir::TraitItem {
|
||||||
kind: hir::TraitItemKind::Type(bounds, _),
|
kind: hir::TraitItemKind::Type(bounds, _),
|
||||||
span,
|
span,
|
||||||
@ -123,16 +123,18 @@ pub(super) fn explicit_item_bounds(
|
|||||||
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
|
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
|
||||||
}
|
}
|
||||||
_ => bug!("item_bounds called on {:?}", def_id),
|
_ => bug!("item_bounds called on {:?}", def_id),
|
||||||
}
|
};
|
||||||
|
ty::EarlyBinder(bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn item_bounds(
|
pub(super) fn item_bounds(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
|
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
|
||||||
let bounds = tcx.mk_predicates_from_iter(util::elaborate(
|
tcx.explicit_item_bounds(def_id).map_bound(|bounds| {
|
||||||
tcx,
|
tcx.mk_predicates_from_iter(util::elaborate(
|
||||||
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
|
tcx,
|
||||||
));
|
bounds.iter().map(|&(bound, _span)| bound),
|
||||||
ty::EarlyBinder(bounds)
|
))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
|||||||
let mut collector =
|
let mut collector =
|
||||||
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
|
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
|
||||||
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id);
|
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).subst_iter_copied(tcx, id_substs) {
|
||||||
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
|
|
||||||
debug!(?pred);
|
debug!(?pred);
|
||||||
|
|
||||||
// We only ignore opaque type substs if the opaque type is the outermost type.
|
// We only ignore opaque type substs if the opaque type is the outermost type.
|
||||||
|
@ -530,7 +530,7 @@ pub(crate) fn opt_suggest_box_span(
|
|||||||
for ty in [first_ty, second_ty] {
|
for ty in [first_ty, second_ty] {
|
||||||
for (pred, _) in self
|
for (pred, _) in self
|
||||||
.tcx
|
.tcx
|
||||||
.bound_explicit_item_bounds(rpit_def_id)
|
.explicit_item_bounds(rpit_def_id)
|
||||||
.subst_iter_copied(self.tcx, substs)
|
.subst_iter_copied(self.tcx, substs)
|
||||||
{
|
{
|
||||||
let pred = pred.kind().rebind(match pred.kind().skip_binder() {
|
let pred = pred.kind().rebind(match pred.kind().skip_binder() {
|
||||||
|
@ -172,7 +172,7 @@ fn deduce_closure_signature(
|
|||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
|
||||||
.deduce_closure_signature_from_predicates(
|
.deduce_closure_signature_from_predicates(
|
||||||
expected_ty,
|
expected_ty,
|
||||||
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
|
self.tcx.explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
|
||||||
),
|
),
|
||||||
ty::Dynamic(ref object_type, ..) => {
|
ty::Dynamic(ref object_type, ..) => {
|
||||||
let sig = object_type.projection_bounds().find_map(|pb| {
|
let sig = object_type.projection_bounds().find_map(|pb| {
|
||||||
@ -713,13 +713,13 @@ fn deduce_future_output_from_obligations(
|
|||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
|
||||||
.tcx
|
.tcx
|
||||||
.bound_explicit_item_bounds(def_id)
|
.explicit_item_bounds(def_id)
|
||||||
.subst_iter_copied(self.tcx, substs)
|
.subst_iter_copied(self.tcx, substs)
|
||||||
.find_map(|(p, s)| get_future_output(p, s))?,
|
.find_map(|(p, s)| get_future_output(p, s))?,
|
||||||
ty::Error(_) => return None,
|
ty::Error(_) => return None,
|
||||||
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
|
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
|
||||||
.tcx
|
.tcx
|
||||||
.bound_explicit_item_bounds(proj.def_id)
|
.explicit_item_bounds(proj.def_id)
|
||||||
.subst_iter_copied(self.tcx, proj.substs)
|
.subst_iter_copied(self.tcx, proj.substs)
|
||||||
.find_map(|(p, s)| get_future_output(p, s))?,
|
.find_map(|(p, s)| get_future_output(p, s))?,
|
||||||
_ => span_bug!(
|
_ => span_bug!(
|
||||||
|
@ -571,7 +571,7 @@ fn check_must_not_suspend_ty<'tcx>(
|
|||||||
// FIXME: support adding the attribute to TAITs
|
// FIXME: support adding the attribute to TAITs
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||||
let mut has_emitted = false;
|
let mut has_emitted = false;
|
||||||
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
|
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def).skip_binder() {
|
||||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
// 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)) =
|
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
|
||||||
predicate.kind().skip_binder()
|
predicate.kind().skip_binder()
|
||||||
|
@ -402,7 +402,7 @@ pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
|||||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||||
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
|
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
|
||||||
|
|
||||||
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
|
self.tcx.explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
|
||||||
|(predicate, _)| {
|
|(predicate, _)| {
|
||||||
predicate
|
predicate
|
||||||
.kind()
|
.kind()
|
||||||
|
@ -540,7 +540,7 @@ fn register_hidden_type(
|
|||||||
.obligations;
|
.obligations;
|
||||||
}
|
}
|
||||||
|
|
||||||
let item_bounds = tcx.bound_explicit_item_bounds(def_id.to_def_id());
|
let item_bounds = tcx.explicit_item_bounds(def_id);
|
||||||
|
|
||||||
for (predicate, _) in item_bounds.subst_iter_copied(tcx, substs) {
|
for (predicate, _) in item_bounds.subst_iter_copied(tcx, substs) {
|
||||||
let predicate = predicate.fold_with(&mut BottomUpFolder {
|
let predicate = predicate.fold_with(&mut BottomUpFolder {
|
||||||
|
@ -74,7 +74,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
|||||||
// For every projection predicate in the opaque type's explicit bounds,
|
// For every projection predicate in the opaque type's explicit bounds,
|
||||||
// check that the type that we're assigning actually satisfies the bounds
|
// check that the type that we're assigning actually satisfies the bounds
|
||||||
// of the associated type.
|
// of the associated type.
|
||||||
for &(pred, pred_span) in cx.tcx.explicit_item_bounds(def_id) {
|
for (pred, pred_span) in cx.tcx.explicit_item_bounds(def_id).subst_identity_iter_copied() {
|
||||||
// Liberate bound regions in the predicate since we
|
// Liberate bound regions in the predicate since we
|
||||||
// don't actually care about lifetimes in this check.
|
// don't actually care about lifetimes in this check.
|
||||||
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
|
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
|
||||||
@ -112,7 +112,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
|||||||
// with `impl Send: OtherTrait`.
|
// with `impl Send: OtherTrait`.
|
||||||
for (assoc_pred, assoc_pred_span) in cx
|
for (assoc_pred, assoc_pred_span) in cx
|
||||||
.tcx
|
.tcx
|
||||||
.bound_explicit_item_bounds(proj.projection_ty.def_id)
|
.explicit_item_bounds(proj.projection_ty.def_id)
|
||||||
.subst_iter_copied(cx.tcx, &proj.projection_ty.substs)
|
.subst_iter_copied(cx.tcx, &proj.projection_ty.substs)
|
||||||
{
|
{
|
||||||
let assoc_pred = assoc_pred.fold_with(proj_replacer);
|
let assoc_pred = assoc_pred.fold_with(proj_replacer);
|
||||||
|
@ -254,7 +254,7 @@ fn is_ty_must_use<'tcx>(
|
|||||||
}
|
}
|
||||||
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
|
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
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.explicit_item_bounds(def).subst_identity_iter_copied())
|
||||||
// We only care about self bounds for the impl-trait
|
// We only care about self bounds for the impl-trait
|
||||||
.filter_only_self()
|
.filter_only_self()
|
||||||
.find_map(|(pred, _span)| {
|
.find_map(|(pred, _span)| {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
use rustc_middle::ty::codec::TyDecoder;
|
use rustc_middle::ty::codec::TyDecoder;
|
||||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||||
use rustc_middle::ty::GeneratorDiagnosticData;
|
use rustc_middle::ty::GeneratorDiagnosticData;
|
||||||
use rustc_middle::ty::{self, ParameterizedOverTcx, Ty, TyCtxt, Visibility};
|
use rustc_middle::ty::{self, ParameterizedOverTcx, Predicate, Ty, TyCtxt, Visibility};
|
||||||
use rustc_serialize::opaque::MemDecoder;
|
use rustc_serialize::opaque::MemDecoder;
|
||||||
use rustc_serialize::{Decodable, Decoder};
|
use rustc_serialize::{Decodable, Decoder};
|
||||||
use rustc_session::cstore::{
|
use rustc_session::cstore::{
|
||||||
@ -857,6 +857,20 @@ fn load_proc_macro(self, id: DefIndex, sess: &Session) -> SyntaxExtension {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_explicit_item_bounds(
|
||||||
|
self,
|
||||||
|
index: DefIndex,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
) -> ty::EarlyBinder<&'tcx [(Predicate<'tcx>, Span)]> {
|
||||||
|
let lazy = self.root.tables.explicit_item_bounds.get(self, index);
|
||||||
|
let output = if lazy.is_default() {
|
||||||
|
&mut []
|
||||||
|
} else {
|
||||||
|
tcx.arena.alloc_from_iter(lazy.decode((self, tcx)))
|
||||||
|
};
|
||||||
|
ty::EarlyBinder(&*output)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_variant(self, kind: &DefKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
|
fn get_variant(self, kind: &DefKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
|
||||||
let adt_kind = match kind {
|
let adt_kind = match kind {
|
||||||
DefKind::Variant => ty::AdtKind::Enum,
|
DefKind::Variant => ty::AdtKind::Enum,
|
||||||
|
@ -203,7 +203,7 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
provide! { tcx, def_id, other, cdata,
|
provide! { tcx, def_id, other, cdata,
|
||||||
explicit_item_bounds => { table_defaulted_array }
|
explicit_item_bounds => { cdata.get_explicit_item_bounds(def_id.index, tcx) }
|
||||||
explicit_predicates_of => { table }
|
explicit_predicates_of => { table }
|
||||||
generics_of => { table }
|
generics_of => { table }
|
||||||
inferred_outlives_of => { table_defaulted_array }
|
inferred_outlives_of => { table_defaulted_array }
|
||||||
|
@ -1423,7 +1423,7 @@ fn encode_info_for_mod(&mut self, local_def_id: LocalDefId) {
|
|||||||
|
|
||||||
fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
|
fn encode_explicit_item_bounds(&mut self, def_id: DefId) {
|
||||||
debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id);
|
debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id);
|
||||||
let bounds = self.tcx.explicit_item_bounds(def_id);
|
let bounds = self.tcx.explicit_item_bounds(def_id).skip_binder();
|
||||||
record_defaulted_array!(self.tables.explicit_item_bounds[def_id] <- bounds);
|
record_defaulted_array!(self.tables.explicit_item_bounds[def_id] <- bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@
|
|||||||
/// `key` is the `DefId` of the associated type or opaque type.
|
/// `key` is the `DefId` of the associated type or opaque type.
|
||||||
///
|
///
|
||||||
/// Bounds from the parent (e.g. with nested impl trait) are not included.
|
/// Bounds from the parent (e.g. with nested impl trait) are not included.
|
||||||
query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
query explicit_item_bounds(key: DefId) -> ty::EarlyBinder<&'tcx [(ty::Predicate<'tcx>, Span)]> {
|
||||||
desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
|
||||||
cache_on_disk_if { key.is_local() }
|
cache_on_disk_if { key.is_local() }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
|
@ -1603,7 +1603,7 @@ pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
|
|||||||
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
|
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
|
||||||
let future_trait = self.require_lang_item(LangItem::Future, None);
|
let future_trait = self.require_lang_item(LangItem::Future, None);
|
||||||
|
|
||||||
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
self.explicit_item_bounds(def_id).skip_binder().iter().any(|&(predicate, _)| {
|
||||||
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
|
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -914,7 +914,7 @@ fn pretty_print_opaque_impl_type(
|
|||||||
|
|
||||||
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
||||||
// by looking up the projections associated with the def_id.
|
// by looking up the projections associated with the def_id.
|
||||||
let bounds = tcx.bound_explicit_item_bounds(def_id);
|
let bounds = tcx.explicit_item_bounds(def_id);
|
||||||
|
|
||||||
let mut traits = FxIndexMap::default();
|
let mut traits = FxIndexMap::default();
|
||||||
let mut fn_traits = FxIndexMap::default();
|
let mut fn_traits = FxIndexMap::default();
|
||||||
|
@ -612,6 +612,12 @@ pub fn subst_iter(
|
|||||||
) -> SubstIter<'s, 'tcx, I> {
|
) -> SubstIter<'s, 'tcx, I> {
|
||||||
SubstIter { it: self.0.into_iter(), tcx, substs }
|
SubstIter { it: self.0.into_iter(), tcx, substs }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Similar to [`subst_identity`](EarlyBinder::subst_identity),
|
||||||
|
/// but on an iterator of `TypeFoldable` values.
|
||||||
|
pub fn subst_identity_iter(self) -> I::IntoIter {
|
||||||
|
self.0.into_iter()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SubstIter<'s, 'tcx, I: IntoIterator> {
|
pub struct SubstIter<'s, 'tcx, I: IntoIterator> {
|
||||||
@ -664,6 +670,12 @@ pub fn subst_iter_copied(
|
|||||||
) -> SubstIterCopied<'s, 'tcx, I> {
|
) -> SubstIterCopied<'s, 'tcx, I> {
|
||||||
SubstIterCopied { it: self.0.into_iter(), tcx, substs }
|
SubstIterCopied { it: self.0.into_iter(), tcx, substs }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Similar to [`subst_identity`](EarlyBinder::subst_identity),
|
||||||
|
/// but on an iterator of values that deref to a `TypeFoldable`.
|
||||||
|
pub fn subst_identity_iter_copied(self) -> impl Iterator<Item = <I::Item as Deref>::Target> {
|
||||||
|
self.0.into_iter().map(|v| *v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SubstIterCopied<'a, 'tcx, I: IntoIterator> {
|
pub struct SubstIterCopied<'a, 'tcx, I: IntoIterator> {
|
||||||
|
@ -701,13 +701,6 @@ pub fn try_expand_impl_trait_type(
|
|||||||
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
|
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bound_explicit_item_bounds(
|
|
||||||
self,
|
|
||||||
def_id: DefId,
|
|
||||||
) -> ty::EarlyBinder<&'tcx [(ty::Predicate<'tcx>, rustc_span::Span)]> {
|
|
||||||
ty::EarlyBinder(self.explicit_item_bounds(def_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns names of captured upvars for closures and generators.
|
/// Returns names of captured upvars for closures and generators.
|
||||||
///
|
///
|
||||||
/// Here are some examples:
|
/// Here are some examples:
|
||||||
|
@ -1800,7 +1800,7 @@ fn check_must_not_suspend_ty<'tcx>(
|
|||||||
// FIXME: support adding the attribute to TAITs
|
// FIXME: support adding the attribute to TAITs
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||||
let mut has_emitted = false;
|
let mut has_emitted = false;
|
||||||
for &(predicate, _) in tcx.explicit_item_bounds(def) {
|
for &(predicate, _) in tcx.explicit_item_bounds(def).skip_binder() {
|
||||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
// 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)) =
|
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
|
||||||
predicate.kind().skip_binder()
|
predicate.kind().skip_binder()
|
||||||
|
@ -269,7 +269,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<V::BreakTy> {
|
|||||||
// and are visited by shallow visitors.
|
// and are visited by shallow visitors.
|
||||||
self.visit_predicates(ty::GenericPredicates {
|
self.visit_predicates(ty::GenericPredicates {
|
||||||
parent: None,
|
parent: None,
|
||||||
predicates: tcx.explicit_item_bounds(def_id),
|
predicates: tcx.explicit_item_bounds(def_id).skip_binder(),
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1784,7 +1784,7 @@ fn predicates(&mut self) -> &mut Self {
|
|||||||
fn bounds(&mut self) -> &mut Self {
|
fn bounds(&mut self) -> &mut Self {
|
||||||
self.visit_predicates(ty::GenericPredicates {
|
self.visit_predicates(ty::GenericPredicates {
|
||||||
parent: None,
|
parent: None,
|
||||||
predicates: self.tcx.explicit_item_bounds(self.item_def_id),
|
predicates: self.tcx.explicit_item_bounds(self.item_def_id).skip_binder(),
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -297,8 +297,8 @@ fn predicates_reference_self(
|
|||||||
tcx.associated_items(trait_def_id)
|
tcx.associated_items(trait_def_id)
|
||||||
.in_definition_order()
|
.in_definition_order()
|
||||||
.filter(|item| item.kind == ty::AssocKind::Type)
|
.filter(|item| item.kind == ty::AssocKind::Type)
|
||||||
.flat_map(|item| tcx.explicit_item_bounds(item.def_id))
|
.flat_map(|item| tcx.explicit_item_bounds(item.def_id).subst_identity_iter_copied())
|
||||||
.filter_map(|pred_span| predicate_references_self(tcx, *pred_span))
|
.filter_map(|pred_span| predicate_references_self(tcx, pred_span))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,12 +50,11 @@ fn bounds_for<T>(&self, def_id: DefId, bound_vars: SubstsRef<'tcx>) -> Vec<T>
|
|||||||
where
|
where
|
||||||
ty::Predicate<'tcx>: LowerInto<'tcx, std::option::Option<T>>,
|
ty::Predicate<'tcx>: LowerInto<'tcx, std::option::Option<T>>,
|
||||||
{
|
{
|
||||||
let bounds = self.interner.tcx.bound_explicit_item_bounds(def_id);
|
self.interner
|
||||||
bounds
|
.tcx
|
||||||
.0
|
.explicit_item_bounds(def_id)
|
||||||
.iter()
|
.subst_iter_copied(self.interner.tcx, &bound_vars)
|
||||||
.map(|(bound, _)| bounds.rebind(*bound).subst(self.interner.tcx, &bound_vars))
|
.filter_map(|(bound, _)| LowerInto::<Option<_>>::lower_into(bound, self.interner))
|
||||||
.filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, self.interner))
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -506,15 +505,11 @@ fn opaque_ty_data(
|
|||||||
|
|
||||||
let identity_substs = InternalSubsts::identity_for_item(self.interner.tcx, opaque_ty_id.0);
|
let identity_substs = InternalSubsts::identity_for_item(self.interner.tcx, opaque_ty_id.0);
|
||||||
|
|
||||||
let explicit_item_bounds = self.interner.tcx.bound_explicit_item_bounds(opaque_ty_id.0);
|
let explicit_item_bounds = self.interner.tcx.explicit_item_bounds(opaque_ty_id.0);
|
||||||
let bounds =
|
let bounds =
|
||||||
explicit_item_bounds
|
explicit_item_bounds
|
||||||
.0
|
.subst_iter_copied(self.interner.tcx, &bound_vars)
|
||||||
.iter()
|
|
||||||
.map(|(bound, _)| {
|
.map(|(bound, _)| {
|
||||||
explicit_item_bounds.rebind(*bound).subst(self.interner.tcx, &bound_vars)
|
|
||||||
})
|
|
||||||
.map(|bound| {
|
|
||||||
bound.fold_with(&mut ReplaceOpaqueTyFolder {
|
bound.fold_with(&mut ReplaceOpaqueTyFolder {
|
||||||
tcx: self.interner.tcx,
|
tcx: self.interner.tcx,
|
||||||
opaque_ty_id,
|
opaque_ty_id,
|
||||||
|
@ -422,8 +422,8 @@ fn clean_projection<'tcx>(
|
|||||||
let bounds = cx
|
let bounds = cx
|
||||||
.tcx
|
.tcx
|
||||||
.explicit_item_bounds(ty.skip_binder().def_id)
|
.explicit_item_bounds(ty.skip_binder().def_id)
|
||||||
.iter()
|
.subst_iter_copied(cx.tcx, ty.skip_binder().substs)
|
||||||
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.skip_binder().substs))
|
.map(|(pred, _)| pred)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
return clean_middle_opaque_bounds(cx, bounds);
|
return clean_middle_opaque_bounds(cx, bounds);
|
||||||
}
|
}
|
||||||
@ -1315,10 +1315,11 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let ty::TraitContainer = assoc_item.container {
|
if let ty::TraitContainer = assoc_item.container {
|
||||||
let bounds = tcx.explicit_item_bounds(assoc_item.def_id);
|
let bounds =
|
||||||
|
tcx.explicit_item_bounds(assoc_item.def_id).subst_identity_iter_copied();
|
||||||
let predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
|
let predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
|
||||||
let 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(
|
let mut generics = clean_ty_generics(
|
||||||
cx,
|
cx,
|
||||||
tcx.generics_of(assoc_item.def_id),
|
tcx.generics_of(assoc_item.def_id),
|
||||||
@ -1845,8 +1846,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
|||||||
let bounds = cx
|
let bounds = cx
|
||||||
.tcx
|
.tcx
|
||||||
.explicit_item_bounds(def_id)
|
.explicit_item_bounds(def_id)
|
||||||
.iter()
|
.subst_iter_copied(cx.tcx, substs)
|
||||||
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, substs))
|
.map(|(bound, _)| bound)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
clean_middle_opaque_bounds(cx, bounds)
|
clean_middle_opaque_bounds(cx, bounds)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use rustc_hir::{Body, FnDecl};
|
use rustc_hir::{Body, FnDecl};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
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_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::{sym, Span};
|
||||||
@ -66,8 +66,7 @@ fn check_fn(
|
|||||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
|
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.explicit_item_bounds(def_id);
|
||||||
let mut is_future = false;
|
let mut is_future = false;
|
||||||
for &(p, _span) in preds {
|
for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
|
||||||
let p = EarlyBinder(p).subst(cx.tcx, substs);
|
|
||||||
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
|
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() {
|
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
|
||||||
is_future = true;
|
is_future = true;
|
||||||
|
@ -90,7 +90,7 @@ fn contains_ty_adt_constructor_opaque_inner<'tcx>(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
|
for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).subst_identity_iter_copied() {
|
||||||
match predicate.kind().skip_binder() {
|
match predicate.kind().skip_binder() {
|
||||||
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
|
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
|
||||||
// and check substituions to find `U`.
|
// and check substituions to find `U`.
|
||||||
@ -267,7 +267,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::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() {
|
||||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().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) {
|
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
||||||
return true;
|
return true;
|
||||||
@ -743,7 +743,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
|
|||||||
|
|
||||||
for (pred, _) in cx
|
for (pred, _) in cx
|
||||||
.tcx
|
.tcx
|
||||||
.bound_explicit_item_bounds(ty.def_id)
|
.explicit_item_bounds(ty.def_id)
|
||||||
.subst_iter_copied(cx.tcx, ty.substs)
|
.subst_iter_copied(cx.tcx, ty.substs)
|
||||||
{
|
{
|
||||||
match pred.kind().skip_binder() {
|
match pred.kind().skip_binder() {
|
||||||
|
Loading…
Reference in New Issue
Block a user