]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/traits-multidispatch-infer-convert-target.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / traits-multidispatch-infer-convert-target.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// Test that we can infer the Target based on the Self or vice versa.
12
c34b1796 13
1a4d82fc
JJ
14use std::mem;
15
16trait Convert<Target> {
17 fn convert(&self) -> Target;
18}
19
20impl Convert<u32> for i16 {
21 fn convert(&self) -> u32 {
22 *self as u32
23 }
24}
25
26impl Convert<i16> for u32 {
27 fn convert(&self) -> i16 {
28 *self as i16
29 }
30}
31
c34b1796 32fn test<T,U>(_: T, _: U, t_size: usize, u_size: usize)
1a4d82fc
JJ
33where T : Convert<U>
34{
35 assert_eq!(mem::size_of::<T>(), t_size);
36 assert_eq!(mem::size_of::<U>(), u_size);
37}
38
39fn main() {
40 use std::default::Default;
41 // T = i16, U = u32
42 test(22_i16, Default::default(), 2, 4);
43
44 // T = u32, U = i16
45 test(22_u32, Default::default(), 4, 2);
46}