Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@
all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED),
feature(unsafe_pinned)
)]
#![cfg_attr(doc, allow(internal_features))]
#![cfg_attr(doc, feature(rustdoc_internals))]

use core::{
cell::UnsafeCell,
Expand Down Expand Up @@ -1635,9 +1637,15 @@ impl_zeroable! {
}

macro_rules! impl_tuple_zeroable {
($(,)?) => {};
($first:ident, $(,)?) => {
#[cfg_attr(doc, doc(fake_variadic))]
/// Implemented for tuples up to 10 items long.
// SAFETY: All elements are zeroable and padding can be zero.
unsafe impl<$first: Zeroable> Zeroable for ($first,) {}
};
($first:ident, $($t:ident),* $(,)?) => {
// SAFETY: All elements are zeroable and padding can be zero.
#[cfg_attr(doc, doc(hidden))]
unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {}
impl_tuple_zeroable!($($t),* ,);
}
Expand All @@ -1651,9 +1659,18 @@ macro_rules! impl_fn_zeroable_option {
$(impl_fn_zeroable_option!({unsafe extern $abi} $args);)*
};
({$($prefix:tt)*} {$(,)?}) => {};
({$($prefix:tt)*} {$ret:ident, $arg:ident $(,)?}) => {
#[cfg_attr(doc, doc(fake_variadic))]
/// Implemented for function pointers with up to 20 arity.
// SAFETY: function pointers are part of the option layout optimization:
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
unsafe impl<$ret, $arg> ZeroableOption for $($prefix)* fn($arg) -> $ret {}
impl_fn_zeroable_option!({$($prefix)*} {$arg,});
};
({$($prefix:tt)*} {$ret:ident, $($rest:ident),* $(,)?}) => {
// SAFETY: function pointers are part of the option layout optimization:
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
#[cfg_attr(doc, doc(hidden))]
unsafe impl<$ret, $($rest),*> ZeroableOption for $($prefix)* fn($($rest),*) -> $ret {}
impl_fn_zeroable_option!({$($prefix)*} {$($rest),*,});
};
Expand Down