trait Foo {} trait Trait { type Associated; } trait DerivedTrait: Trait {} trait GenericTrait { type Associated; } struct Impl; impl Foo for Impl {} impl Trait for Impl { type Associated = (); } impl DerivedTrait for Impl {} impl GenericTrait for Impl { type Associated = (); } fn returns_opaque() -> impl Trait + 'static { Impl } fn returns_opaque_derived() -> impl DerivedTrait + 'static { Impl } fn returns_opaque_foo() -> impl Trait + Foo { Impl } fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo { Impl } fn returns_opaque_generic() -> impl GenericTrait<()> + 'static { Impl } fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo { Impl } fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait { Impl } fn accepts_trait>(_: T) {} fn accepts_generic_trait>(_: T) {} fn check_generics(a: A, b: B, c: C, d: D, e: E, f: F, g: G) where A: Trait + 'static, B: DerivedTrait + 'static, C: Trait + Foo, D: DerivedTrait + Foo, E: GenericTrait<()> + 'static, F: GenericTrait<()> + Foo, G: GenericTrait<()> + GenericTrait, { accepts_trait(a); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(b); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(c); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(d); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_generic_trait(e); //~^ ERROR type mismatch resolving `>::Associated == ()` accepts_generic_trait(f); //~^ ERROR type mismatch resolving `>::Associated == ()` accepts_generic_trait(g); //~^ ERROR type mismatch resolving `>::Associated == ()` } fn main() { accepts_trait(returns_opaque()); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(returns_opaque_derived()); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(returns_opaque_foo()); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_trait(returns_opaque_derived_foo()); //~^ ERROR type mismatch resolving `::Associated == ()` accepts_generic_trait(returns_opaque_generic()); //~^ ERROR type mismatch resolving ` as GenericTrait<()>>::Associated == ()` accepts_generic_trait(returns_opaque_generic_foo()); //~^ ERROR type mismatch resolving ` + Foo as GenericTrait<()>>::Associated == ()` accepts_generic_trait(returns_opaque_generic_duplicate()); //~^ ERROR type mismatch resolving ` + GenericTrait as GenericTrait<()>>::Associated == ()` }