@@ -94,10 +94,9 @@ fn test8() -> isize {
94
94
}
95
95
96
96
#[ 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
+ {
101
100
f ( x, y)
102
101
}
103
102
@@ -106,6 +105,14 @@ fn test_fn_object(f: &Fn(i32, i32) -> i32, x: i32, y: i32) -> i32 {
106
105
f ( x, y)
107
106
}
108
107
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
+
109
116
fn main ( ) {
110
117
assert_eq ! ( test1( 1 , ( 2 , 3 ) , & [ 4 , 5 , 6 ] ) , ( 1 , ( 2 , 3 ) , & [ 4 , 5 , 6 ] [ ..] ) ) ;
111
118
assert_eq ! ( test2( 98 ) , 98 ) ;
@@ -117,7 +124,9 @@ fn main() {
117
124
assert_eq ! ( test7( ) , 1 ) ;
118
125
assert_eq ! ( test8( ) , 2 ) ;
119
126
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 ) ;
123
132
}
0 commit comments