Skip to content

Required lifetime bounds for GATs in where clauses get removed  #4954

@jam1garner

Description

@jam1garner

Minimal reproduction (playground link, hit 'format' then try building to see it in action):

Before

trait Foo {
    type Arg<'a>;
}

struct Bar<T>(T) where for<'a> T: Foo<Arg<'a> = ()>;

After

trait Foo {
    type Arg<'a>;
}

struct Bar<T>(T)
where
    for<'a> T: Foo<Arg = ()>;
//                             ^^^ note the lack of <'a> bound, which is needed

This will result in the following compiler error:

error[E0107]: missing generics for associated type `Foo::Arg`
 --> src/main.rs:9:20
  |
9 |     for<'a> T: Foo<Arg = ()>;
  |                    ^^^ expected 1 lifetime argument
  |
note: associated type defined here, with 1 lifetime parameter: `'a`
 --> src/main.rs:4:10
  |
4 |     type Arg<'a>;
  |          ^^^ --
help: add missing lifetime argument
  |
9 |     for<'a> T: Foo<Arg<'a> = ()>;
  |                    ~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions