about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2025-09-11 23:52:04 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2025-09-11 23:55:45 +0200
commit321a76b5f95325f20c9e88e87bfb4ddf536b6950 (patch)
tree0e3868cc2202d91bfec6ad9d2c062b0548c88aa4
parent01e83adc88653123fee444fdb930c16dd08da82d (diff)
downloadrust-321a76b5f95325f20c9e88e87bfb4ddf536b6950.tar.gz
rust-321a76b5f95325f20c9e88e87bfb4ddf536b6950.zip
c-variadic: test that unsupported c-variadic ABIs are reported correctly
-rw-r--r--tests/ui/c-variadic/unsupported-abi.rs123
-rw-r--r--tests/ui/c-variadic/unsupported-abi.stderr345
2 files changed, 468 insertions, 0 deletions
diff --git a/tests/ui/c-variadic/unsupported-abi.rs b/tests/ui/c-variadic/unsupported-abi.rs
new file mode 100644
index 00000000000..40179b164ce
--- /dev/null
+++ b/tests/ui/c-variadic/unsupported-abi.rs
@@ -0,0 +1,123 @@
+//@ add-core-stubs
+//@ needs-llvm-components: x86
+//@ compile-flags: --target=i686-pc-windows-gnu --crate-type=rlib
+#![no_core]
+#![feature(no_core, lang_items, c_variadic)]
+
+// Test that ABIs for which C-variadics are not supported report an error.
+
+extern crate minicore;
+use minicore::*;
+
+#[rustfmt::skip]
+mod foreign {
+    extern "Rust"  { fn rust_foreign_explicit(_: ...); }
+    //~^ ERROR C-variadic functions with the "Rust" calling convention are not supported
+    extern "C"  { fn c_foreign(_: ...); }
+    extern "C-unwind"  { fn c_unwind_foreign(_: ...); }
+    extern "cdecl"  { fn cdecl_foreign(_: ...); }
+    extern "cdecl-unwind"  { fn cdecl_unwind_foreign(_: ...); }
+    extern "stdcall"  { fn stdcall_foreign(_: ...); }
+    //~^ ERROR C-variadic functions with the "stdcall" calling convention are not supported
+    extern "stdcall-unwind"  { fn stdcall_unwind_foreign(_: ...); }
+    //~^ ERROR C-variadic functions with the "stdcall-unwind" calling convention are not supported
+    extern "thiscall"  { fn thiscall_foreign(_: ...); }
+    //~^ ERROR C-variadic functions with the "thiscall" calling convention are not supported
+    extern "thiscall-unwind"  { fn thiscall_unwind_foreign(_: ...); }
+    //~^ ERROR C-variadic functions with the "thiscall-unwind" calling convention are not supported
+}
+
+#[lang = "va_list"]
+struct VaList(*mut u8);
+
+unsafe fn rust_free(_: ...) {}
+//~^ ERROR `...` is not supported for non-extern functions
+unsafe extern "Rust" fn rust_free_explicit(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "Rust"` functions
+
+unsafe extern "C" fn c_free(_: ...) {}
+unsafe extern "C-unwind" fn c_unwind_free(_: ...) {}
+
+unsafe extern "cdecl" fn cdecl_free(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "cdecl"` functions
+unsafe extern "cdecl-unwind" fn cdecl_unwind_free(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
+unsafe extern "stdcall" fn stdcall_free(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "stdcall"` functions
+unsafe extern "stdcall-unwind" fn stdcall_unwind_free(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
+unsafe extern "thiscall" fn thiscall_free(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "thiscall"` functions
+unsafe extern "thiscall-unwind" fn thiscall_unwind_free(_: ...) {}
+//~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
+
+struct S;
+
+impl S {
+    unsafe fn rust_method(_: ...) {}
+    //~^ ERROR `...` is not supported for non-extern functions
+    unsafe extern "Rust" fn rust_method_explicit(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "Rust"` functions
+
+    unsafe extern "C" fn c_method(_: ...) {}
+    unsafe extern "C-unwind" fn c_unwind_method(_: ...) {}
+
+    unsafe extern "cdecl" fn cdecl_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "cdecl"` functions
+    unsafe extern "cdecl-unwind" fn cdecl_unwind_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
+    unsafe extern "stdcall" fn stdcall_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "stdcall"` functions
+    unsafe extern "stdcall-unwind" fn stdcall_unwind_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
+    unsafe extern "thiscall" fn thiscall_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "thiscall"` functions
+    unsafe extern "thiscall-unwind" fn thiscall_unwind_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
+}
+
+trait T {
+    unsafe fn rust_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for non-extern functions
+    unsafe extern "Rust" fn rust_trait_method_explicit(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "Rust"` functions
+
+    unsafe extern "C" fn c_trait_method(_: ...) {}
+    unsafe extern "C-unwind" fn c_unwind_trait_method(_: ...) {}
+
+    unsafe extern "cdecl" fn cdecl_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "cdecl"` functions
+    unsafe extern "cdecl-unwind" fn cdecl_unwind_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
+    unsafe extern "stdcall" fn stdcall_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "stdcall"` functions
+    unsafe extern "stdcall-unwind" fn stdcall_unwind_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
+    unsafe extern "thiscall" fn thiscall_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "thiscall"` functions
+    unsafe extern "thiscall-unwind" fn thiscall_unwind_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
+}
+
+impl T for S {
+    unsafe fn rust_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for non-extern functions
+    unsafe extern "Rust" fn rust_trait_method_explicit(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "Rust"` functions
+
+    unsafe extern "C" fn c_trait_method(_: ...) {}
+    unsafe extern "C-unwind" fn c_unwind_trait_method(_: ...) {}
+
+    unsafe extern "cdecl" fn cdecl_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "cdecl"` functions
+    unsafe extern "cdecl-unwind" fn cdecl_unwind_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
+    unsafe extern "stdcall" fn stdcall_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "stdcall"` functions
+    unsafe extern "stdcall-unwind" fn stdcall_unwind_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
+    unsafe extern "thiscall" fn thiscall_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "thiscall"` functions
+    unsafe extern "thiscall-unwind" fn thiscall_unwind_trait_method(_: ...) {}
+    //~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
+}
diff --git a/tests/ui/c-variadic/unsupported-abi.stderr b/tests/ui/c-variadic/unsupported-abi.stderr
new file mode 100644
index 00000000000..daed9171406
--- /dev/null
+++ b/tests/ui/c-variadic/unsupported-abi.stderr
@@ -0,0 +1,345 @@
+error: `...` is not supported for non-extern functions
+  --> $DIR/unsupported-abi.rs:33:21
+   |
+LL | unsafe fn rust_free(_: ...) {}
+   |                     ^^^^^^
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "Rust"` functions
+  --> $DIR/unsupported-abi.rs:35:44
+   |
+LL | unsafe extern "Rust" fn rust_free_explicit(_: ...) {}
+   |        -------------                       ^^^^^^
+   |        |
+   |        `extern "Rust"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl"` functions
+  --> $DIR/unsupported-abi.rs:41:37
+   |
+LL | unsafe extern "cdecl" fn cdecl_free(_: ...) {}
+   |        --------------               ^^^^^^
+   |        |
+   |        `extern "cdecl"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl-unwind"` functions
+  --> $DIR/unsupported-abi.rs:43:51
+   |
+LL | unsafe extern "cdecl-unwind" fn cdecl_unwind_free(_: ...) {}
+   |        ---------------------                      ^^^^^^
+   |        |
+   |        `extern "cdecl-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall"` functions
+  --> $DIR/unsupported-abi.rs:45:41
+   |
+LL | unsafe extern "stdcall" fn stdcall_free(_: ...) {}
+   |        ----------------                 ^^^^^^
+   |        |
+   |        `extern "stdcall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:47:55
+   |
+LL | unsafe extern "stdcall-unwind" fn stdcall_unwind_free(_: ...) {}
+   |        -----------------------                        ^^^^^^
+   |        |
+   |        `extern "stdcall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall"` functions
+  --> $DIR/unsupported-abi.rs:49:43
+   |
+LL | unsafe extern "thiscall" fn thiscall_free(_: ...) {}
+   |        -----------------                  ^^^^^^
+   |        |
+   |        `extern "thiscall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:51:57
+   |
+LL | unsafe extern "thiscall-unwind" fn thiscall_unwind_free(_: ...) {}
+   |        ------------------------                         ^^^^^^
+   |        |
+   |        `extern "thiscall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for non-extern functions
+  --> $DIR/unsupported-abi.rs:57:27
+   |
+LL |     unsafe fn rust_method(_: ...) {}
+   |                           ^^^^^^
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "Rust"` functions
+  --> $DIR/unsupported-abi.rs:59:50
+   |
+LL |     unsafe extern "Rust" fn rust_method_explicit(_: ...) {}
+   |            -------------                         ^^^^^^
+   |            |
+   |            `extern "Rust"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl"` functions
+  --> $DIR/unsupported-abi.rs:65:43
+   |
+LL |     unsafe extern "cdecl" fn cdecl_method(_: ...) {}
+   |            --------------                 ^^^^^^
+   |            |
+   |            `extern "cdecl"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl-unwind"` functions
+  --> $DIR/unsupported-abi.rs:67:57
+   |
+LL |     unsafe extern "cdecl-unwind" fn cdecl_unwind_method(_: ...) {}
+   |            ---------------------                        ^^^^^^
+   |            |
+   |            `extern "cdecl-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall"` functions
+  --> $DIR/unsupported-abi.rs:69:47
+   |
+LL |     unsafe extern "stdcall" fn stdcall_method(_: ...) {}
+   |            ----------------                   ^^^^^^
+   |            |
+   |            `extern "stdcall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:71:61
+   |
+LL |     unsafe extern "stdcall-unwind" fn stdcall_unwind_method(_: ...) {}
+   |            -----------------------                          ^^^^^^
+   |            |
+   |            `extern "stdcall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall"` functions
+  --> $DIR/unsupported-abi.rs:73:49
+   |
+LL |     unsafe extern "thiscall" fn thiscall_method(_: ...) {}
+   |            -----------------                    ^^^^^^
+   |            |
+   |            `extern "thiscall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:75:63
+   |
+LL |     unsafe extern "thiscall-unwind" fn thiscall_unwind_method(_: ...) {}
+   |            ------------------------                           ^^^^^^
+   |            |
+   |            `extern "thiscall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for non-extern functions
+  --> $DIR/unsupported-abi.rs:80:33
+   |
+LL |     unsafe fn rust_trait_method(_: ...) {}
+   |                                 ^^^^^^
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "Rust"` functions
+  --> $DIR/unsupported-abi.rs:82:56
+   |
+LL |     unsafe extern "Rust" fn rust_trait_method_explicit(_: ...) {}
+   |            -------------                               ^^^^^^
+   |            |
+   |            `extern "Rust"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl"` functions
+  --> $DIR/unsupported-abi.rs:88:49
+   |
+LL |     unsafe extern "cdecl" fn cdecl_trait_method(_: ...) {}
+   |            --------------                       ^^^^^^
+   |            |
+   |            `extern "cdecl"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl-unwind"` functions
+  --> $DIR/unsupported-abi.rs:90:63
+   |
+LL |     unsafe extern "cdecl-unwind" fn cdecl_unwind_trait_method(_: ...) {}
+   |            ---------------------                              ^^^^^^
+   |            |
+   |            `extern "cdecl-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall"` functions
+  --> $DIR/unsupported-abi.rs:92:53
+   |
+LL |     unsafe extern "stdcall" fn stdcall_trait_method(_: ...) {}
+   |            ----------------                         ^^^^^^
+   |            |
+   |            `extern "stdcall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:94:67
+   |
+LL |     unsafe extern "stdcall-unwind" fn stdcall_unwind_trait_method(_: ...) {}
+   |            -----------------------                                ^^^^^^
+   |            |
+   |            `extern "stdcall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall"` functions
+  --> $DIR/unsupported-abi.rs:96:55
+   |
+LL |     unsafe extern "thiscall" fn thiscall_trait_method(_: ...) {}
+   |            -----------------                          ^^^^^^
+   |            |
+   |            `extern "thiscall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:98:69
+   |
+LL |     unsafe extern "thiscall-unwind" fn thiscall_unwind_trait_method(_: ...) {}
+   |            ------------------------                                 ^^^^^^
+   |            |
+   |            `extern "thiscall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for non-extern functions
+  --> $DIR/unsupported-abi.rs:103:33
+   |
+LL |     unsafe fn rust_trait_method(_: ...) {}
+   |                                 ^^^^^^
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "Rust"` functions
+  --> $DIR/unsupported-abi.rs:105:56
+   |
+LL |     unsafe extern "Rust" fn rust_trait_method_explicit(_: ...) {}
+   |            -------------                               ^^^^^^
+   |            |
+   |            `extern "Rust"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl"` functions
+  --> $DIR/unsupported-abi.rs:111:49
+   |
+LL |     unsafe extern "cdecl" fn cdecl_trait_method(_: ...) {}
+   |            --------------                       ^^^^^^
+   |            |
+   |            `extern "cdecl"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "cdecl-unwind"` functions
+  --> $DIR/unsupported-abi.rs:113:63
+   |
+LL |     unsafe extern "cdecl-unwind" fn cdecl_unwind_trait_method(_: ...) {}
+   |            ---------------------                              ^^^^^^
+   |            |
+   |            `extern "cdecl-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall"` functions
+  --> $DIR/unsupported-abi.rs:115:53
+   |
+LL |     unsafe extern "stdcall" fn stdcall_trait_method(_: ...) {}
+   |            ----------------                         ^^^^^^
+   |            |
+   |            `extern "stdcall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "stdcall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:117:67
+   |
+LL |     unsafe extern "stdcall-unwind" fn stdcall_unwind_trait_method(_: ...) {}
+   |            -----------------------                                ^^^^^^
+   |            |
+   |            `extern "stdcall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall"` functions
+  --> $DIR/unsupported-abi.rs:119:55
+   |
+LL |     unsafe extern "thiscall" fn thiscall_trait_method(_: ...) {}
+   |            -----------------                          ^^^^^^
+   |            |
+   |            `extern "thiscall"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error: `...` is not supported for `extern "thiscall-unwind"` functions
+  --> $DIR/unsupported-abi.rs:121:69
+   |
+LL |     unsafe extern "thiscall-unwind" fn thiscall_unwind_trait_method(_: ...) {}
+   |            ------------------------                                 ^^^^^^
+   |            |
+   |            `extern "thiscall-unwind"` because of this
+   |
+   = help: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
+
+error[E0045]: C-variadic functions with the "Rust" calling convention are not supported
+  --> $DIR/unsupported-abi.rs:14:22
+   |
+LL |     extern "Rust"  { fn rust_foreign_explicit(_: ...); }
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0045]: C-variadic functions with the "stdcall" calling convention are not supported
+  --> $DIR/unsupported-abi.rs:20:25
+   |
+LL |     extern "stdcall"  { fn stdcall_foreign(_: ...); }
+   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0045]: C-variadic functions with the "stdcall-unwind" calling convention are not supported
+  --> $DIR/unsupported-abi.rs:22:32
+   |
+LL |     extern "stdcall-unwind"  { fn stdcall_unwind_foreign(_: ...); }
+   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0045]: C-variadic functions with the "thiscall" calling convention are not supported
+  --> $DIR/unsupported-abi.rs:24:26
+   |
+LL |     extern "thiscall"  { fn thiscall_foreign(_: ...); }
+   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0045]: C-variadic functions with the "thiscall-unwind" calling convention are not supported
+  --> $DIR/unsupported-abi.rs:26:33
+   |
+LL |     extern "thiscall-unwind"  { fn thiscall_unwind_foreign(_: ...); }
+   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error: aborting due to 37 previous errors
+
+For more information about this error, try `rustc --explain E0045`.