]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-to-closure-and-proc.rs
auto merge of #12626 : alexcrichton/rust/assert-eq, r=thestinger
[rust.git] / src / test / run-pass / coerce-to-closure-and-proc.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 fn id<T>(x: T) -> T {
12     x
13 }
14
15 #[deriving(Eq, Show)]
16 struct Foo<T>(T);
17
18 #[deriving(Eq, Show)]
19 enum Bar<T> {
20     Bar(T)
21 }
22
23 pub fn main() {
24     let f: |int| -> int = id;
25     assert_eq!(f(5), 5);
26
27     let f: proc(int) -> int = id;
28     assert_eq!(f(5), 5);
29
30     let f: |int| -> Foo<int> = Foo;
31     assert_eq!(f(5), Foo(5));
32
33     let f: proc(int) -> Foo<int> = Foo;
34     assert_eq!(f(5), Foo(5));
35
36     let f: |int| -> Bar<int> = Bar;
37     assert_eq!(f(5), Bar(5));
38
39     let f: proc(int) -> Bar<int> = Bar;
40     assert_eq!(f(5), Bar(5));
41
42     let f: |int| -> Option<int> = Some;
43     assert_eq!(f(5), Some(5));
44
45     let f: proc(int) -> Option<int> = Some;
46     assert_eq!(f(5), Some(5));
47 }