Skip to content

Commit

Permalink
add test for str as extern "C" arg causes compiler panic rust-lang#80125
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskrgr authored and RenjiSann committed Mar 25, 2024
1 parent a4b0e0f commit 52e19fc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/ui/extern/extern-C-str-arg-ice-80125.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// test for #80125
//@ check-pass
type ExternCallback = extern "C" fn(*const u8, u32, str);
//~^ WARN `extern` fn uses type `str`, which is not FFI-safe

pub struct Struct(ExternCallback);

#[no_mangle]
pub extern "C" fn register_something(bind: ExternCallback) -> Struct {
//~^ WARN `extern` fn uses type `str`, which is not FFI-safe
//~^^ WARN `extern` fn uses type `Struct`, which is not FFI-safe
Struct(bind)
}

fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/extern/extern-C-str-arg-ice-80125.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
warning: `extern` fn uses type `str`, which is not FFI-safe
--> $DIR/extern-C-str-arg-ice-80125.rs:3:23
|
LL | type ExternCallback = extern "C" fn(*const u8, u32, str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider using `*const u8` and a length instead
= note: string slices have no C equivalent
= note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `str`, which is not FFI-safe
--> $DIR/extern-C-str-arg-ice-80125.rs:9:44
|
LL | pub extern "C" fn register_something(bind: ExternCallback) -> Struct {
| ^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider using `*const u8` and a length instead
= note: string slices have no C equivalent

warning: `extern` fn uses type `Struct`, which is not FFI-safe
--> $DIR/extern-C-str-arg-ice-80125.rs:9:63
|
LL | pub extern "C" fn register_something(bind: ExternCallback) -> Struct {
| ^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: the type is defined here
--> $DIR/extern-C-str-arg-ice-80125.rs:6:1
|
LL | pub struct Struct(ExternCallback);
| ^^^^^^^^^^^^^^^^^

warning: 3 warnings emitted

0 comments on commit 52e19fc

Please sign in to comment.