File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,12 @@ fn h(i: i32, j: i32) -> i32 {
1010 j * i * 7
1111}
1212
13- fn return_fn_ptr ( ) -> fn ( ) -> i32 {
13+ fn return_fn_ptr ( f : fn ( ) -> i32 ) -> fn ( ) -> i32 {
1414 f
1515}
1616
1717fn call_fn_ptr ( ) -> i32 {
18- return_fn_ptr ( ) ( )
18+ return_fn_ptr ( f ) ( )
1919}
2020
2121fn indirect < F : Fn ( ) -> i32 > ( f : F ) -> i32 { f ( ) }
@@ -41,6 +41,7 @@ fn main() {
4141 assert_eq ! ( indirect3( h) , 210 ) ;
4242 assert_eq ! ( indirect_mut3( h) , 210 ) ;
4343 assert_eq ! ( indirect_once3( h) , 210 ) ;
44- assert ! ( return_fn_ptr( ) == f) ;
45- assert ! ( return_fn_ptr( ) as unsafe fn ( ) -> i32 == f as fn ( ) -> i32 as unsafe fn ( ) -> i32 ) ;
44+ let g = f as fn ( ) -> i32 ;
45+ assert ! ( return_fn_ptr( g) == g) ;
46+ assert ! ( return_fn_ptr( g) as unsafe fn ( ) -> i32 == g as fn ( ) -> i32 as unsafe fn ( ) -> i32 ) ;
4647}
Original file line number Diff line number Diff line change @@ -60,7 +60,10 @@ fn main() {
6060 let a = [ 0 , 1 , 2 ] ;
6161 let square_local : fn ( u32 ) -> u32 = square;
6262 let ( f, g) = fn_coercions ( & square_local) ;
63- assert_eq ! ( f as * const ( ) , square as * const ( ) ) ;
63+ // cannot use `square as *const ()` because we can't know whether the compiler duplicates
64+ // functions, so two function pointers are only equal if they result from the same function
65+ // to function pointer cast
66+ assert_eq ! ( f as * const ( ) , square_local as * const ( ) ) ;
6467 assert_eq ! ( g( 4 ) , 16 ) ;
6568 assert_eq ! ( identity_coercion( g) ( 5 ) , 25 ) ;
6669
You can’t perform that action at this time.
0 commit comments