summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/multidispatch-infer-convert-target.rs
blob: 626e1ae71bc2fc7a7322ac392ead07e0d3c565a1 (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
// run-pass
// Test that we can infer the Target based on the Self or vice versa.


use std::mem;

trait Convert<Target> {
    fn convert(&self) -> Target;
}

impl Convert<u32> for i16 {
    fn convert(&self) -> u32 {
        *self as u32
    }
}

impl Convert<i16> for u32 {
    fn convert(&self) -> i16 {
        *self as i16
    }
}

fn test<T,U>(_: T, _: U, t_size: usize, u_size: usize)
where T : Convert<U>
{
    assert_eq!(mem::size_of::<T>(), t_size);
    assert_eq!(mem::size_of::<U>(), u_size);
}

fn main() {
    // T = i16, U = u32
    test(22_i16, Default::default(),  2, 4);

    // T = u32, U = i16
    test(22_u32, Default::default(), 4, 2);
}