]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
1a4d82fc JJ |
2 | // Test that we are able to resolve conditional dispatch. Here, the |
3 | // blanket impl for T:Copy coexists with an impl for Box<T>, because | |
4 | // Box does not impl Copy. | |
5 | ||
1a4d82fc JJ |
6 | #![feature(box_syntax)] |
7 | ||
8 | trait Get { | |
9 | fn get(&self) -> Self; | |
10 | } | |
11 | ||
9346a6ac | 12 | trait MyCopy { fn copy(&self) -> Self; } |
c34b1796 AL |
13 | impl MyCopy for u16 { fn copy(&self) -> Self { *self } } |
14 | impl MyCopy for u32 { fn copy(&self) -> Self { *self } } | |
15 | impl MyCopy for i32 { fn copy(&self) -> Self { *self } } | |
16 | impl<T:Copy> MyCopy for Option<T> { fn copy(&self) -> Self { *self } } | |
17 | ||
18 | impl<T:MyCopy> Get for T { | |
19 | fn get(&self) -> T { self.copy() } | |
1a4d82fc JJ |
20 | } |
21 | ||
c34b1796 AL |
22 | impl Get for Box<i32> { |
23 | fn get(&self) -> Box<i32> { box get_it(&**self) } | |
1a4d82fc JJ |
24 | } |
25 | ||
26 | fn get_it<T:Get>(t: &T) -> T { | |
27 | (*t).get() | |
28 | } | |
29 | ||
30 | fn main() { | |
31 | assert_eq!(get_it(&1_u32), 1_u32); | |
32 | assert_eq!(get_it(&1_u16), 1_u16); | |
33 | assert_eq!(get_it(&Some(1_u16)), Some(1_u16)); | |
c34b1796 | 34 | assert_eq!(get_it(&Box::new(1)), Box::new(1)); |
1a4d82fc | 35 | } |