rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.55k stars 12.74k forks source link

Introducing a GAT parameter leads to a false positive E0207 for another parameter constrained by Fn type #88526

Open mvlabat opened 3 years ago

mvlabat commented 3 years ago

I tried this code:

#![feature(generic_associated_types)]

trait A {
    type I<'a>;
}

pub struct TestA<F>
{
    f: F,
}

impl<F> A for TestA<F> {
    type I<'a> = &'a F;
}

struct TestB<Q, F>
{
    q: Q,
    f: F,
}

impl<'q, Q, I, F> A for TestB<Q, F>
where
    Q: A<I<'q> = &'q I>,
    F: Fn(I),
{
    type I<'a> = ();
}

I expected it to compile. Instead, I've got the following error:

error[E0207]: the type parameter `I` is not constrained by the impl trait, self type, or predicates
  --> src/lib.rs:22:13
   |
22 | impl<'q, Q, I, F> A for TestB<Q, F>
   |             ^ unconstrained type parameter

For more information about this error, try `rustc --explain E0207`.
error: could not compile `playground` due to previous error

If I remove the GAT, the code compiles successfully. I've created the following two playground examples to play around with (the first one compiles, the second one doesn't): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=15548086c5da59870ffbf5b4fe4de27a https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=725c4e36f367bd3b1ba30917cfc38b65

I'm not 100% sure that this is a bug, but the fact, that adding a GAT parameter to (as it seems) an unrelated type produces such an error, looks strange to me.

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (5eacec9ec 2021-08-28)
binary: rustc
commit-hash: 5eacec9ec7e112a0de1011519a57c45586d58414
commit-date: 2021-08-28
host: x86_64-pc-windows-msvc
release: 1.56.0-nightly
LLVM version: 13.0.0
jackh726 commented 3 years ago

Looks like a duplicate of #87735

jackh726 commented 3 years ago

GATs issue triage: not blocking. See #87735 for reasoning.