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 {
10
10
j * i * 7
11
11
}
12
12
13
- fn return_fn_ptr ( ) -> fn ( ) -> i32 {
13
+ fn return_fn_ptr ( f : fn ( ) -> i32 ) -> fn ( ) -> i32 {
14
14
f
15
15
}
16
16
17
17
fn call_fn_ptr ( ) -> i32 {
18
- return_fn_ptr ( ) ( )
18
+ return_fn_ptr ( f ) ( )
19
19
}
20
20
21
21
fn indirect < F : Fn ( ) -> i32 > ( f : F ) -> i32 { f ( ) }
@@ -41,6 +41,7 @@ fn main() {
41
41
assert_eq ! ( indirect3( h) , 210 ) ;
42
42
assert_eq ! ( indirect_mut3( h) , 210 ) ;
43
43
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 ) ;
46
47
}
Original file line number Diff line number Diff line change @@ -60,7 +60,10 @@ fn main() {
60
60
let a = [ 0 , 1 , 2 ] ;
61
61
let square_local : fn ( u32 ) -> u32 = square;
62
62
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 ( ) ) ;
64
67
assert_eq ! ( g( 4 ) , 16 ) ;
65
68
assert_eq ! ( identity_coercion( g) ( 5 ) , 25 ) ;
66
69
You can’t perform that action at this time.
0 commit comments