How to get predicates bound to their types in ImplHeader?

The following code:

impl<R, K, T: LikeOne> Of<T> for (K, R, i32) 
    where K: LikeTwo {
}

contains ImplHeader:

ImplHeader {    
    impl_def_id: DefId(0:8 ~ marker_with_items[5448]::{impl#1}),
    impl_args: [
        ?0t,
        ?1t,
        ?2t,
    ],
    self_ty: (?0t, ?1t, i32),
    trait_ref: Some(
        <(_, _, i32) as Of<_>>,
    ),
    predicates: [
        Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] },
        Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] },
        Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] },
        Binder { value: TraitPredicate(<_ as LikeOne>, polarity:Positive), bound_vars: [] },   
        Binder { value: TraitPredicate(<_ as LikeTwo>, polarity:Positive), bound_vars: [] },   
    ],
}

but for further analysis I would like to get predicates bound to their generic types. In the end I would like to get 2 lists for trait and for self. Each list contains a generic type and its predicates. The elements of the lists are arranged in the order in which the generic in the corresponding trait and self are arranged. That is: trait: [(T, [LikeOne])] self: [(K, [LikeTwo]), (R, [])]

Or as in ImplHeader:

[
    (?2t, [
        Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] },
        Binder { value: TraitPredicate(<_ as LikeOne>, polarity:Positive), bound_vars: [] },
    ])
],
[
    (?0t, [
        Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] },
        Binder { value: TraitPredicate(<_ as LikeTwo>>, polarity:Positive), bound_vars: [] },
    ]),
    (?1t, [
        Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] }
    ])
]

Predicate::kind will give you an enum you can pattern match on to extract basically whatever data you want, although it's not clear what your actual goal is here

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.