fn opaque_type_projection_predicates(
    tcx: TyCtxt<'_>,
    def_id: DefId,
) -> &'_ ty::List<ty::Predicate<'_>> {
    let substs = InternalSubsts::identity_for_item(tcx, def_id);

    let bounds = tcx.predicates_of(def_id);
    let predicates =
        util::elaborate_predicates(tcx, bounds.predicates.into_iter().map(|&(pred, _)| pred));

    let filtered_predicates = predicates.filter_map(|obligation| {
        let pred = obligation.predicate;
        match pred.kind() {
            ty::PredicateKind::Trait(tr, _) => {
                if let ty::Opaque(opaque_def_id, opaque_substs) = tr.skip_binder().self_ty().kind {
                    if opaque_def_id == def_id && opaque_substs == substs {
                        return Some(pred);
                    }
                }
            }
            ty::PredicateKind::Projection(proj) => {
                if let ty::Opaque(opaque_def_id, opaque_substs) =
                    proj.skip_binder().projection_ty.self_ty().kind
                {
                    if opaque_def_id == def_id && opaque_substs == substs {
                        return Some(pred);
                    }
                }
            }
            ty::PredicateKind::TypeOutlives(outlives) => {
                if let ty::Opaque(opaque_def_id, opaque_substs) = outlives.skip_binder().0.kind {
                    if opaque_def_id == def_id && opaque_substs == substs {
                        return Some(pred);
                    }
                } else {
                    // These can come from elaborating other predicates
                    return None;
                }
            }
            // These can come from elaborating other predicates
            ty::PredicateKind::RegionOutlives(_) => return None,
            _ => {}
        }
        tcx.sess.delay_span_bug(
            obligation.cause.span(tcx),
            &format!("unexpected predicate {:?} on opaque type", pred),
        );
        None
    });

    let result = tcx.mk_predicates(filtered_predicates);
    debug!("opaque_type_projection_predicates({}) = {:?}", tcx.def_path_str(def_id), result);
    result
}
/// Opaque types don't have the same issues as associated types: the only
/// predicates on an opaque type (excluding those it inherits from its parent
/// item) should be of the form we're expecting.
Opaque types don't have the same issues as associated types: the only
predicates on an opaque type (excluding those it inherits from its parent
item) should be of the form we're expecting.
Opaque types don ' t have the same issues as associated types : the only predicates on an opaque type ( excluding those it inherits from its parent item ) should be of the form we ' re expecting .
fn opaque_type_projection_predicates(
    tcx: TyCtxt<'_>,
    def_id: DefId,
) -> &'_ ty::List<ty::Predicate<'_>> {
    let substs = InternalSubsts::identity_for_item(tcx, def_id);
    let bounds = tcx.predicates_of(def_id);
    let predicates =
        util::elaborate_predicates(tcx, bounds.predicates.into_iter().map(|&(pred, _)| pred));
    let filtered_predicates = predicates.filter_map(|obligation| {
        let pred = obligation.predicate;
        match pred.kind() {
            ty::PredicateKind::Trait(tr, _) => {
                if let ty::Opaque(opaque_def_id, opaque_substs) = tr.skip_binder().self_ty().kind {
                    if opaque_def_id == def_id && opaque_substs == substs {
                        return Some(pred);
                    }
                }
            }
            ty::PredicateKind::Projection(proj) => {
                if let ty::Opaque(opaque_def_id, opaque_substs) =
                    proj.skip_binder().projection_ty.self_ty().kind
                {
                    if opaque_def_id == def_id && opaque_substs == substs {
                        return Some(pred);
                    }
                }
            }
            ty::PredicateKind::TypeOutlives(outlives) => {
                if let ty::Opaque(opaque_def_id, opaque_substs) = outlives.skip_binder().0.kind {
                    if opaque_def_id == def_id && opaque_substs == substs {
                        return Some(pred);
                    }
                } else {
                    // These can come from elaborating other predicates
                    return None;
                }
            }
            // These can come from elaborating other predicates
            ty::PredicateKind::RegionOutlives(_) => return None,
            _ => {}
        }
        tcx.sess.delay_span_bug(
            obligation.cause.span(tcx),
            &format!("unexpected predicate {:?} on opaque type", pred),
        );
        None
    });
    let result = tcx.mk_predicates(filtered_predicates);
    debug!("opaque_type_projection_predicates({}) = {:?}", tcx.def_path_str(def_id), result);
    result
}
fn opaque_type_projection_predicates ( tcx : TyCtxt < ' _ > , def_id : DefId , ) -> & ' _ ty :: List < ty :: Predicate < ' _ > > { let substs = InternalSubsts :: identity_for_item ( tcx , def_id ) ; let bounds = tcx . predicates_of ( def_id ) ; let predicates = util :: elaborate_predicates ( tcx , bounds . predicates . into_iter ( ) . map ( | & ( pred , _ ) | pred ) ) ; let filtered_predicates = predicates . filter_map ( | obligation | { let pred = obligation . predicate ; match pred . kind ( ) { ty :: PredicateKind :: Trait ( tr , _ ) => { if let ty :: Opaque ( opaque_def_id , opaque_substs ) = tr . skip_binder ( ) . self_ty ( ) . kind { if opaque_def_id == def_id && opaque_substs == substs { return Some ( pred ) ; } } } ty :: PredicateKind :: Projection ( proj ) => { if let ty :: Opaque ( opaque_def_id , opaque_substs ) = proj . skip_binder ( ) . projection_ty . self_ty ( ) . kind { if opaque_def_id == def_id && opaque_substs == substs { return Some ( pred ) ; } } } ty :: PredicateKind :: TypeOutlives ( outlives ) => { if let ty :: Opaque ( opaque_def_id , opaque_substs ) = outlives . skip_binder ( ) . 0 . kind { if opaque_def_id == def_id && opaque_substs == substs { return Some ( pred ) ; } } else { // These can come from elaborating other predicates return None ; } } // These can come from elaborating other predicates ty :: PredicateKind :: RegionOutlives ( _ ) => return None , _ => { } } tcx . sess . delay_span_bug ( obligation . cause . span ( tcx ) , & format ! ( " " pred ) , ) ; None } ) ; let result = tcx . mk_predicates ( filtered_predicates ) ; debug ! ( " " tcx def_path_str ( def_id ) result ) ; result }
Opaque types don't have the same issues as associated types: the only
predicates on an opaque type (excluding those it inherits from its parent
item) should be of the form we're expecting.
Opaque types don ' t have the same issues as associated types : the only predicates on an opaque type ( excluding those it inherits from its parent item ) should be of the form we ' re expecting .
tcx
TyCtxt<'_>
def_id
DefId
tcx
TyCtxt<'_>
def_id
DefId