summaryrefslogtreecommitdiffstats
path: root/tests/ui/associated-types/issue-87261.rs
blob: 384561f8ccd7e0496ef3c867ff4e015f8955a958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
trait Foo {}

trait Trait {
    type Associated;
}
trait DerivedTrait: Trait {}
trait GenericTrait<A> {
    type Associated;
}

struct Impl;
impl Foo for Impl {}
impl Trait for Impl {
    type Associated = ();
}
impl DerivedTrait for Impl {}
impl<A> GenericTrait<A> 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<u8> {
    Impl
}

fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}

fn check_generics<A, B, C, D, E, F, G>(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<u8>,
{
    accepts_trait(a);
    //~^ ERROR type mismatch resolving `<A as Trait>::Associated == ()`

    accepts_trait(b);
    //~^ ERROR type mismatch resolving `<B as Trait>::Associated == ()`

    accepts_trait(c);
    //~^ ERROR type mismatch resolving `<C as Trait>::Associated == ()`

    accepts_trait(d);
    //~^ ERROR type mismatch resolving `<D as Trait>::Associated == ()`

    accepts_generic_trait(e);
    //~^ ERROR type mismatch resolving `<E as GenericTrait<()>>::Associated == ()`

    accepts_generic_trait(f);
    //~^ ERROR type mismatch resolving `<F as GenericTrait<()>>::Associated == ()`

    accepts_generic_trait(g);
    //~^ ERROR type mismatch resolving `<G as GenericTrait<()>>::Associated == ()`
}

fn main() {
    accepts_trait(returns_opaque());
    //~^ ERROR type mismatch resolving `<impl Trait as Trait>::Associated == ()`

    accepts_trait(returns_opaque_derived());
    //~^ ERROR type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`

    accepts_trait(returns_opaque_foo());
    //~^ ERROR type mismatch resolving `<impl Trait + Foo as Trait>::Associated == ()`

    accepts_trait(returns_opaque_derived_foo());
    //~^ ERROR type mismatch resolving `<impl DerivedTrait + Foo as Trait>::Associated == ()`

    accepts_generic_trait(returns_opaque_generic());
    //~^ ERROR type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`

    accepts_generic_trait(returns_opaque_generic_foo());
    //~^ ERROR type mismatch resolving `<impl GenericTrait<()> + Foo as GenericTrait<()>>::Associated == ()`

    accepts_generic_trait(returns_opaque_generic_duplicate());
    //~^ ERROR type mismatch resolving `<impl GenericTrait<()> + GenericTrait<u8> as GenericTrait<()>>::Associated == ()`
}