make Va::arg and VaList::drop const fns

This commit is contained in:
Folkert de Vries 2026-01-02 16:02:28 +01:00
parent a7888c1342
commit ce693807f6
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 18 additions and 4 deletions

View file

@ -216,7 +216,8 @@ impl Clone for VaList<'_> {
}
}
impl<'f> Drop for VaList<'f> {
#[rustc_const_unstable(feature = "c_variadic_const", issue = "none")]
impl<'f> const Drop for VaList<'f> {
fn drop(&mut self) {
// SAFETY: this variable argument list is being dropped, so won't be read from again.
unsafe { va_end(self) }
@ -291,7 +292,8 @@ impl<'f> VaList<'f> {
///
/// [valid]: https://doc.rust-lang.org/nightly/nomicon/what-unsafe-does.html
#[inline]
pub unsafe fn arg<T: VaArgSafe>(&mut self) -> T {
#[rustc_const_unstable(feature = "c_variadic_const", issue = "none")]
pub const unsafe fn arg<T: VaArgSafe>(&mut self) -> T {
// SAFETY: the caller must uphold the safety contract for `va_arg`.
unsafe { va_arg(self) }
}

View file

@ -3472,7 +3472,7 @@ pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize
///
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaList<'_>) -> T;
pub const unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaList<'_>) -> T;
/// Duplicates a variable argument list. The returned list is initially at the same position as
/// the one in `src`, but can be advanced independently.
@ -3503,6 +3503,6 @@ pub fn va_copy<'f>(src: &VaList<'f>) -> VaList<'f> {
///
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn va_end(ap: &mut VaList<'_>) {
pub const unsafe fn va_end(ap: &mut VaList<'_>) {
/* deliberately does nothing */
}

View file

@ -217,6 +217,10 @@ LL | const unsafe extern "C" fn f4_1(x: isize, _: ...) {}
| ^ - value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
|
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
= help: add `#![feature(const_destruct)]` 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[E0493]: destructor of `VaList<'_>` cannot be evaluated at compile-time
--> $DIR/variadic-ffi-semantic-restrictions.rs:36:36
@ -225,6 +229,10 @@ LL | const extern "C" fn f4_2(x: isize, _: ...) {}
| ^ - value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
|
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
= help: add `#![feature(const_destruct)]` 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[E0493]: destructor of `VaList<'_>` cannot be evaluated at compile-time
--> $DIR/variadic-ffi-semantic-restrictions.rs:62:29
@ -233,6 +241,10 @@ LL | const fn i_f5(x: isize, _: ...) {}
| ^ - value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
|
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
= help: add `#![feature(const_destruct)]` 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: aborting due to 29 previous errors