Skip to content

Commit 19310ce

Browse files
committed
add test for str as extern "C" arg causes compiler panic #80125
Fixes #80125
1 parent a5ad0be commit 19310ce

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// test for #80125
2+
//@ check-pass
3+
type ExternCallback = extern "C" fn(*const u8, u32, str);
4+
//~^ WARN `extern` fn uses type `str`, which is not FFI-safe
5+
6+
pub struct Struct(ExternCallback);
7+
8+
#[no_mangle]
9+
pub extern "C" fn register_something(bind: ExternCallback) -> Struct {
10+
//~^ WARN `extern` fn uses type `str`, which is not FFI-safe
11+
//~^^ WARN `extern` fn uses type `Struct`, which is not FFI-safe
12+
Struct(bind)
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
warning: `extern` fn uses type `str`, which is not FFI-safe
2+
--> $DIR/extern-C-str-arg-ice-80125.rs:3:23
3+
|
4+
LL | type ExternCallback = extern "C" fn(*const u8, u32, str);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
6+
|
7+
= help: consider using `*const u8` and a length instead
8+
= note: string slices have no C equivalent
9+
= note: `#[warn(improper_ctypes_definitions)]` on by default
10+
11+
warning: `extern` fn uses type `str`, which is not FFI-safe
12+
--> $DIR/extern-C-str-arg-ice-80125.rs:9:44
13+
|
14+
LL | pub extern "C" fn register_something(bind: ExternCallback) -> Struct {
15+
| ^^^^^^^^^^^^^^ not FFI-safe
16+
|
17+
= help: consider using `*const u8` and a length instead
18+
= note: string slices have no C equivalent
19+
20+
warning: `extern` fn uses type `Struct`, which is not FFI-safe
21+
--> $DIR/extern-C-str-arg-ice-80125.rs:9:63
22+
|
23+
LL | pub extern "C" fn register_something(bind: ExternCallback) -> Struct {
24+
| ^^^^^^ not FFI-safe
25+
|
26+
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
27+
= note: this struct has unspecified layout
28+
note: the type is defined here
29+
--> $DIR/extern-C-str-arg-ice-80125.rs:6:1
30+
|
31+
LL | pub struct Struct(ExternCallback);
32+
| ^^^^^^^^^^^^^^^^^
33+
34+
warning: 3 warnings emitted
35+

0 commit comments

Comments
 (0)