GAT(Generic Associated Type) used in bound of another GAT

Hi
I'm trying to use GATs for a small personal project (I know that I probably shouldn't). So far it worked, but now I'm having an error, which I don't understand. Here is an example.

Here is the error:

error[E0271]: type mismatch resolving `for<'a> <<FooImpl as Foo>::Bar<'a> as Bar>::Baz == <FooImpl as Foo>::Baz<'a>`
 --> src/main.rs:42:20
  |
42 |     type Baz<'a> = MyBaz<'a>;
  |                    ^^^^^^^^^ expected struct `MyBaz`, found associated type
  |
  = note:       expected struct `MyBaz<'_>`
          found associated type `<FooImpl as Foo>::Baz<'_>`
  = help: consider constraining the associated type `<FooImpl as Foo>::Baz<'_>` to `MyBaz<'_>`
  = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

What am I doing wrong?

GATs are far from complete, and are unsound, I would avoid them till more work is done

https://github.com/rust-lang/rust/issues/68641

2 Likes

Interpreting the error, I think the compiler is failing to resolve <FooImpl as Foo>::Baz<'a>, and isn't realizing that it is actually specified as MyBaz<'a>.

As far as what you did wrong, I don't think you did anything wrong. As @RustyYato stated, this is simply generic associated type support being incomplete.

1 Like

Thank you for your help!

1 Like

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