Skip to content

GAT: Fails to compile with additional bounds #139207

Open
@Ddystopia

Description

@Ddystopia

I tried this code:

trait Gat {
    type Assoc<'a>;
}

struct Foo<S>(S);

impl<S> Foo<S> {
    fn bar<'a, C, T>(&self)
    where
        C: Gat<Assoc<'a> = T>,
        C: Gat<Assoc<'static> = S>, // By commenting out this bound code will compile
    {
        self.foo::<C, T>(); // or comment out this line, it will compile too
    }

    fn foo<'a, C, T>(&self)
    where
        C: Gat<Assoc<'a> = T>,
        // To be closer to original code `C: Gat<Assoc<'static> = S>` may be included, but error is the same anyway
    {
    }
}

I expected to see this happen: Code should compile

Instead, this happened: Code did not compile. Probably because 'a is different in both cases, I but cannot specify lifetime arguments explicitly if late bound lifetime parameters are present #42868 .

 1  error[E0284]: type annotations needed: cannot satisfy `<C as Gat>::Assoc<'_> == T`
   --> src/main.rs:13:14
    |
 13 |         self.foo::<C, T>();
    |              ^^^ cannot satisfy `<C as Gat>::Assoc<'_> == T`
    |
 note: required by a bound in `Foo::<S>::foo`
   --> src/main.rs:18:16
    |
 16 |     fn foo<'a, C, T>(&self)
    |        --- required by a bound in this associated function
 17 |     where
 18 |         C: Gat<Assoc<'a> = T>,
    |                ^^^^^^^^^^^^^ required by this bound in `Foo::<S>::foo`

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (b48576b4d 2025-03-22)
binary: rustc
commit-hash: b48576b4db5a595f453891f0b7243ef75d8c0afa
commit-date: 2025-03-22
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.T-typesRelevant to the types 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