Skip to content

Incorrect unused parameter with GAT #80766

Closed
@bobbobbio

Description

@bobbobbio

I tried this code:

#![feature(generic_associated_types)]
#![allow(incomplete_features)]

trait Factory {
    type Output<'a>;
    fn build<'b>(&self, v: &'b u8) -> Self::Output<'b>;
}

#[allow(unused)]
struct Foo<'a, F: Factory> {
    f: F::Output<'a>,
}

I got this error:

error[E0392]: parameter `'a` is never used
  --> src/lib.rs:10:12
   |
10 | struct Foo<'a, F: Factory> {
   |            ^^ unused parameter
   |
   = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

I think it doesn't make sense since 'a is used in the field f, if I add the PhantomData like suggested, it works fine.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (da305a2b0 2021-01-05)
binary: rustc
commit-hash: da305a2b00530aa34dea4e48389204c26fa35dbb
commit-date: 2021-01-05
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsrequires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions