about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-22 18:12:49 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2024-03-24 09:23:12 +0100
commit19310ce2cc330f301d60ce53541969e5f5602d52 (patch)
tree330d4ce69fb40cf631913a83535662837943401f
parenta5ad0be52f123b4d6c61c62567518f7c5692af39 (diff)
downloadrust-19310ce2cc330f301d60ce53541969e5f5602d52.tar.gz
rust-19310ce2cc330f301d60ce53541969e5f5602d52.zip
add test for str as extern "C" arg causes compiler panic #80125
Fixes #80125
-rw-r--r--tests/ui/extern/extern-C-str-arg-ice-80125.rs15
-rw-r--r--tests/ui/extern/extern-C-str-arg-ice-80125.stderr35
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/extern/extern-C-str-arg-ice-80125.rs b/tests/ui/extern/extern-C-str-arg-ice-80125.rs
new file mode 100644
index 00000000000..71098fed2ef
--- /dev/null
+++ b/tests/ui/extern/extern-C-str-arg-ice-80125.rs
@@ -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() {}
diff --git a/tests/ui/extern/extern-C-str-arg-ice-80125.stderr b/tests/ui/extern/extern-C-str-arg-ice-80125.stderr
new file mode 100644
index 00000000000..ebd6cec6ecd
--- /dev/null
+++ b/tests/ui/extern/extern-C-str-arg-ice-80125.stderr
@@ -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
+