@@ -94,10 +94,9 @@ fn test8() -> isize {
9494}
9595
9696#[ rustc_mir]
97- fn test_fn_impl ( f : & & Fn ( i32 , i32 ) -> i32 , x : i32 , y : i32 ) -> i32 {
98- // This call goes through the Fn implementation for &Fn provided in
99- // core::ops::impls. It expands to a static Fn::call() that calls the
100- // Fn::call() implemenation of the object shim underneath.
97+ fn test_closure < F > ( f : & F , x : i32 , y : i32 ) -> i32
98+ where F : Fn ( i32 , i32 ) -> i32
99+ {
101100 f ( x, y)
102101}
103102
@@ -106,6 +105,14 @@ fn test_fn_object(f: &Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 {
106105 f ( x, y)
107106}
108107
108+ #[ rustc_mir]
109+ fn test_fn_impl ( f : & & Fn ( i32 , i32 ) -> i32 , x : i32 , y : i32 ) -> i32 {
110+ // This call goes through the Fn implementation for &Fn provided in
111+ // core::ops::impls. It expands to a static Fn::call() that calls the
112+ // Fn::call() implemenation of the object shim underneath.
113+ f ( x, y)
114+ }
115+
109116fn main ( ) {
110117 assert_eq ! ( test1( 1 , ( 2 , 3 ) , & [ 4 , 5 , 6 ] ) , ( 1 , ( 2 , 3 ) , & [ 4 , 5 , 6 ] [ ..] ) ) ;
111118 assert_eq ! ( test2( 98 ) , 98 ) ;
@@ -117,7 +124,9 @@ fn main() {
117124 assert_eq ! ( test7( ) , 1 ) ;
118125 assert_eq ! ( test8( ) , 2 ) ;
119126
120- let function_object = ( & |x : i32 , y : i32 | { x + y } ) as & Fn ( i32 , i32 ) -> i32 ;
121- assert_eq ! ( test_fn_object( function_object, 100 , 1 ) , 101 ) ;
122- assert_eq ! ( test_fn_impl( & function_object, 100 , 2 ) , 102 ) ;
127+ let closure = |x : i32 , y : i32 | { x + y } ;
128+ assert_eq ! ( test_closure( & closure, 100 , 1 ) , 101 ) ;
129+ let function_object = & closure as & Fn ( i32 , i32 ) -> i32 ;
130+ assert_eq ! ( test_fn_object( function_object, 100 , 2 ) , 102 ) ;
131+ assert_eq ! ( test_fn_impl( & function_object, 100 , 3 ) , 103 ) ;
123132}
0 commit comments