diff options
| author | Michael Woerister <michaelwoerister@posteo.net> | 2016-01-05 12:32:49 -0500 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo.net> | 2016-01-05 12:50:54 -0500 |
| commit | e281509dcee2ef1ca06b333b6a40e8520c642d15 (patch) | |
| tree | 8d2f9e4f8f4a7fdd71fbd9e4d55c048f67784d0a /src | |
| parent | 7d357190ff8cd5a06117ff1fbb4a739fa67ae44f (diff) | |
[MIR] Add test case for translation of closure calls.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/run-pass/mir_trans_calls.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/test/run-pass/mir_trans_calls.rs b/src/test/run-pass/mir_trans_calls.rs index 1ce0618daf3..bd236e95d1c 100644 --- a/src/test/run-pass/mir_trans_calls.rs +++ b/src/test/run-pass/mir_trans_calls.rs @@ -94,10 +94,9 @@ fn test8() -> isize { } #[rustc_mir] -fn test_fn_impl(f: &&Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 { - // This call goes through the Fn implementation for &Fn provided in - // core::ops::impls. It expands to a static Fn::call() that calls the - // Fn::call() implemenation of the object shim underneath. +fn test_closure<F>(f: &F, x: i32, y: i32) -> i32 + where F: Fn(i32, i32) -> i32 +{ f(x, y) } @@ -106,6 +105,14 @@ fn test_fn_object(f: &Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 { f(x, y) } +#[rustc_mir] +fn test_fn_impl(f: &&Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 { + // This call goes through the Fn implementation for &Fn provided in + // core::ops::impls. It expands to a static Fn::call() that calls the + // Fn::call() implemenation of the object shim underneath. + f(x, y) +} + fn main() { assert_eq!(test1(1, (2, 3), &[4, 5, 6]), (1, (2, 3), &[4, 5, 6][..])); assert_eq!(test2(98), 98); @@ -117,7 +124,9 @@ fn main() { assert_eq!(test7(), 1); assert_eq!(test8(), 2); - let function_object = (&|x: i32, y: i32| { x + y }) as &Fn(i32, i32) -> i32; - assert_eq!(test_fn_object(function_object, 100, 1), 101); - assert_eq!(test_fn_impl(&function_object, 100, 2), 102); + let closure = |x: i32, y: i32| { x + y }; + assert_eq!(test_closure(&closure, 100, 1), 101); + let function_object = &closure as &Fn(i32, i32) -> i32; + assert_eq!(test_fn_object(function_object, 100, 2), 102); + assert_eq!(test_fn_impl(&function_object, 100, 3), 103); } |
