Skip to content

variadic functions: remove list of supported ABIs from error #142464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
18 changes: 5 additions & 13 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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, ...)) {
Expand All @@ -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, ...)) {
Expand All @@ -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, ...)) {
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/c-variadic/variadic-ffi-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use minicore::*;

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" {
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/c-variadic/variadic-ffi-1.stderr
Original file line number Diff line number Diff line change
@@ -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, ...);
| ^^^ - -
Expand All @@ -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, ...);
| ^^^ -
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
| ^^^^
Expand All @@ -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);
| ^^^^
Expand All @@ -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);
| ^^^
Expand All @@ -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);
| ^^^
Expand All @@ -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);
| ^^^^
Expand All @@ -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);
| ^^^^
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/c-variadic/variadic-ffi-2.rs
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/c-variadic/variadic-ffi-2.stderr
Original file line number Diff line number Diff line change
@@ -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, ...)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ type WithTransparentTraitObject =
//~^ 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
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0045.stderr
Original file line number Diff line number Diff line change
@@ -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, ...); }
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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, ...)) {
Expand Down
Loading