Skip to content

Commit 1dd6cc3

Browse files
authored
Merge pull request #576 from solson/rustup3
Adjust tests for funciton pointer changes
2 parents 96b2c34 + 77ef84e commit 1dd6cc3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tests/run-pass/function_pointers.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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

1717
fn call_fn_ptr() -> i32 {
18-
return_fn_ptr()()
18+
return_fn_ptr(f)()
1919
}
2020

2121
fn 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
}

tests/run-pass/mir_coercions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)