variadic functions: remove list of supported ABIs from error

This commit is contained in:
Ralf Jung
2025-06-13 17:18:26 +02:00
parent c359117819
commit 963fdbc852
14 changed files with 34 additions and 44 deletions
+1 -1
View File
@@ -595,7 +595,7 @@ hir_analysis_value_of_associated_struct_already_specified =
.label = re-bound here
.previous_bound_label = `{$item_name}` bound here first
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like {$conventions}
hir_analysis_variadic_function_compatible_convention = C-variadic functions with the {$convention} calling convention are not supported
.label = C-variadic function must have a compatible calling convention
hir_analysis_variances_of = {$variances}
+1 -1
View File
@@ -633,7 +633,7 @@ pub(crate) struct VariadicFunctionCompatibleConvention<'a> {
#[primary_span]
#[label]
pub span: Span,
pub conventions: &'a str,
pub convention: &'a str,
}
#[derive(Diagnostic)]
+5 -13
View File
@@ -115,12 +115,6 @@ fn require_c_abi_if_c_variadic(
abi: ExternAbi,
span: Span,
) {
const CONVENTIONS_UNSTABLE: &str =
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
const UNSTABLE_EXPLAIN: &str =
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
// ABIs which can stably use varargs
if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
return;
@@ -140,20 +134,18 @@ fn require_c_abi_if_c_variadic(
// Looks like we need to pick an error to emit.
// Is there any feature which we could have enabled to make this work?
let unstable_explain =
format!("C-variadic functions with the {abi} calling convention are unstable");
match abi {
ExternAbi::System { .. } => {
feature_err(&tcx.sess, sym::extern_system_varargs, span, UNSTABLE_EXPLAIN)
feature_err(&tcx.sess, sym::extern_system_varargs, span, unstable_explain)
}
abi if abi.supports_varargs() => {
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN)
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, unstable_explain)
}
_ => tcx.dcx().create_err(errors::VariadicFunctionCompatibleConvention {
span,
conventions: if tcx.sess.opts.unstable_features.is_nightly_build() {
CONVENTIONS_UNSTABLE
} else {
CONVENTIONS_STABLE
},
convention: &format!("{abi}"),
}),
}
.emit();
@@ -1,15 +1,15 @@
//@ only-x86_64
fn efiapi(f: extern "efiapi" fn(usize, ...)) {
//~^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
//~^ ERROR: unstable
f(22, 44);
}
fn sysv(f: extern "sysv64" fn(usize, ...)) {
//~^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
//~^ ERROR: unstable
f(22, 44);
}
fn win(f: extern "win64" fn(usize, ...)) {
//~^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
//~^ ERROR: unstable
f(22, 44);
}
@@ -1,4 +1,4 @@
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
error[E0658]: C-variadic functions with the "efiapi" calling convention are unstable
--> $DIR/feature-gate-extended_varargs_abi_support.rs:3:14
|
LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
@@ -8,7 +8,7 @@ LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
error[E0658]: C-variadic functions with the "sysv64" calling convention are unstable
--> $DIR/feature-gate-extended_varargs_abi_support.rs:7:12
|
LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
@@ -18,7 +18,7 @@ LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
error[E0658]: C-variadic functions with the "win64" calling convention are unstable
--> $DIR/feature-gate-extended_varargs_abi_support.rs:11:11
|
LL | fn win(f: extern "win64" fn(usize, ...)) {
+1 -2
View File
@@ -9,8 +9,7 @@
extern "stdcall" {
fn printf(_: *const u8, ...);
//~^ ERROR: C-variadic function must have a compatible calling convention,
// like C, cdecl, win64, sysv64 or efiapi
//~^ ERROR: C-variadic functions with the "stdcall" calling convention are not supported
}
extern "C" {
+13 -13
View File
@@ -1,17 +1,17 @@
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
error[E0045]: C-variadic functions with the "stdcall" calling convention are not supported
--> $DIR/variadic-ffi-1.rs:11:5
|
LL | fn printf(_: *const u8, ...);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
error[E0060]: this function takes at least 2 arguments but 0 arguments were supplied
--> $DIR/variadic-ffi-1.rs:24:9
--> $DIR/variadic-ffi-1.rs:23:9
|
LL | foo();
| ^^^-- two arguments of type `isize` and `u8` are missing
|
note: function defined here
--> $DIR/variadic-ffi-1.rs:17:8
--> $DIR/variadic-ffi-1.rs:16:8
|
LL | fn foo(f: isize, x: u8, ...);
| ^^^ - -
@@ -21,13 +21,13 @@ LL | foo(/* isize */, /* u8 */);
| +++++++++++++++++++++
error[E0060]: this function takes at least 2 arguments but 1 argument was supplied
--> $DIR/variadic-ffi-1.rs:25:9
--> $DIR/variadic-ffi-1.rs:24:9
|
LL | foo(1);
| ^^^--- argument #2 of type `u8` is missing
|
note: function defined here
--> $DIR/variadic-ffi-1.rs:17:8
--> $DIR/variadic-ffi-1.rs:16:8
|
LL | fn foo(f: isize, x: u8, ...);
| ^^^ -
@@ -37,7 +37,7 @@ LL | foo(1, /* u8 */);
| ++++++++++
error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:27:56
--> $DIR/variadic-ffi-1.rs:26:56
|
LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
| ------------------------------------- ^^^ expected non-variadic fn, found variadic function
@@ -48,7 +48,7 @@ LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
found fn item `unsafe extern "C" fn(_, _, ...) {foo}`
error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:28:54
--> $DIR/variadic-ffi-1.rs:27:54
|
LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
| ----------------------------------- ^^^ expected variadic fn, found non-variadic function
@@ -59,7 +59,7 @@ LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
found fn item `extern "C" fn(_, _) {bar}`
error[E0617]: can't pass `f32` to variadic function
--> $DIR/variadic-ffi-1.rs:30:19
--> $DIR/variadic-ffi-1.rs:29:19
|
LL | foo(1, 2, 3f32);
| ^^^^
@@ -70,7 +70,7 @@ LL | foo(1, 2, 3f32 as c_double);
| +++++++++++
error[E0617]: can't pass `bool` to variadic function
--> $DIR/variadic-ffi-1.rs:31:19
--> $DIR/variadic-ffi-1.rs:30:19
|
LL | foo(1, 2, true);
| ^^^^
@@ -81,7 +81,7 @@ LL | foo(1, 2, true as c_int);
| ++++++++
error[E0617]: can't pass `i8` to variadic function
--> $DIR/variadic-ffi-1.rs:32:19
--> $DIR/variadic-ffi-1.rs:31:19
|
LL | foo(1, 2, 1i8);
| ^^^
@@ -92,7 +92,7 @@ LL | foo(1, 2, 1i8 as c_int);
| ++++++++
error[E0617]: can't pass `u8` to variadic function
--> $DIR/variadic-ffi-1.rs:33:19
--> $DIR/variadic-ffi-1.rs:32:19
|
LL | foo(1, 2, 1u8);
| ^^^
@@ -103,7 +103,7 @@ LL | foo(1, 2, 1u8 as c_uint);
| +++++++++
error[E0617]: can't pass `i16` to variadic function
--> $DIR/variadic-ffi-1.rs:34:19
--> $DIR/variadic-ffi-1.rs:33:19
|
LL | foo(1, 2, 1i16);
| ^^^^
@@ -114,7 +114,7 @@ LL | foo(1, 2, 1i16 as c_int);
| ++++++++
error[E0617]: can't pass `u16` to variadic function
--> $DIR/variadic-ffi-1.rs:35:19
--> $DIR/variadic-ffi-1.rs:34:19
|
LL | foo(1, 2, 1u16);
| ^^^^
+1 -2
View File
@@ -1,8 +1,7 @@
#![feature(extended_varargs_abi_support)]
fn baz(f: extern "Rust" fn(usize, ...)) {
//~^ ERROR: C-variadic function must have a compatible calling convention,
// like C, cdecl, system, aapcs, win64, sysv64 or efiapi
//~^ ERROR: C-variadic functions with the "Rust" calling convention are not supported
f(22, 44);
}
+1 -1
View File
@@ -1,4 +1,4 @@
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
error[E0045]: C-variadic functions with the "Rust" calling convention are not supported
--> $DIR/variadic-ffi-2.rs:3:11
|
LL | fn baz(f: extern "Rust" fn(usize, ...)) {
@@ -38,4 +38,4 @@ trait Trait {}
//~^ ERROR return value of `"C-cmse-nonsecure-call"` function too large to pass via registers [E0798]
type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
//~^ ERROR C-variadic function must have a compatible calling convention, like `C`
//~^ ERROR C-variadic functions with the "C-cmse-nonsecure-call" calling convention are not supported
@@ -69,7 +69,7 @@ LL | extern "C-cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTranspa
= note: functions with the `"C-cmse-nonsecure-call"` ABI must pass their result via the available return registers
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
error[E0045]: C-variadic functions with the "C-cmse-nonsecure-call" calling convention are not supported
--> $DIR/generics.rs:40:20
|
LL | type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
+1 -1
View File
@@ -1,4 +1,4 @@
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
error[E0045]: C-variadic functions with the "Rust" calling convention are not supported
--> $DIR/E0045.rs:1:17
|
LL | extern "Rust" { fn foo(x: u8, ...); }
@@ -1,5 +1,5 @@
fn system(f: extern "system" fn(usize, ...)) {
//~^ ERROR using calling conventions other than `C` or `cdecl` for varargs functions is unstable
//~^ ERROR unstable
f(22, 44);
}
@@ -1,4 +1,4 @@
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
error[E0658]: C-variadic functions with the "system" calling convention are unstable
--> $DIR/feature-gate-extern_system_varargs.rs:1:14
|
LL | fn system(f: extern "system" fn(usize, ...)) {