]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/mir/mir_codegen_calls.rs
2 #![feature(fn_traits, test)]
6 fn test1(a
: isize, b
: (i32, i32), c
: &[i32]) -> (isize, (i32, i32), &[i32]) {
7 // Test passing a number of arguments including a fat pointer.
8 // Also returning via an out pointer
9 fn callee(a
: isize, b
: (i32, i32), c
: &[i32]) -> (isize, (i32, i32), &[i32]) {
15 fn test2(a
: isize) -> isize {
16 // Test passing a single argument.
17 // Not using out pointer.
18 fn callee(a
: isize) -> isize {
24 #[derive(PartialEq, Eq, Debug)]
27 fn inherent_method(&self, a
: isize) -> isize { a }
30 fn test3(x
: &Foo
, a
: isize) -> isize {
31 // Test calling inherent method
36 fn extension_method(&self, a
: isize) -> isize { a }
40 fn test4(x
: &Foo
, a
: isize) -> isize {
41 // Test calling extension method
45 fn test5(x
: &dyn Bar
, a
: isize) -> isize {
46 // Test calling method on trait object
50 fn test6
<T
: Bar
>(x
: &T
, a
: isize) -> isize {
51 // Test calling extension method on generic callee
59 fn one() -> isize { 1 }
63 // Test calling trait static method
69 fn two() -> isize { 2 }
73 // Test calling impl static method
77 #[allow(improper_ctypes_definitions)]
78 extern "C" fn simple_extern(x
: u32, y
: (u32, u32)) -> u32 {
83 simple_extern(41, (42, 43))
86 fn test_closure
<F
>(f
: &F
, x
: i32, y
: i32) -> i32
87 where F
: Fn(i32, i32) -> i32
92 fn test_fn_object(f
: &dyn Fn(i32, i32) -> i32, x
: i32, y
: i32) -> i32 {
96 fn test_fn_impl(f
: &&dyn Fn(i32, i32) -> i32, x
: i32, y
: i32) -> i32 {
97 // This call goes through the Fn implementation for &Fn provided in
98 // core::ops::impls. It expands to a static Fn::call() that calls the
99 // Fn::call() implementation of the object shim underneath.
103 fn test_fn_direct_call
<F
>(f
: &F
, x
: i32, y
: i32) -> i32
104 where F
: Fn(i32, i32) -> i32
109 fn test_fn_const_call
<F
>(f
: &F
) -> i32
110 where F
: Fn(i32, i32) -> i32
115 fn test_fn_nil_call
<F
>(f
: &F
) -> i32
121 fn test_fn_transmute_zst(x
: ()) -> [(); 1] {
122 fn id
<T
>(x
: T
) -> T {x}
125 std
::mem
::transmute(x
)
129 fn test_fn_ignored_pair() -> ((), ()) {
133 fn test_fn_ignored_pair_0() {
134 test_fn_ignored_pair().0
137 fn id
<T
>(x
: T
) -> T { x }
139 fn ignored_pair_named() -> (Foo
, Foo
) {
143 fn test_fn_ignored_pair_named() -> (Foo
, Foo
) {
144 id(ignored_pair_named())
147 fn test_fn_nested_pair(x
: &((f32, f32), u32)) -> (f32, f32) {
153 fn test_fn_const_arg_by_ref(mut a
: [u64; 4]) -> u64 {
154 // Mutate the by-reference argument, which won't work with
155 // a non-immediate constant unless it's copied to the stack.
156 let a
= test
::black_box(&mut a
);
164 assert_eq
!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..]));
165 assert_eq
!(test2(98), 98);
166 assert_eq
!(test3(&Foo
, 42), 42);
167 assert_eq
!(test4(&Foo
, 970), 970);
168 assert_eq
!(test5(&Foo
, 8576), 8576);
169 assert_eq
!(test6(&Foo
, 12367), 12367);
170 assert_eq
!(test7(), 1);
171 assert_eq
!(test8(), 2);
172 assert_eq
!(test9(), 41 + 42 * 43);
175 let closure
= |x
: i32, y
: i32| { r*(x + (y*2)) }
;
176 assert_eq
!(test_fn_const_call(&closure
), 294);
177 assert_eq
!(test_closure(&closure
, 100, 1), 306);
178 let function_object
= &closure
as &dyn Fn(i32, i32) -> i32;
179 assert_eq
!(test_fn_object(function_object
, 100, 2), 312);
180 assert_eq
!(test_fn_impl(&function_object
, 100, 3), 318);
181 assert_eq
!(test_fn_direct_call(&closure
, 100, 4), 324);
183 assert_eq
!(test_fn_nil_call(&(|| 42)), 42);
184 assert_eq
!(test_fn_transmute_zst(()), [()]);
186 assert_eq
!(test_fn_ignored_pair_0(), ());
187 assert_eq
!(test_fn_ignored_pair_named(), (Foo
, Foo
));
188 assert_eq
!(test_fn_nested_pair(&((1.0, 2.0), 0)), (1.0, 2.0));
190 const ARRAY
: [u64; 4] = [1, 2, 3, 4];
191 assert_eq
!(test_fn_const_arg_by_ref(ARRAY
), 1 + 2 + 3 + 4);