Skip to content

Commit 530c4eb

Browse files
committed
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, gated behind `USE_RUSTC_FEATURES`, and can be removed at any time. This feature is already used by serde and bevy to improve documentation quality. For compilers that cannot use this feature, we still hide most generated impls, and the existence of them are hinted by doc comments on the single non-hidden impl. Signed-off-by: Gary Guo <gary@garyguo.net>
1 parent a188482 commit 530c4eb

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
@@ -276,6 +276,8 @@
276276
all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED),
277277
feature(unsafe_pinned)
278278
)]
279+
#![cfg_attr(all(USE_RUSTC_FEATURES, doc), allow(internal_features))]
280+
#![cfg_attr(all(USE_RUSTC_FEATURES, doc), feature(rustdoc_internals))]
279281

280282
use core::{
281283
cell::UnsafeCell,
@@ -1638,9 +1640,15 @@ impl_zeroable! {
16381640
}
16391641

16401642
macro_rules! impl_tuple_zeroable {
1641-
($(,)?) => {};
1643+
($first:ident, $(,)?) => {
1644+
#[cfg_attr(all(USE_RUSTC_FEATURES, doc), doc(fake_variadic))]
1645+
/// Implemented for tuples up to 10 items long.
1646+
// SAFETY: All elements are zeroable and padding can be zero.
1647+
unsafe impl<$first: Zeroable> Zeroable for ($first,) {}
1648+
};
16421649
($first:ident, $($t:ident),* $(,)?) => {
16431650
// SAFETY: All elements are zeroable and padding can be zero.
1651+
#[cfg_attr(doc, doc(hidden))]
16441652
unsafe impl<$first: Zeroable, $($t: Zeroable),*> Zeroable for ($first, $($t),*) {}
16451653
impl_tuple_zeroable!($($t),* ,);
16461654
}
@@ -1654,9 +1662,18 @@ macro_rules! impl_fn_zeroable_option {
16541662
$(impl_fn_zeroable_option!({unsafe extern $abi} $args);)*
16551663
};
16561664
({$($prefix:tt)*} {$(,)?}) => {};
1665+
({$($prefix:tt)*} {$ret:ident, $arg:ident $(,)?}) => {
1666+
#[cfg_attr(all(USE_RUSTC_FEATURES, doc), doc(fake_variadic))]
1667+
/// Implemented for function pointers with up to 20 arity.
1668+
// SAFETY: function pointers are part of the option layout optimization:
1669+
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
1670+
unsafe impl<$ret, $arg> ZeroableOption for $($prefix)* fn($arg) -> $ret {}
1671+
impl_fn_zeroable_option!({$($prefix)*} {$arg,});
1672+
};
16571673
({$($prefix:tt)*} {$ret:ident, $($rest:ident),* $(,)?}) => {
16581674
// SAFETY: function pointers are part of the option layout optimization:
16591675
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
1676+
#[cfg_attr(doc, doc(hidden))]
16601677
unsafe impl<$ret, $($rest),*> ZeroableOption for $($prefix)* fn($($rest),*) -> $ret {}
16611678
impl_fn_zeroable_option!({$($prefix)*} {$($rest),*,});
16621679
};

0 commit comments

Comments
 (0)