Skip to content

Commit 9aec5c5

Browse files
committed
Add test for fn pointer duplication.
1 parent 1a851da commit 9aec5c5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ compile-flags:-O
2+
3+
fn foo() {}
4+
5+
pub static ADDR: fn() = foo;
6+
7+
#[inline(always)]
8+
pub fn bar(x: fn()) -> bool {
9+
x == ADDR
10+
}

tests/ui/mir/static_fnptr.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ run-pass
2+
//@ compile-flags:-Cno-prepopulate-passes -Copt-level=0
3+
//@ aux-build:static_fnptr.rs
4+
5+
extern crate static_fnptr;
6+
use static_fnptr::{ADDR, bar};
7+
8+
fn baz() -> bool {
9+
bar(ADDR)
10+
}
11+
12+
fn main() {
13+
assert!(baz())
14+
}

0 commit comments

Comments
 (0)