I'm testing out GATs, and I'm hitting a weird error message that I can't make sense of, and I'm wondering whether I'm hitting a known limitation, a bug in the implementation, or if I am just misunderstanding something.
My reduced test case looks like the following:
#![feature(generic_associated_types)]
pub trait Foo {
type Type<'a>;
}
pub trait Bar {}
pub struct Qux<T>(T);
pub fn bar(_: impl Bar) {}
impl<T: Foo> Bar for Qux<T> where for<'a> <T as Foo>::Type<'a>: Bar {}
impl Foo for String {
type Type<'a> = Self;
}
impl Bar for String {}
pub fn foo() {
bar(Qux("foo".to_string()));
}
This fails to compile with:
error[E0277]: the trait bound `for<'a> <String as Foo>::Type<'a>: Bar` is not satisfied
--> src/lib.rs:17:5
|
7 | pub fn bar(_: impl Bar) {}
| --- required by this bound in `bar`
...
17 | bar(Qux("foo".to_string()));
| ^^^ the trait `for<'a> Bar` is not implemented for `<String as Foo>::Type<'a>`
|
= note: required because of the requirements on the impl of `Bar` for `Qux<String>`
The simpler version of the code, without GATs, compiles just fine, which is what confuses me:
pub trait Foo {
type Type;
}
pub trait Bar {}
pub struct Qux<T>(T);
pub fn bar(_: impl Bar) {}
impl<T: Foo> Bar for Qux<T> where <T as Foo>::Type: Bar {}
impl Foo for String {
type Type = Self;
}
impl Bar for String {}
pub fn foo() {
bar(Qux("foo".to_string()));
}