Skip to content

GAT: incorrect suggestion on missing lifetime #81961

Closed
@lcnr

Description

@lcnr
#![feature(generic_associated_types)]
trait Foo {
    type Assoc<'a, const N: usize>;
}

fn foo<T: Foo>() {
    let _: <T as Foo>::Assoc<3>;
}

results in the following error:

error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
 --> src/lib.rs:7:24
  |
7 |     let _: <T as Foo>::Assoc<3>;
  |                        ^^^^^ expected 1 lifetime argument
  |
note: associated type defined here, with 1 lifetime parameter: `'a`
 --> src/lib.rs:3:10
  |
3 |     type Assoc<'a, const N: usize>;
  |          ^^^^^ --
help: add missing lifetime argument
  |
7 |     let _: <T as Foo>::Assoc<'a3>;
  |                              ^^

Note that we suggest <T as Foo>::Assoc<'a3> here, which is missing a comma.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions