summaryrefslogtreecommitdiffstats
path: root/src/test/ui/associated-types/issue-54108.rs
blob: 87f67ce4b527a6fca58e85e2ed8009d20d6bc42d (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
use std::ops::Add;

pub trait Encoder {
    type Size: Add<Output = Self::Size>;

    fn foo(&self) -> Self::Size;
}

pub trait SubEncoder: Encoder {
    type ActualSize;

    fn bar(&self) -> Self::Size;
}

impl<T> Encoder for T
where
    T: SubEncoder,
{
    type Size = <Self as SubEncoder>::ActualSize;
    //~^ ERROR: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`

    fn foo(&self) -> Self::Size {
        self.bar() + self.bar()
    }
}

pub struct UnitEncoder;

impl SubEncoder for UnitEncoder {
    type ActualSize = ();

    fn bar(&self) {}
}

pub fn fun<R: Encoder>(encoder: &R) {
    encoder.foo();
}

fn main() {
    fun(&UnitEncoder {});
}