Skip to content

Commit

Permalink
Factor out a call to skip_binder()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Sep 13, 2024
1 parent ca1dac1 commit ca85aa9
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ pub mod rustc {
use crate::rustc_utils::*;
use rustc_middle::ty::*;

fn predicates_to_poly_trait_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
predicates: impl Iterator<Item = Predicate<'tcx>>,
generics: GenericArgsRef<'tcx>,
) -> impl Iterator<Item = PolyTraitPredicate<'tcx>> {
predicates
.filter_map(|pred| pred.as_trait_clause())
.map(move |clause| clause.subst(tcx, generics))
}

#[derive(Clone, Debug)]
pub enum PathChunk<'tcx> {
AssocItem {
Expand Down Expand Up @@ -157,20 +147,28 @@ pub mod rustc {

#[extension_traits::extension(pub trait TraitPredicateExt)]
impl<'tcx, S: UnderOwnerState<'tcx>> PolyTraitPredicate<'tcx> {
fn predicates_to_poly_trait_predicates(
self,
s: &S,
predicates: impl Iterator<Item = Predicate<'tcx>>,
) -> impl Iterator<Item = PolyTraitPredicate<'tcx>> {
let tcx = s.base().tcx;
let generics = self.skip_binder().trait_ref.args;
predicates
.filter_map(|pred| pred.as_trait_clause())
.map(move |clause| clause.subst(tcx, generics))
}

#[tracing::instrument(level = "trace", skip(s))]
fn parents_trait_predicates(self, s: &S) -> Vec<(usize, PolyTraitPredicate<'tcx>)> {
let tcx = s.base().tcx;
let predicates = tcx
.predicates_defined_on_or_above(self.def_id())
.into_iter()
.map(|apred| apred.predicate);
predicates_to_poly_trait_predicates(
tcx,
predicates,
self.skip_binder().trait_ref.args,
)
.enumerate()
.collect()
self.predicates_to_poly_trait_predicates(s, predicates)
.enumerate()
.collect()
}
#[tracing::instrument(level = "trace", skip(s))]
fn associated_items_trait_predicates(
Expand All @@ -187,10 +185,9 @@ pub mod rustc {
.copied()
.map(|item| {
let bounds = tcx.item_bounds(item.def_id).map_bound(|clauses| {
predicates_to_poly_trait_predicates(
tcx,
self.predicates_to_poly_trait_predicates(
s,
clauses.into_iter().map(|clause| clause.as_predicate()),
self.skip_binder().trait_ref.args,
)
.enumerate()
.collect()
Expand Down

0 comments on commit ca85aa9

Please sign in to comment.