Skip to content

Commit d57eb96

Browse files
nbdd0121BennoLossin
authored andcommitted
doc: de-clutter documentation with fake-variadics
Currently the doc for `Zeroable` and `ZeroableOption` are filled with the generated impl of tuples and fn pointers. Use the internal "fake_variadics" feature to improve the rendered quality. This makes use of an internal feature, however this is of minimal risk as it's for documentation only, not activated during normal build, and can be removed at any time. This feature is already used by serde and bevy to improve documentation quality. Signed-off-by: Gary Guo <gary@garyguo.net>
1 parent e7a5b50 commit d57eb96

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@
279279
all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED),
280280
feature(unsafe_pinned)
281281
)]
282+
#![cfg_attr(doc, allow(internal_features))]
283+
#![cfg_attr(doc, feature(rustdoc_internals))]
282284

283285
use core::{
284286
cell::UnsafeCell,
@@ -1635,9 +1637,15 @@ impl_zeroable! {
16351637
}
16361638

16371639
macro_rules! impl_tuple_zeroable {
1638-
($(,)?) => {};
1640+
($first:ident, $(,)?) => {
1641+
#[cfg_attr(doc, doc(fake_variadic))]
1642+
/// Implemented for tuples up to 10 items long.
1643+
// SAFETY: All elements are zeroable and padding can be zero.
1644+
unsafe impl<$first: Zeroable> Zeroable for ($first,) {}
1645+
};
16391646
($first:ident, $($t:ident),* $(,)?) => {
16401647
// SAFETY: All elements are zeroable and padding can be zero.
1648+
#[cfg_attr(doc, doc(hidden))]
16411649
unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {}
16421650
impl_tuple_zeroable!($($t),* ,);
16431651
}
@@ -1651,9 +1659,18 @@ macro_rules! impl_fn_zeroable_option {
16511659
$(impl_fn_zeroable_option!({unsafe extern $abi} $args);)*
16521660
};
16531661
({$($prefix:tt)*} {$(,)?}) => {};
1662+
({$($prefix:tt)*} {$ret:ident, $arg:ident $(,)?}) => {
1663+
#[cfg_attr(doc, doc(fake_variadic))]
1664+
/// Implemented for function pointers with up to 20 arity.
1665+
// SAFETY: function pointers are part of the option layout optimization:
1666+
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
1667+
unsafe impl<$ret, $arg> ZeroableOption for $($prefix)* fn($arg) -> $ret {}
1668+
impl_fn_zeroable_option!({$($prefix)*} {$arg,});
1669+
};
16541670
({$($prefix:tt)*} {$ret:ident, $($rest:ident),* $(,)?}) => {
16551671
// SAFETY: function pointers are part of the option layout optimization:
16561672
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
1673+
#[cfg_attr(doc, doc(hidden))]
16571674
unsafe impl<$ret, $($rest),*> ZeroableOption for $($prefix)* fn($($rest),*) -> $ret {}
16581675
impl_fn_zeroable_option!({$($prefix)*} {$($rest),*,});
16591676
};

0 commit comments

Comments
 (0)