Stop using ty::GenericPredicates for non-predicates_of queries
This commit is contained in:
parent
ac77e88f7a
commit
92004523db
20 changed files with 101 additions and 98 deletions
|
@ -420,7 +420,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
span: Span,
|
||||
def_id: LocalDefId,
|
||||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name))
|
||||
}
|
||||
|
||||
|
|
|
@ -580,24 +580,24 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
|||
/// Ensures that the super-predicates of the trait with a `DefId`
|
||||
/// of `trait_def_id` are lowered and stored. This also ensures that
|
||||
/// the transitive super-predicates are lowered.
|
||||
pub(super) fn explicit_super_predicates_of(
|
||||
tcx: TyCtxt<'_>,
|
||||
pub(super) fn explicit_super_predicates_of<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_def_id: LocalDefId,
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
implied_predicates_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
|
||||
}
|
||||
|
||||
pub(super) fn explicit_supertraits_containing_assoc_item(
|
||||
tcx: TyCtxt<'_>,
|
||||
pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
(trait_def_id, assoc_name): (DefId, Ident),
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
implied_predicates_with_filter(tcx, trait_def_id, PredicateFilter::SelfThatDefines(assoc_name))
|
||||
}
|
||||
|
||||
pub(super) fn explicit_implied_predicates_of(
|
||||
tcx: TyCtxt<'_>,
|
||||
pub(super) fn explicit_implied_predicates_of<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_def_id: LocalDefId,
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
implied_predicates_with_filter(
|
||||
tcx,
|
||||
trait_def_id.to_def_id(),
|
||||
|
@ -612,11 +612,11 @@ pub(super) fn explicit_implied_predicates_of(
|
|||
/// Ensures that the super-predicates of the trait with a `DefId`
|
||||
/// of `trait_def_id` are lowered and stored. This also ensures that
|
||||
/// the transitive super-predicates are lowered.
|
||||
pub(super) fn implied_predicates_with_filter(
|
||||
tcx: TyCtxt<'_>,
|
||||
pub(super) fn implied_predicates_with_filter<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_def_id: DefId,
|
||||
filter: PredicateFilter,
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
let Some(trait_def_id) = trait_def_id.as_local() else {
|
||||
// if `assoc_name` is None, then the query should've been redirected to an
|
||||
// external provider
|
||||
|
@ -679,20 +679,16 @@ pub(super) fn implied_predicates_with_filter(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: implied_bounds,
|
||||
effects_min_tys: ty::List::empty(),
|
||||
}
|
||||
ty::EarlyBinder::bind(implied_bounds)
|
||||
}
|
||||
|
||||
/// Returns the predicates defined on `item_def_id` of the form
|
||||
/// `X: Foo` where `X` is the type parameter `def_id`.
|
||||
#[instrument(level = "trace", skip(tcx))]
|
||||
pub(super) fn type_param_predicates(
|
||||
tcx: TyCtxt<'_>,
|
||||
pub(super) fn type_param_predicates<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
use rustc_hir::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
|
@ -713,18 +709,20 @@ pub(super) fn type_param_predicates(
|
|||
tcx.generics_of(item_def_id).parent.map(|def_id| def_id.expect_local())
|
||||
};
|
||||
|
||||
let mut result = parent
|
||||
.map(|parent| {
|
||||
let icx = ItemCtxt::new(tcx, parent);
|
||||
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let result = if let Some(parent) = parent {
|
||||
let icx = ItemCtxt::new(tcx, parent);
|
||||
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name)
|
||||
} else {
|
||||
ty::EarlyBinder::bind(&[] as &[_])
|
||||
};
|
||||
let mut extend = None;
|
||||
|
||||
let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
|
||||
|
||||
let hir_node = tcx.hir_node(item_hir_id);
|
||||
let Some(hir_generics) = hir_node.generics() else { return result };
|
||||
let Some(hir_generics) = hir_node.generics() else {
|
||||
return result;
|
||||
};
|
||||
if let Node::Item(item) = hir_node
|
||||
&& let ItemKind::Trait(..) = item.kind
|
||||
// Implied `Self: Trait` and supertrait bounds.
|
||||
|
@ -748,9 +746,10 @@ pub(super) fn type_param_predicates(
|
|||
_ => false,
|
||||
}),
|
||||
);
|
||||
result.predicates =
|
||||
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(extra_predicates));
|
||||
result
|
||||
|
||||
ty::EarlyBinder::bind(
|
||||
tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_predicates)),
|
||||
)
|
||||
}
|
||||
|
||||
impl<'tcx> ItemCtxt<'tcx> {
|
||||
|
|
|
@ -1761,7 +1761,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
break Some((bound_vars.into_iter().collect(), assoc_item));
|
||||
}
|
||||
let predicates = tcx.explicit_supertraits_containing_assoc_item((def_id, assoc_name));
|
||||
let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| {
|
||||
let obligations = predicates.iter_identity_copied().filter_map(|(pred, _)| {
|
||||
let bound_predicate = pred.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::ClauseKind::Trait(data) => {
|
||||
|
|
|
@ -136,7 +136,7 @@ pub trait HirTyLowerer<'tcx> {
|
|||
span: Span,
|
||||
def_id: LocalDefId,
|
||||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx>;
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]>;
|
||||
|
||||
/// Lower an associated type to a projection.
|
||||
///
|
||||
|
@ -831,13 +831,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
debug!(?ty_param_def_id, ?assoc_name, ?span);
|
||||
let tcx = self.tcx();
|
||||
|
||||
let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name).predicates;
|
||||
let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name);
|
||||
debug!("predicates={:#?}", predicates);
|
||||
|
||||
self.probe_single_bound_for_assoc_item(
|
||||
|| {
|
||||
let trait_refs = predicates
|
||||
.iter()
|
||||
.iter_identity_copied()
|
||||
.filter_map(|(p, _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref)));
|
||||
traits::transitive_bounds_that_define_assoc_item(tcx, trait_refs, assoc_name)
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue