1
Fork 0

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:
Matthias Krüger 2023-04-25 21:06:32 +02:00 committed by GitHub
commit 297b222066
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 88 additions and 71 deletions

View file

@ -251,7 +251,7 @@ rustc_queries! {
/// `key` is the `DefId` of the associated type or opaque type.
///
/// 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) }
cache_on_disk_if { key.is_local() }
separate_provide_extern

View file

@ -1603,7 +1603,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.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;
};

View file

@ -914,7 +914,7 @@ pub trait PrettyPrinter<'tcx>:
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// 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 fn_traits = FxIndexMap::default();

View file

@ -612,6 +612,12 @@ where
) -> SubstIter<'s, 'tcx, I> {
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> {
@ -664,6 +670,12 @@ where
) -> SubstIterCopied<'s, 'tcx, I> {
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> {

View file

@ -701,13 +701,6 @@ impl<'tcx> TyCtxt<'tcx> {
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.
///
/// Here are some examples: