Skip to content

Commit e4dffec

Browse files
committed
make Va::arg and VaList::drop const fns
1 parent 954e2c0 commit e4dffec

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

library/core/src/ffi/va_list.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ impl<'f> VaList<'f> {
247247
///
248248
/// [valid]: https://doc.rust-lang.org/nightly/nomicon/what-unsafe-does.html
249249
#[inline]
250-
pub unsafe fn arg<T: VaArgSafe>(&mut self) -> T {
250+
#[rustc_const_unstable(feature = "c_variadic_const", issue = "none")]
251+
pub const unsafe fn arg<T: VaArgSafe>(&mut self) -> T {
251252
// SAFETY: the caller must uphold the safety contract for `va_arg`.
252253
unsafe { va_arg(self) }
253254
}
@@ -265,7 +266,8 @@ impl<'f> Clone for VaList<'f> {
265266
}
266267
}
267268

268-
impl<'f> Drop for VaList<'f> {
269+
#[rustc_const_unstable(feature = "c_variadic_const", issue = "none")]
270+
impl<'f> const Drop for VaList<'f> {
269271
fn drop(&mut self) {
270272
// Rust requires that not calling `va_end` on a `va_list` does not cause undefined behaviour
271273
// (as it is safe to leak values). As `va_end` is a no-op on all current LLVM targets, this

library/core/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3474,7 +3474,7 @@ pub unsafe fn va_copy<'f>(dest: *mut VaList<'f>, src: &VaList<'f>);
34743474
///
34753475
#[rustc_intrinsic]
34763476
#[rustc_nounwind]
3477-
pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaList<'_>) -> T;
3477+
pub const unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaList<'_>) -> T;
34783478

34793479
/// Destroy the arglist `ap` after initialization with `va_start` or `va_copy`.
34803480
///

tests/ui/parser/variadic-ffi-semantic-restrictions.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ LL | const unsafe extern "C" fn f4_1(x: isize, _: ...) {}
217217
| ^ - value is dropped here
218218
| |
219219
| the destructor for this type cannot be evaluated in constant functions
220+
|
221+
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
222+
= help: add `#![feature(const_destruct)]` to the crate attributes to enable
223+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
220224

221225
error[E0493]: destructor of `VaList<'_>` cannot be evaluated at compile-time
222226
--> $DIR/variadic-ffi-semantic-restrictions.rs:36:36
@@ -225,6 +229,10 @@ LL | const extern "C" fn f4_2(x: isize, _: ...) {}
225229
| ^ - value is dropped here
226230
| |
227231
| the destructor for this type cannot be evaluated in constant functions
232+
|
233+
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
234+
= help: add `#![feature(const_destruct)]` to the crate attributes to enable
235+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
228236

229237
error[E0493]: destructor of `VaList<'_>` cannot be evaluated at compile-time
230238
--> $DIR/variadic-ffi-semantic-restrictions.rs:62:29
@@ -233,6 +241,10 @@ LL | const fn i_f5(x: isize, _: ...) {}
233241
| ^ - value is dropped here
234242
| |
235243
| the destructor for this type cannot be evaluated in constant functions
244+
|
245+
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
246+
= help: add `#![feature(const_destruct)]` to the crate attributes to enable
247+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
236248

237249
error: aborting due to 29 previous errors
238250

0 commit comments

Comments
 (0)