]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/multidispatch-infer-convert-target.rs
Auto merge of #84959 - camsteffen:lint-suggest-group, r=estebank
[rust.git] / src / test / ui / traits / multidispatch-infer-convert-target.rs
1 // run-pass
2 // Test that we can infer the Target based on the Self or vice versa.
3
4
5 use std::mem;
6
7 trait Convert<Target> {
8     fn convert(&self) -> Target;
9 }
10
11 impl Convert<u32> for i16 {
12     fn convert(&self) -> u32 {
13         *self as u32
14     }
15 }
16
17 impl Convert<i16> for u32 {
18     fn convert(&self) -> i16 {
19         *self as i16
20     }
21 }
22
23 fn test<T,U>(_: T, _: U, t_size: usize, u_size: usize)
24 where T : Convert<U>
25 {
26     assert_eq!(mem::size_of::<T>(), t_size);
27     assert_eq!(mem::size_of::<U>(), u_size);
28 }
29
30 fn main() {
31     // T = i16, U = u32
32     test(22_i16, Default::default(),  2, 4);
33
34     // T = u32, U = i16
35     test(22_u32, Default::default(), 4, 2);
36 }