GATs and Trait Objects

How does currently GATs behave when the trait is made into a trait object? Can a trait object's associated type depend on a GAT?

Suppose this trait:

pub trait MakesFoo {
    type Foo<'a>;

    fn make_foo<'a>(&'a self) -> Self::Foo<'a>;
}

Is there a way to express a trait object whose associated type depends on a lifetime, like this:

dyn MakeFoo<Foo<'a> = &'a i32>

?

It currently gives a syntax error.

I do can write:

dyn MakeFoo<Foo = &'a i32>

But this won't work as I expect, because this lifetime is either fixed or unbounded.

1 Like

Gat isn't implemented yet, at least not to a meaningful degree. I would assume that you can't make trait objects for the same reason why you can't have generic functions in trait objects. If it's just lifetimes, we still don't have a syntax for it, and this one looks nice

3 Likes

Gat isn't implemented yet, at least not to a meaningful degree.

I see.

If it's just lifetimes

Yes, I only intend to do this with generic lifetimes, not with generic types, just like a trait method is not object-safe if it quantifies generic types, but it is object safe if it quantifies only lifetimes.