Skip to content

Commit 4a65032

Browse files
committed
Ensure that we error when calling "const extern fn" with wrong convention
See #64926
1 parent 6250d56 commit 4a65032

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Checks that we report ABI mismatches for "const extern fn"
2+
// compile-flags: -Z unleash-the-miri-inside-of-you
3+
4+
#![feature(const_extern_fn)]
5+
6+
const extern "C" fn c_fn() {}
7+
8+
const fn call_rust_fn(my_fn: extern "Rust" fn()) {
9+
my_fn(); //~ ERROR any use of this value will cause an error
10+
//~^ WARN skipping const checks
11+
}
12+
13+
const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
14+
//~^ WARN skipping const checks
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
warning: skipping const checks
2+
--> $DIR/abi-mismatch.rs:9:5
3+
|
4+
LL | my_fn();
5+
| ^^^^^^^
6+
7+
warning: skipping const checks
8+
--> $DIR/abi-mismatch.rs:13:39
9+
|
10+
LL | const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: any use of this value will cause an error
14+
--> $DIR/abi-mismatch.rs:9:5
15+
|
16+
LL | my_fn();
17+
| ^^^^^^^
18+
| |
19+
| tried to call a function with ABI C using caller ABI Rust
20+
| inside call to `call_rust_fn` at $DIR/abi-mismatch.rs:13:17
21+
...
22+
LL | const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
23+
| --------------------------------------------------------------------------------------
24+
|
25+
= note: `#[deny(const_err)]` on by default
26+
27+
error: aborting due to previous error
28+

0 commit comments

Comments
 (0)