]> git.proxmox.com Git - rustc.git/blob - src/test/ui/associated-types/issue-87261.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / associated-types / issue-87261.rs
1 trait Foo {}
2
3 trait Trait {
4 type Associated;
5 }
6 trait DerivedTrait: Trait {}
7 trait GenericTrait<A> {
8 type Associated;
9 }
10
11 struct Impl;
12 impl Foo for Impl {}
13 impl Trait for Impl {
14 type Associated = ();
15 }
16 impl DerivedTrait for Impl {}
17 impl<A> GenericTrait<A> for Impl {
18 type Associated = ();
19 }
20
21 fn returns_opaque() -> impl Trait + 'static {
22 Impl
23 }
24 fn returns_opaque_derived() -> impl DerivedTrait + 'static {
25 Impl
26 }
27 fn returns_opaque_foo() -> impl Trait + Foo {
28 Impl
29 }
30 fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo {
31 Impl
32 }
33 fn returns_opaque_generic() -> impl GenericTrait<()> + 'static {
34 Impl
35 }
36 fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo {
37 Impl
38 }
39 fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait<u8> {
40 Impl
41 }
42
43 fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
44 fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}
45
46 fn check_generics<A, B, C, D, E, F, G>(a: A, b: B, c: C, d: D, e: E, f: F, g: G)
47 where
48 A: Trait + 'static,
49 B: DerivedTrait + 'static,
50 C: Trait + Foo,
51 D: DerivedTrait + Foo,
52 E: GenericTrait<()> + 'static,
53 F: GenericTrait<()> + Foo,
54 G: GenericTrait<()> + GenericTrait<u8>,
55 {
56 accepts_trait(a);
57 //~^ ERROR type mismatch resolving `<A as Trait>::Associated == ()`
58
59 accepts_trait(b);
60 //~^ ERROR type mismatch resolving `<B as Trait>::Associated == ()`
61
62 accepts_trait(c);
63 //~^ ERROR type mismatch resolving `<C as Trait>::Associated == ()`
64
65 accepts_trait(d);
66 //~^ ERROR type mismatch resolving `<D as Trait>::Associated == ()`
67
68 accepts_generic_trait(e);
69 //~^ ERROR type mismatch resolving `<E as GenericTrait<()>>::Associated == ()`
70
71 accepts_generic_trait(f);
72 //~^ ERROR type mismatch resolving `<F as GenericTrait<()>>::Associated == ()`
73
74 accepts_generic_trait(g);
75 //~^ ERROR type mismatch resolving `<G as GenericTrait<()>>::Associated == ()`
76 }
77
78 fn main() {
79 accepts_trait(returns_opaque());
80 //~^ ERROR type mismatch resolving `<impl Trait as Trait>::Associated == ()`
81
82 accepts_trait(returns_opaque_derived());
83 //~^ ERROR type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`
84
85 accepts_trait(returns_opaque_foo());
86 //~^ ERROR type mismatch resolving `<impl Trait + Foo as Trait>::Associated == ()`
87
88 accepts_trait(returns_opaque_derived_foo());
89 //~^ ERROR type mismatch resolving `<impl DerivedTrait + Foo as Trait>::Associated == ()`
90
91 accepts_generic_trait(returns_opaque_generic());
92 //~^ ERROR type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`
93
94 accepts_generic_trait(returns_opaque_generic_foo());
95 //~^ ERROR type mismatch resolving `<impl GenericTrait<()> + Foo as GenericTrait<()>>::Associated == ()`
96
97 accepts_generic_trait(returns_opaque_generic_duplicate());
98 //~^ ERROR type mismatch resolving `<impl GenericTrait<()> + GenericTrait<u8> as GenericTrait<()>>::Associated == ()`
99 }