Nested trait bounds without `PhantomData`

I don't really know how to word the question.

My question is, is there a way to rewrite this so it compiled without needing to use PhantomData?

trait Foo {}
trait Bar<F: Foo> {}

struct Baz<F: Foo, B: Bar<F>> {
    bar: B,
}

Don't put type bounds on struct definitions.

trait Foo {}
trait Bar {
    type F: Foo;
}

struct Baz<B> {
    bar: B,
}

impl<F: Foo, B: Bar<F = F>> Baz<B> {
    ...
}

In this case, you probably also want F to be an associated type rather than a generic parameter. If F can't be an associated type, then you would need to say more about how you use the trait.

2 Likes

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.