rust-lang / rust

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

GAT with bound on another GAT fails despite fulfilling the bound #102159

Open CraftSpider opened 2 years ago

CraftSpider commented 2 years ago

I tried this code:

struct HasGeneric<T>(T);

trait GatFoo {
    type Foo<T>: GatBar<Bar<()> = Self::Foo<()>>;
}

trait GatBar {
    type Bar<T>;
}

impl<U> GatBar for HasGeneric<U> {
    type Bar<T> = HasGeneric<T>;
}

impl<U> GatFoo for HasGeneric<U> {
    type Foo<T> = HasGeneric<T>;
}

I expected to see this happen: This compiles successfully, as the bound is true - GatBar::Bar<()> == HasGeneric<()>.

Instead, this happened: The compile fails with E0271, type mismatch during resolution

Meta

Tested on the playground with:

1.65.0-beta.1
(2022-09-19 2a65764f21cf10b7e03c)

and

1.66.0-nightly
(2022-09-21 9062b780b32d2eab060b)
Backtrace

``` Compiling playground v0.0.1 (/playground) error[[E0271]](https://doc.rust-lang.org/beta/error-index.html#E0271): type mismatch resolving ` as GatBar>::Bar<()> == HasGeneric` --> src/lib.rs:17:19 | 17 | type Foo = HasGeneric; | - ^^^^^^^^^^^^^ type mismatch resolving ` as GatBar>::Bar<()> == HasGeneric` | | | this type parameter | note: expected this to be `HasGeneric` --> src/lib.rs:13:19 | 13 | type Bar = HasGeneric; | ^^^^^^^^^^^^^ = note: expected struct `HasGeneric` found struct `HasGeneric<()>` note: required by a bound in `GatFoo::Foo` --> src/lib.rs:5:25 | 5 | type Foo: GatBar = Self::Foo<()>>; | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `GatFoo::Foo` For more information about this error, try `rustc --explain E0271`. error: could not compile `playground` due to previous error ```

CraftSpider commented 2 years ago

I may be wrong, but while looking for duplicate issues, this looks somewhat similar to some prior issues related to higher-ranked bounds with lifetimes. This would make sense to me, as I think this is attempting to require rustc prove a bound like for<T> Foo<()> == Bar<()>

Rageking8 commented 2 years ago

@rustbot label +T-compiler +F-generic_associated_types