Skip to content

Commit 74c0e61

Browse files
workingjubileeWaffleLapkin
authored andcommitted
Revert "Stabilize extended_varargs_abi_support"
This reverts commit 685f189.
1 parent 3821385 commit 74c0e61

File tree

16 files changed

+124
-12
lines changed

16 files changed

+124
-12
lines changed

compiler/rustc_feature/src/accepted.rs

-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ declare_features! (
197197
(accepted, expr_fragment_specifier_2024, "1.83.0", Some(123742)),
198198
/// Allows arbitrary expressions in key-value attributes at parse time.
199199
(accepted, extended_key_value_attributes, "1.54.0", Some(78835)),
200-
/// Allows using `efiapi`, `aapcs`, `sysv64` and `win64` as calling
201-
/// convention for functions with varargs.
202-
(accepted, extended_varargs_abi_support, "1.85.0", Some(100189)),
203200
/// Allows resolving absolute paths as paths from other crates.
204201
(accepted, extern_absolute_paths, "1.30.0", Some(44660)),
205202
/// Allows `extern crate foo as bar;`. This puts `bar` into extern prelude.

compiler/rustc_feature/src/unstable.rs

+3
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ declare_features! (
479479
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
480480
/// Allows explicit tail calls via `become` expression.
481481
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
482+
/// Allows using `efiapi`, `sysv64` and `win64` as calling convention
483+
/// for functions with varargs.
484+
(unstable, extended_varargs_abi_support, "1.65.0", Some(100189)),
482485
/// Allows defining `extern type`s.
483486
(unstable, extern_types, "1.23.0", Some(43467)),
484487
/// Allow using 128-bit (quad precision) floating point numbers.

compiler/rustc_hir_analysis/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ hir_analysis_value_of_associated_struct_already_specified =
602602
.label = re-bound here
603603
.previous_bound_label = `{$item_name}` bound here first
604604
605-
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
605+
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like {$conventions}
606606
.label = C-variadic function must have a compatible calling convention
607607
608608
hir_analysis_variances_of = {$variances}

compiler/rustc_hir_analysis/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,11 @@ pub(crate) struct MainFunctionGenericParameters {
688688

689689
#[derive(Diagnostic)]
690690
#[diag(hir_analysis_variadic_function_compatible_convention, code = E0045)]
691-
pub(crate) struct VariadicFunctionCompatibleConvention {
691+
pub(crate) struct VariadicFunctionCompatibleConvention<'a> {
692692
#[primary_span]
693693
#[label]
694694
pub span: Span,
695+
pub conventions: &'a str,
695696
}
696697

697698
#[derive(Diagnostic)]

compiler/rustc_hir_analysis/src/lib.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ use rustc_middle::middle;
100100
use rustc_middle::mir::interpret::GlobalId;
101101
use rustc_middle::query::Providers;
102102
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
103+
use rustc_session::parse::feature_err;
104+
use rustc_span::symbol::sym;
103105
use rustc_span::Span;
104106
use rustc_trait_selection::traits;
105107

@@ -113,9 +115,34 @@ fn require_c_abi_if_c_variadic(
113115
abi: ExternAbi,
114116
span: Span,
115117
) {
116-
if decl.c_variadic && !abi.supports_varargs() {
117-
tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span });
118+
const CONVENTIONS_UNSTABLE: &str =
119+
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
120+
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
121+
const UNSTABLE_EXPLAIN: &str =
122+
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
123+
124+
if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
125+
return;
118126
}
127+
128+
let extended_abi_support = tcx.features().extended_varargs_abi_support();
129+
let conventions = match (extended_abi_support, abi.supports_varargs()) {
130+
// User enabled additional ABI support for varargs and function ABI matches those ones.
131+
(true, true) => return,
132+
133+
// Using this ABI would be ok, if the feature for additional ABI support was enabled.
134+
// Return CONVENTIONS_STABLE, because we want the other error to look the same.
135+
(false, true) => {
136+
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN)
137+
.emit();
138+
CONVENTIONS_STABLE
139+
}
140+
141+
(false, false) => CONVENTIONS_STABLE,
142+
(true, false) => CONVENTIONS_UNSTABLE,
143+
};
144+
145+
tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span, conventions });
119146
}
120147

121148
pub fn provide(providers: &mut Providers) {

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
#![feature(doc_masked)]
290290
#![feature(doc_notable_trait)]
291291
#![feature(dropck_eyepatch)]
292+
#![feature(extended_varargs_abi_support)]
292293
#![feature(f128)]
293294
#![feature(f16)]
294295
#![feature(formatting_options)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `extended_varargs_abi_support`
2+
3+
The tracking issue for this feature is: [#100189]
4+
5+
[#100189]: https://github.com/rust-lang/rust/issues/100189
6+
7+
------------------------
8+
9+
This feature adds the possibility of using `sysv64`, `win64` or `efiapi` calling
10+
conventions on functions with varargs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ only-x86_64
2+
3+
fn efiapi(f: extern "efiapi" fn(usize, ...)) {
4+
//~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
5+
//~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
6+
f(22, 44);
7+
}
8+
fn sysv(f: extern "sysv64" fn(usize, ...)) {
9+
//~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
10+
//~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
11+
f(22, 44);
12+
}
13+
fn win(f: extern "win64" fn(usize, ...)) {
14+
//~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
15+
//~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
16+
f(22, 44);
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
2+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:3:14
3+
|
4+
LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #100189 <https://github.com/rust-lang/rust/issues/100189> for more information
8+
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
12+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:3:14
13+
|
14+
LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
16+
17+
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
18+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:8:12
19+
|
20+
LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: see issue #100189 <https://github.com/rust-lang/rust/issues/100189> for more information
24+
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
25+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
26+
27+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
28+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:8:12
29+
|
30+
LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
32+
33+
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
34+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:13:11
35+
|
36+
LL | fn win(f: extern "win64" fn(usize, ...)) {
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
|
39+
= note: see issue #100189 <https://github.com/rust-lang/rust/issues/100189> for more information
40+
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
41+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
42+
43+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
44+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:13:11
45+
|
46+
LL | fn win(f: extern "win64" fn(usize, ...)) {
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
48+
49+
error: aborting due to 6 previous errors
50+
51+
Some errors have detailed explanations: E0045, E0658.
52+
For more information about an error, try `rustc --explain E0045`.

tests/ui/c-variadic/variadic-ffi-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
1+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
22
--> $DIR/variadic-ffi-1.rs:9:5
33
|
44
LL | fn printf(_: *const u8, ...);

tests/ui/c-variadic/variadic-ffi-2-arm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ only-arm
22
//@ build-pass
3+
#![feature(extended_varargs_abi_support)]
34

45
fn aapcs(f: extern "aapcs" fn(usize, ...)) {
56
f(22, 44);

tests/ui/c-variadic/variadic-ffi-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ ignore-arm stdcall isn't supported
2+
#![feature(extended_varargs_abi_support)]
23

34
#[allow(unsupported_fn_ptr_calling_conventions)]
45
fn baz(f: extern "stdcall" fn(usize, ...)) {

tests/ui/c-variadic/variadic-ffi-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
2-
--> $DIR/variadic-ffi-2.rs:4:11
2+
--> $DIR/variadic-ffi-2.rs:5:11
33
|
44
LL | fn baz(f: extern "stdcall" fn(usize, ...)) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention

tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ type WithTransparentTraitObject =
3939
//~^ ERROR return value of `"C-cmse-nonsecure-call"` function too large to pass via registers [E0798]
4040

4141
type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
42-
//~^ ERROR C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi` [E0045]
42+
//~^ ERROR C-variadic function must have a compatible calling convention, like `C` or `cdecl` [E0045]

tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LL | extern "C-cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTranspa
6868
= note: functions with the `"C-cmse-nonsecure-call"` ABI must pass their result via the available return registers
6969
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
7070

71-
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
71+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
7272
--> $DIR/generics.rs:41:20
7373
|
7474
LL | type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);

tests/ui/error-codes/E0045.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
1+
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
22
--> $DIR/E0045.rs:1:17
33
|
44
LL | extern "Rust" { fn foo(x: u8, ...); }

0 commit comments

Comments
 (0)