Skip to content
Open
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
8 changes: 2 additions & 6 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Comment thread
folkertdev marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::visit::{self, AssocCtxt, FnKind, Visitor};
use rustc_ast::{self as ast, AttrVec, GenericBound, NodeId, PatKind, attr, token};
use rustc_attr_parsing::AttributeParser;
use rustc_errors::msg;
Expand Down Expand Up @@ -379,7 +379,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_poly_trait_ref(self, t);
}

fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, _: Span, _: NodeId) {
if let Some(_header) = fn_kind.header() {
// Stability of const fn methods are covered in `visit_assoc_item` below.
}
Expand All @@ -388,10 +388,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
self.check_late_bound_lifetime_defs(generic_params);
}

if fn_kind.ctxt() != Some(FnCtxt::Foreign) && fn_kind.decl().c_variadic() {
gate!(self, c_variadic, span, "C-variadic functions are unstable");
}

visit::walk_fn(self, fn_kind)
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ declare_features! (
(accepted, c_str_literals, "1.77.0", Some(105723)),
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries and treat `extern "C" fn` as nounwind.
(accepted, c_unwind, "1.81.0", Some(74990)),
/// Allows using C-variadics.
(accepted, c_variadic, "CURRENT_RUSTC_VERSION", Some(44930)),
/// 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
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ declare_features! (
(unstable, avx10_target_feature, "1.88.0", Some(138843)),
/// Target features on bpf.
(unstable, bpf_target_feature, "1.54.0", Some(150247)),
/// Allows using C-variadics.
(unstable, c_variadic, "1.34.0", Some(44930)),
/// 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)),
Expand Down
6 changes: 1 addition & 5 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ use crate::fmt;
pub mod c_str;

mod va_list;
#[unstable(
feature = "c_variadic",
issue = "44930",
reason = "the `c_variadic` feature has not been properly tested on all supported platforms"
)]
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
pub use self::va_list::{VaArgSafe, VaList};

mod primitives;
Expand Down
26 changes: 18 additions & 8 deletions library/core/src/ffi/va_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
//!
//! Better known as "varargs".

#![unstable(
feature = "c_variadic",
issue = "44930",
reason = "the `c_variadic` feature has not been properly tested on all supported platforms"
)]

#[cfg(not(target_arch = "xtensa"))]
use crate::ffi::c_void;
use crate::fmt;
Expand Down Expand Up @@ -195,8 +189,6 @@ crate::cfg_select! {
/// is automatically initialized (equivalent to calling `va_start` in C).
///
/// ```
/// #![feature(c_variadic)]
///
/// use std::ffi::VaList;
///
/// /// # Safety
Expand Down Expand Up @@ -230,11 +222,13 @@ crate::cfg_select! {
/// terms of layout and ABI.
#[repr(transparent)]
#[lang = "va_list"]
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
pub struct VaList<'a> {
inner: VaListInner,
_marker: PhantomCovariantLifetime<'a>,
}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for VaList<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// No need to include `_marker` in debug output.
Expand All @@ -249,6 +243,7 @@ impl VaList<'_> {
}
}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")]
const impl<'f> Clone for VaList<'f> {
/// Clone the [`VaList`], producing a second independent cursor into the variable argument list.
Expand All @@ -264,6 +259,7 @@ const impl<'f> Clone for VaList<'f> {
}
}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")]
const impl<'f> Drop for VaList<'f> {
/// Drop the [`VaList`].
Expand Down Expand Up @@ -313,6 +309,7 @@ const impl<'f> Drop for VaList<'f> {
// types with an alignment larger than 8, or with a non-scalar layout. Inline assembly can be used
// to accept unsupported types in the meantime.
#[lang = "va_arg_safe"]
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
pub impl(self) unsafe trait VaArgSafe: Copy {}

crate::cfg_select! {
Expand All @@ -321,7 +318,9 @@ crate::cfg_select! {
//
// - i8 is implicitly promoted to c_int in C, and cannot implement `VaArgSafe`.
// - u8 is implicitly promoted to c_uint in C, and cannot implement `VaArgSafe`.
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for i16 {}
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for u16 {}
}
_ => {
Expand All @@ -335,6 +334,7 @@ crate::cfg_select! {
crate::cfg_select! {
target_arch = "avr" => {
// c_double is f32 on this target.
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for f32 {}
}
_ => {
Expand All @@ -344,17 +344,26 @@ crate::cfg_select! {
}
}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for i32 {}
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for i64 {}
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for isize {}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for u32 {}
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for u64 {}
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for usize {}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl VaArgSafe for f64 {}

#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl<T> VaArgSafe for *mut T {}
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
unsafe impl<T> VaArgSafe for *const T {}

// Check that relevant `core::ffi` types implement `VaArgSafe`.
Expand Down Expand Up @@ -401,6 +410,7 @@ impl<'f> VaList<'f> {
///
/// [`c_void`]: core::ffi::c_void
#[inline] // Avoid codegen when not used to help backends that don't support VaList.
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn next_arg<T: VaArgSafe>(&mut self) -> T {
Expand Down
7 changes: 1 addition & 6 deletions library/std/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,7 @@ pub mod c_str;

#[stable(feature = "core_c_void", since = "1.30.0")]
pub use core::ffi::c_void;
#[unstable(
feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
all supported platforms",
issue = "44930"
)]
#[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")]
pub use core::ffi::{VaArgSafe, VaList};
#[stable(feature = "core_ffi_c", since = "1.64.0")]
pub use core::ffi::{
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@
// Only for re-exporting:
// tidy-alphabetical-start
#![feature(async_iterator)]
#![feature(c_variadic)]
#![feature(cfg_accessible)]
#![feature(cfg_eval)]
#![feature(concat_bytes)]
Expand Down
24 changes: 0 additions & 24 deletions src/doc/unstable-book/src/language-features/c-variadic.md

This file was deleted.

2 changes: 0 additions & 2 deletions src/tools/miri/tests/fail/c-variadic-ignored-argument.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(c_variadic)]

// While 1-ZST are currently ignored on most ABIs, we don't guarantee that, and it's UB to
// rely on it.

Expand Down
2 changes: 0 additions & 2 deletions src/tools/miri/tests/fail/c-variadic-mismatch-count.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(c_variadic)]

unsafe extern "C" fn helper(_: i32, _: ...) {}

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions src/tools/miri/tests/fail/c-variadic-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(c_variadic)]

unsafe extern "C" fn helper(_: i32, _: ...) {}

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions src/tools/miri/tests/fail/c-variadic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(c_variadic)]

fn read_too_many() {
unsafe extern "C" fn variadic(mut ap: ...) {
ap.next_arg::<i32>(); //~ERROR: more C-variadic arguments read than were passed
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/tests/pass/both_borrows/c_variadics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@revisions: stack tree tree_implicit_writes
//@[tree_implicit_writes]compile-flags: -Zmiri-tree-borrows -Zmiri-tree-borrows-implicit-writes
//@[tree]compile-flags: -Zmiri-tree-borrows
#![feature(c_variadic)]

fn main() {
unsafe extern "C" fn write_with_first_arg(ptr_to_val: *mut i32, _hidden_mut_ref_to_val: ...) {
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/tests/pass/c-variadic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@run-native
#![feature(c_variadic)]

use std::ffi::{CStr, VaList, c_char, c_double, c_int, c_long};

Expand Down
1 change: 0 additions & 1 deletion tests/assembly-llvm/c-variadic/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//@ ignore-android
#![no_std]
#![crate_type = "lib"]
#![feature(c_variadic)]

// Check that the assembly that rustc generates matches what clang emits. This example in particular
// is related to https://github.com/rust-lang/rust/pull/144549 and shows the effect of us correctly
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/c-variadic/avr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ revisions: AVR
//@ [AVR] compile-flags: -Copt-level=3 --target=avr-none -Ctarget-cpu=atmega328p
//@ [AVR] needs-llvm-components: avr
#![feature(c_variadic, c_variadic_experimental_arch, no_core, lang_items, intrinsics, rustc_attrs)]
#![feature(c_variadic_experimental_arch, no_core, lang_items, intrinsics, rustc_attrs)]
#![no_core]
#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/c-variadic/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//@ [MIPS] compile-flags: -Copt-level=3 --target mips-unknown-linux-gnu
//@ [MIPS64] compile-flags: -Copt-level=3 --target mipsisa64r6-unknown-linux-gnuabi64
//@ [MIPS64EL] compile-flags: -Copt-level=3 --target mips64el-unknown-linux-gnuabi64
#![feature(c_variadic, no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)]
#![feature(no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)]
#![no_core]
#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/c-variadic/sparc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//@ [SPARC] needs-llvm-components: sparc
//@ [SPARC64] compile-flags: -Copt-level=3 --target sparc64-unknown-linux-gnu
//@ [SPARC64] needs-llvm-components: sparc
#![feature(c_variadic, no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)]
#![feature(no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)]
#![cfg_attr(target_arch = "sparc", feature(c_variadic_experimental_arch))]
#![no_core]
#![crate_type = "lib"]
Expand Down
1 change: 0 additions & 1 deletion tests/codegen-llvm/c-variadic-lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ add-minicore
//@ compile-flags: -Copt-level=3
#![feature(c_variadic)]
#![crate_type = "lib"]

// Check that `%args` explicitly has its lifetime start and end. Being explicit can improve
Expand Down
1 change: 0 additions & 1 deletion tests/codegen-llvm/cffi/c-variadic-inline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -C opt-level=3
#![feature(c_variadic)]

// Test that the inline attributes are accepted on C-variadic functions.
//
Expand Down
1 change: 0 additions & 1 deletion tests/codegen-llvm/cffi/c-variadic-naked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// tests that `va_start` is not injected into naked functions

#![crate_type = "lib"]
#![feature(c_variadic)]
#![no_std]

#[unsafe(naked)]
Expand Down
1 change: 0 additions & 1 deletion tests/codegen-llvm/cffi/c-variadic-opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ ignore-bpf: BPF does not support C variadics

#![crate_type = "lib"]
#![feature(c_variadic)]
#![no_std]
use core::ffi::VaList;

Expand Down
1 change: 0 additions & 1 deletion tests/codegen-llvm/cffi/c-variadic-va_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]
#![feature(c_variadic)]
#![no_std]
use core::ffi::VaList;

Expand Down
1 change: 0 additions & 1 deletion tests/codegen-llvm/cffi/c-variadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0

#![crate_type = "lib"]
#![feature(c_variadic)]
#![no_std]
use core::ffi::VaList;

Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/inline/inline_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#![crate_type = "lib"]
#![feature(sanitize)]
#![feature(c_variadic)]

#[inline]
#[target_feature(enable = "sse2")]
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/fn-variadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See issue #58853.

//@ pp-exact
#![feature(c_variadic)]

extern "C" {
pub fn foo(x: i32, ...);
Expand Down
2 changes: 0 additions & 2 deletions tests/pretty/hir-fn-variadic.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![attr = Feature([c_variadic#0])]
extern crate std;
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir
//@ pp-exact:hir-fn-variadic.pp


extern "C" {
unsafe fn foo(x: i32, va1: ...);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/pretty/hir-fn-variadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//@ pretty-mode:hir
//@ pp-exact:hir-fn-variadic.pp

#![feature(c_variadic)]

extern "C" {
pub fn foo(x: i32, va1: ...);
}
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_type = "staticlib"]
#![feature(c_variadic)]

use core::ffi::{CStr, VaList, c_char, c_double, c_int, c_long, c_longlong};

Expand Down
1 change: 0 additions & 1 deletion tests/ui-fulldeps/rustc_public/check_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ fn generate_input(path: &str) -> std::io::Result<()> {
write!(
file,
r#"
#![feature(c_variadic)]
#![allow(unused_variables)]

use std::num::NonZero;
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/abi/variadic-ffi.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//@ run-pass
//@ ignore-backends: gcc

#![feature(c_variadic)]

use std::ffi::VaList;

#[link(name = "rust_test_helpers", kind = "static")]
Expand Down
Loading
Loading