]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/associated-types-bound.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / associated-types-bound.rs
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 equality constrai32s on associated types in a where clause.
12
13 // pretty-expanded FIXME #23616
14
15 pub trait ToI32 {
16     fn to_i32(&self) -> i32;
17 }
18
19 impl ToI32 for i32 {
20     fn to_i32(&self) -> i32 { *self }
21 }
22
23 impl ToI32 for u32 {
24     fn to_i32(&self) -> i32 { *self as i32 }
25 }
26
27 pub trait GetToI32
28 {
29     type R : ToI32;
30
31     fn get(&self) -> <Self as GetToI32>::R;
32 }
33
34 impl GetToI32 for i32 {
35     type R = i32;
36     fn get(&self) -> i32 { *self }
37 }
38
39 impl GetToI32 for u32 {
40     type R = u32;
41     fn get(&self) -> u32 { *self }
42 }
43
44 fn foo<G>(g: G) -> i32
45     where G : GetToI32
46 {
47     ToI32::to_i32(&g.get())
48 }
49
50 pub fn main() {
51     assert_eq!(foo(22i32), 22);
52     assert_eq!(foo(22u32), 22);
53 }