# How to get predicates bound to their types in ImplHeader?

**URL:** <https://internals.rust-lang.org/t/how-to-get-predicates-bound-to-their-types-in-implheader/21244>\
**Category:** traits working group\
**Created:** [July 24, 2024, 8:40pm UTC](https://internals.rust-lang.org/t/how-to-get-predicates-bound-to-their-types-in-implheader/21244 "2024-07-24T20:40:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![10takla](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/10takla/32/11946_2.png) [@10takla](https://internals.rust-lang.org/u/10takla)\
**Post date:** [July 24, 2024, 8:40pm UTC](https://internals.rust-lang.org/t/how-to-get-predicates-bound-to-their-types-in-implheader/21244/1 "2024-07-24T20:40:40Z")

</div>

The following code:

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

```

contains [ImplHeader](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/struct.ImplHeader.html):

```rust
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`:

```rust
[
    (?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: [] }
    ])
]

```

---

<div class="post-metadata">

**Author:** ![binarycat](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/binarycat/32/12210_2.png) [@binarycat](https://internals.rust-lang.org/u/binarycat)\
**Post date:** [July 24, 2024, 10:28pm UTC](https://internals.rust-lang.org/t/how-to-get-predicates-bound-to-their-types-in-implheader/21244/2 "2024-07-24T22:28:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [January 15, 2026, 10:28pm UTC](https://internals.rust-lang.org/t/how-to-get-predicates-bound-to-their-types-in-implheader/21244/3 "2026-01-15T22:28:46Z")

</div>

Closed on January 15, 2026, 10:28pm UTC

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