2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-10-09 16:19:50 -05:00
|
|
|
// Test that we can infer the Target based on the Self or vice versa.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2014-10-09 16:19:50 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn test<T,U>(_: T, _: U, t_size: usize, u_size: usize)
|
2014-10-09 16:19:50 -05:00
|
|
|
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
|
2014-12-15 08:45:28 -06:00
|
|
|
test(22_i16, Default::default(), 2, 4);
|
2014-10-09 16:19:50 -05:00
|
|
|
|
|
|
|
// T = u32, U = i16
|
2014-12-15 08:45:28 -06:00
|
|
|
test(22_u32, Default::default(), 4, 2);
|
2014-10-09 16:19:50 -05:00
|
|
|
}
|