1 // Copyright 2015 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.
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.
11 #![feature(rustc_attrs)]
14 fn test1(a: isize, b: (i32, i32), c: &[i32]) -> (isize, (i32, i32), &[i32]) {
15 // Test passing a number of arguments including a fat pointer.
16 // Also returning via an out pointer
17 fn callee(a: isize, b: (i32, i32), c: &[i32]) -> (isize, (i32, i32), &[i32]) {
24 fn test2(a: isize) -> isize {
25 // Test passing a single argument.
26 // Not using out pointer.
27 fn callee(a: isize) -> isize {
35 fn inherent_method(&self, a: isize) -> isize { a }
39 fn test3(x: &Foo, a: isize) -> isize {
40 // Test calling inherent method
45 fn extension_method(&self, a: isize) -> isize { a }
50 fn test4(x: &Foo, a: isize) -> isize {
51 // Test calling extension method
56 fn test5(x: &Bar, a: isize) -> isize {
57 // Test calling method on trait object
62 fn test6<T: Bar>(x: &T, a: isize) -> isize {
63 // Test calling extension method on generic callee
71 fn one() -> isize { 1 }
76 // Test calling trait static method
82 fn two() -> isize { 2 }
87 // Test calling impl static method
91 extern fn simple_extern(x: u32, y: (u32, u32)) -> u32 {
97 simple_extern(41, (42, 43))
101 fn test_closure<F>(f: &F, x: i32, y: i32) -> i32
102 where F: Fn(i32, i32) -> i32
108 fn test_fn_object(f: &Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 {
113 fn test_fn_impl(f: &&Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 {
114 // This call goes through the Fn implementation for &Fn provided in
115 // core::ops::impls. It expands to a static Fn::call() that calls the
116 // Fn::call() implemenation of the object shim underneath.
121 assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
122 assert_eq!(test2(98), 98);
123 assert_eq!(test3(&Foo, 42), 42);
124 assert_eq!(test4(&Foo, 970), 970);
125 assert_eq!(test5(&Foo, 8576), 8576);
126 assert_eq!(test6(&Foo, 12367), 12367);
127 assert_eq!(test7(), 1);
128 assert_eq!(test8(), 2);
129 assert_eq!(test9(), 41 + 42 * 43);
131 let closure = |x: i32, y: i32| { x + y };
132 assert_eq!(test_closure(&closure, 100, 1), 101);
133 let function_object = &closure as &Fn(i32, i32) -> i32;
134 assert_eq!(test_fn_object(function_object, 100, 2), 102);
135 assert_eq!(test_fn_impl(&function_object, 100, 3), 103);