A small question about GATs and lifetime parameter

So, I'm just reading this issue to get updated on the pending Generic Associated Types feature, and I noticed how the Associated Type is used there:

#![feature(generic_associated_types)]

struct Foo;

impl Iterator for Foo {
    type Item<'b> = &'b Foo;

    fn next(&mut self) -> Option<Self::Item> {
        None
    }
}

Don't know if I've understood everything correctly, but to me, that code looks like:

impl Iterator for Foo {
    type Item<'b> = &'b Foo;

    fn next<'b>(&mut self) -> Option<Self::Item<'b>> {
             ^--------- Implied lifetime? -------^
        None
    }
}

After been expanded. However, when I actually trying to do that by hand, the compiler will yell at me:

error[E0109]: lifetime arguments are not allowed for this type
 --> gat.rs:8:49
  |
8 |     fn next<'b>(&mut self) -> Option<Self::Item<'b>> {
  |                                                 ^^ lifetime argument not allowed

error: aborting due to previous error

So I guess I've missed something? What could that be?

Indeed. That something is that unstable features are nightly-only for a reason: often they're not fully implemented yet. GATs are precisely such a feature, and thus you'll run into weird errors like this one.

3 Likes