Skip to content

Commit 0d6a313

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

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
@@ -3295,22 +3295,41 @@ 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:
3315+
///
3316+
/// - there is a next variable argument available.
3317+
/// - the next argument's type must be ABI-compatible with the type `T`.
3318+
/// - the next argument must have a properly initialized value of type `T`.
3319+
///
3320+
/// Calling this function with an incompatible type, an invalid value, or when there
3321+
/// are no more variable arguments, is unsound.
3322+
///
33073323
#[rustc_intrinsic]
33083324
#[rustc_nounwind]
33093325
pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
33103326

33113327
/// Destroy the arglist `ap` after initialization with `va_start` or `va_copy`.
33123328
///
3313-
/// FIXME: document safety requirements
3329+
/// # Safety
3330+
///
3331+
/// `ap` must not be used to access variable arguments after this call.
3332+
///
33143333
#[rustc_intrinsic]
33153334
#[rustc_nounwind]
33163335
pub unsafe fn va_end(ap: &mut VaListImpl<'_>);

0 commit comments

Comments
 (0)