]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-bound.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / associated-types / associated-types-bound.rs
1 // run-pass
2 // Test equality constrai32s on associated types in a where clause.
3
4
5 pub trait ToI32 {
6     fn to_i32(&self) -> i32;
7 }
8
9 impl ToI32 for i32 {
10     fn to_i32(&self) -> i32 { *self }
11 }
12
13 impl ToI32 for u32 {
14     fn to_i32(&self) -> i32 { *self as i32 }
15 }
16
17 pub trait GetToI32
18 {
19     type R : ToI32;
20
21     fn get(&self) -> <Self as GetToI32>::R;
22 }
23
24 impl GetToI32 for i32 {
25     type R = i32;
26     fn get(&self) -> i32 { *self }
27 }
28
29 impl GetToI32 for u32 {
30     type R = u32;
31     fn get(&self) -> u32 { *self }
32 }
33
34 fn foo<G>(g: G) -> i32
35     where G : GetToI32
36 {
37     ToI32::to_i32(&g.get())
38 }
39
40 pub fn main() {
41     assert_eq!(foo(22i32), 22);
42     assert_eq!(foo(22u32), 22);
43 }