]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
c34b1796 | 2 | |
1a4d82fc JJ |
3 | trait SignedUnsigned { |
4 | type Opposite; | |
5 | fn convert(self) -> Self::Opposite; | |
6 | } | |
7 | ||
c34b1796 AL |
8 | impl SignedUnsigned for isize { |
9 | type Opposite = usize; | |
1a4d82fc | 10 | |
c34b1796 AL |
11 | fn convert(self) -> usize { |
12 | self as usize | |
1a4d82fc JJ |
13 | } |
14 | } | |
15 | ||
c34b1796 AL |
16 | impl SignedUnsigned for usize { |
17 | type Opposite = isize; | |
1a4d82fc | 18 | |
c34b1796 AL |
19 | fn convert(self) -> isize { |
20 | self as isize | |
1a4d82fc JJ |
21 | } |
22 | } | |
23 | ||
c34b1796 | 24 | fn get(x: isize) -> <isize as SignedUnsigned>::Opposite { |
1a4d82fc JJ |
25 | x.convert() |
26 | } | |
27 | ||
28 | fn main() { | |
29 | let x = get(22); | |
c34b1796 | 30 | assert_eq!(22, x); |
1a4d82fc | 31 | } |