Trait bound of type declared in a trait

Hello, I would like to access the trait bound of a type that is defined in a trait from rustc's HIR (or THIR).

pub trait A {
type B: C

I went down to the TraitItemRef but I cannot find how to get the trait bound (C) from there. I guess I could find this information somewhere in the THIR but I don't know where. I would be thankful if someone could show me where to look :slight_smile:

You might have better luck asking in Zulip, or perhaps on IRLO. If you ask on the latter, please drop a link here so people know.

1 Like

Posted the question on Zulip as well

After getting lost in the compiler's docs I found out that to explore further a TraitItemRef, the solution is to use expect_trait_item and call it as in the following example:

pub fn print_trait_item(tcx: &TyCtxt, trait_item_ref: &rustc_hir::TraitItemRef) {
    let rustc_hir::TraitItemRef {
        } = trait_item_ref;
    let trait_item: &rustc_hir::TraitItem = tcx.hir().expect_trait_item(id.def_id);
    println!("{:?}", trait_item);

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.