rust-lang / rust

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

In Impl Trait for T with associated type that = T, bounds do not recognize that T impls Trait #92505

Open thorjelly opened 2 years ago

thorjelly commented 2 years ago

This compiles and runs: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0b6a35cad2587fe5d1d4cdb30e94aa47

However this doesn't: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4e6a1dc742260b4754b540349099fcb3

The first bound seems to be "forgotten" when the second bound is added. A few folks on the rust discord suggested this may be a bug. It appears to be the case in both nightly and stable.

It appears to be the case even without const generics: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1a12aaeb3addf903f722337a576747b3

Stable version: 1.57.0 Nightly version: 1.59.0-nightly (2022-01-01 c145692254e86974941f)

compiler-errors commented 2 years ago

Minimized:

trait A<T> {
    type I;

     fn f() where Self::I: A<T> {}
}

impl<T> A<T> for () {
    type I = ();

     fn f() where Self::I: A<T> {
         <() as A<T>>::f();
     }
}

This has to do with param-env normalization shenanigans...

thorjelly commented 2 years ago

Thanks, updated title to be a bit more useful.