Skip to content
Draft
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
4 changes: 2 additions & 2 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ impl ExternAbi {
}

/// Returns whether the ABI supports C variadics. This only controls whether we allow *imports*
/// of such functions via `extern` blocks; there's a separate check during AST construction
/// guarding *definitions* of variadic functions.
/// of such functions via `extern` blocks and definition via naked functions; there's a
/// separate check during AST construction guarding *definitions* of variadic functions.
Comment on lines +293 to +294

@folkertdev folkertdev Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the reference we now have to differentiate between naked and non-naked (clothed?) definitions. I guess we'll figure out some terminology in the reference PR.

View changes since the review

#[cfg(feature = "nightly")]
pub fn supports_c_variadic(self) -> CVariadicStatus {
// * C and Cdecl obviously support varargs.
Expand Down
21 changes: 3 additions & 18 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,29 +957,14 @@ impl<'a> AstValidator<'a> {
dotdotdot_span: Span,
sig: &FnSig,
) {
// For naked functions we accept any ABI that is accepted on c-variadic
// foreign functions, if the c_variadic_naked_functions feature is enabled.
if attr::contains_name(attrs, sym::naked) {
match abi.supports_c_variadic() {
CVariadicStatus::Stable if let ExternAbi::C { .. } = abi => {
// With `c_variadic` naked c-variadic `extern "C"` functions are allowed.
}
CVariadicStatus::Stable => {
// For e.g. aapcs or sysv64 `c_variadic_naked_functions` must also be enabled.
if !self.features.enabled(sym::c_variadic_naked_functions) {
let msg = format!("Naked c-variadic `extern {abi}` functions are unstable");
feature_err(&self.sess, sym::c_variadic_naked_functions, sig.span, msg)
.emit();
}
// For naked functions we accept any ABI that is accepted
// on c-variadic foreign functions.
}
CVariadicStatus::Unstable { feature } => {
// Some ABIs need additional features.
if !self.features.enabled(sym::c_variadic_naked_functions) {
let msg = format!("Naked c-variadic `extern {abi}` functions are unstable");
feature_err(&self.sess, sym::c_variadic_naked_functions, sig.span, msg)
.emit();
}

// Some ABIs need additional features to be enabled.
if !self.features.enabled(feature) {
let msg = format!(
"C-variadic functions with the {abi} calling convention are unstable"
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ declare_features! (
(accepted, c_unwind, "1.81.0", Some(74990)),
/// Allows using C-variadics.
(accepted, c_variadic, "CURRENT_RUSTC_VERSION", Some(44930)),
/// Allows defining c-variadic naked functions with any extern ABI that is allowed
/// on c-variadic foreign functions.
(accepted, c_variadic_naked_functions, "CURRENT_RUSTC_VERSION", Some(148767)),
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
/// Allows the use of `#[cfg(<true/false>)]`.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,6 @@ declare_features! (
/// Allows defining c-variadic functions on targets where this feature has not yet
/// undergone sufficient testing for stabilization.
(unstable, c_variadic_experimental_arch, "1.97.0", Some(155973)),
/// Allows defining c-variadic naked functions with any extern ABI that is allowed
/// on c-variadic foreign functions.
(unstable, c_variadic_naked_functions, "1.93.0", Some(148767)),
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
(unstable, cfg_contract_checks, "1.86.0", Some(128044)),
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/c-variadic/naked-invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ ignore-backends: gcc

#![feature(no_core, lang_items, rustc_attrs)]
#![feature(c_variadic_naked_functions, abi_x86_interrupt, naked_functions_rustic_abi)]
#![feature(abi_x86_interrupt, naked_functions_rustic_abi)]
#![crate_type = "rlib"]
#![no_core]

Expand Down
1 change: 0 additions & 1 deletion tests/ui/c-variadic/naked.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ run-pass
//@ only-x86_64
//@ only-linux
#![feature(c_variadic_naked_functions)]

#[repr(C)]
#[derive(Debug, PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/c-variadic/same-program-multiple-abis-arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ only-arm
//@ ignore-thumb (this test uses arm assembly)
//@ only-eabihf (the assembly below requires float hardware support)
#![feature(c_variadic_naked_functions)]

// Check that multiple c-variadic calling conventions can be used in the same program.
//
Expand Down
1 change: 0 additions & 1 deletion tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ run-pass
//@ only-x86_64
#![feature(c_variadic_naked_functions)]

// Check that multiple c-variadic calling conventions can be used in the same program.
//
Expand Down
27 changes: 0 additions & 27 deletions tests/ui/feature-gates/feature-gate-c_variadic-naked-functions.rs

This file was deleted.

This file was deleted.

Loading