Skip to content

Commit f151fb8

Browse files
committed
add doc for va_list APIs
1 parent f6092f2 commit f151fb8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

library/core/src/ffi/va_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ impl<'f> VaListImpl<'f> {
247247
///
248248
/// - has a type that is ABI-compatible with the type `T`
249249
/// - has a value that is a properly initialized value of type `T`
250+
/// - is available (i.e., the number of arguments already read from `ap` is less than the total number passed)
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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,22 +3295,40 @@ pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize
32953295

32963296
/// Copies the current location of arglist `src` to the arglist `dst`.
32973297
///
3298-
/// FIXME: document safety requirements
3298+
/// # Safety
3299+
///
3300+
/// You must check the following invariants before you call this function:
3301+
///
3302+
/// - `dest` must be non-null and point to valid, writable memory.
3303+
/// - `dest` must not alias `src`;
3304+
///
32993305
#[rustc_intrinsic]
33003306
#[rustc_nounwind]
33013307
pub unsafe fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
33023308

33033309
/// Loads an argument of type `T` from the `va_list` `ap` and increment the
33043310
/// argument `ap` points to.
33053311
///
3306-
/// FIXME: document safety requirements
3312+
/// # Safety
3313+
///
3314+
/// This function is only sound to call when the next variable argument:
3315+
///
3316+
/// - has a type that is ABI-compatible with the type `T`
3317+
/// - has a value that is a properly initialized value of type `T`
3318+
/// - is available (i.e., the number of arguments already read from `ap` is less than the total number passed)
3319+
///
33073320
#[rustc_intrinsic]
33083321
#[rustc_nounwind]
33093322
pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
33103323

33113324
/// Destroy the arglist `ap` after initialization with `va_start` or `va_copy`.
33123325
///
3313-
/// FIXME: document safety requirements
3326+
/// # Safety
3327+
///
3328+
/// You must check the following invariants before you call this function:
3329+
///
3330+
/// - `ap` must not be used to access variable arguments after this call
3331+
///
33143332
#[rustc_intrinsic]
33153333
#[rustc_nounwind]
33163334
pub unsafe fn va_end(ap: &mut VaListImpl<'_>);

0 commit comments

Comments
 (0)