Skip to content

Commit 39ae65b

Browse files
authored
Rollup merge of rust-lang#146925 - DiuDiu777:va-doc-fix, r=tgross35
Add doc for va_list APIs I observed that [PR146521](rust-lang#146521) submitted two weeks ago resolved some documentation issues related to `VaListImpl`, similar to the previous [PR136969](rust-lang#136969). This PR specifically adds requirements about argument availability for `VaListImpl::arg`, and also adds safety descriptions to the three associated intrinsic APIs.
2 parents d2f8873 + 0d6a313 commit 39ae65b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

library/core/src/ffi/va_list.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ impl<'f> VaListImpl<'f> {
243243
///
244244
/// # Safety
245245
///
246-
/// This function is only sound to call when the next variable argument:
246+
/// This function is only sound to call when:
247247
///
248-
/// - has a type that is ABI-compatible with the type `T`
249-
/// - has a value that is a properly initialized value of type `T`
248+
/// - there is a next variable argument available.
249+
/// - the next argument's type must be ABI-compatible with the type `T`.
250+
/// - the next argument must have a properly initialized value of type `T`.
250251
///
251252
/// Calling this function with an incompatible type, an invalid value, or when there
252253
/// are no more variable arguments, is unsound.

library/core/src/intrinsics/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,22 +3350,41 @@ pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize
33503350

33513351
/// Copies the current location of arglist `src` to the arglist `dst`.
33523352
///
3353-
/// FIXME: document safety requirements
3353+
/// # Safety
3354+
///
3355+
/// You must check the following invariants before you call this function:
3356+
///
3357+
/// - `dest` must be non-null and point to valid, writable memory.
3358+
/// - `dest` must not alias `src`.
3359+
///
33543360
#[rustc_intrinsic]
33553361
#[rustc_nounwind]
33563362
pub unsafe fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
33573363

33583364
/// Loads an argument of type `T` from the `va_list` `ap` and increment the
33593365
/// argument `ap` points to.
33603366
///
3361-
/// FIXME: document safety requirements
3367+
/// # Safety
3368+
///
3369+
/// This function is only sound to call when:
3370+
///
3371+
/// - there is a next variable argument available.
3372+
/// - the next argument's type must be ABI-compatible with the type `T`.
3373+
/// - the next argument must have a properly initialized value of type `T`.
3374+
///
3375+
/// Calling this function with an incompatible type, an invalid value, or when there
3376+
/// are no more variable arguments, is unsound.
3377+
///
33623378
#[rustc_intrinsic]
33633379
#[rustc_nounwind]
33643380
pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
33653381

33663382
/// Destroy the arglist `ap` after initialization with `va_start` or `va_copy`.
33673383
///
3368-
/// FIXME: document safety requirements
3384+
/// # Safety
3385+
///
3386+
/// `ap` must not be used to access variable arguments after this call.
3387+
///
33693388
#[rustc_intrinsic]
33703389
#[rustc_nounwind]
33713390
pub unsafe fn va_end(ap: &mut VaListImpl<'_>);

0 commit comments

Comments
 (0)