Skip to content

Commit 1951de5

Browse files
committed
c-variadic: unseal core::ffi::VaArgSafe
And update the safety documentation
1 parent f4665ab commit 1951de5

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

library/core/src/ffi/va_list.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,36 +185,19 @@ impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> {
185185
}
186186
}
187187

188-
mod sealed {
189-
pub trait Sealed {}
190-
191-
impl Sealed for i32 {}
192-
impl Sealed for i64 {}
193-
impl Sealed for isize {}
194-
195-
impl Sealed for u32 {}
196-
impl Sealed for u64 {}
197-
impl Sealed for usize {}
198-
199-
impl Sealed for f64 {}
200-
201-
impl<T> Sealed for *mut T {}
202-
impl<T> Sealed for *const T {}
203-
}
204-
205188
/// Trait which permits the allowed types to be used with [`VaListImpl::arg`].
206189
///
207190
/// # Safety
208191
///
209-
/// This trait must only be implemented for types that C passes as varargs without implicit promotion.
192+
/// Implementing this trait asserts that the type can be soundly passed via varargs.
210193
///
211194
/// In C varargs, integers smaller than [`c_int`] and floats smaller than [`c_double`]
212195
/// are implicitly promoted to [`c_int`] and [`c_double`] respectively. Implementing this trait for
213196
/// types that are subject to this promotion rule is invalid.
214197
///
215198
/// [`c_int`]: core::ffi::c_int
216199
/// [`c_double`]: core::ffi::c_double
217-
pub unsafe trait VaArgSafe: sealed::Sealed {}
200+
pub unsafe trait VaArgSafe {}
218201

219202
// i8 and i16 are implicitly promoted to c_int in C, and cannot implement `VaArgSafe`.
220203
unsafe impl VaArgSafe for i32 {}

0 commit comments

Comments
 (0)