Better compiler error message for types implementing trait when multiple types are effectively the same
Interesting. Looks like it's a special undocumented attribute.
Serde:
#[cfg_attr(docsrs, doc(fake_variadic))]
#[cfg_attr(
docsrs,
doc = "This trait is implemented for tuples up to 16 items long."
)]
impl<T> Serialize for (T,)
where
T: Serialize,
{
tuple_impl_body!(1 => (0));
}
Discussion on Bevy talking about this:
github.com/bevyengine/bevy
#### Consider using `fake_variadic` to improve docs
opened 07:56PM - 10 Aug 24 UTC
closed 07:10PM - 12 Aug 24 UTC
janhohenheim
C-Docs S-Ready-For-Implementation A-Cross-Cutting X-Contentious D-Straightforward
## How can Bevy's documentation be improved? `fake_variadic` allows docs on `…docs.rs` to pretend they use variadics to hide tuple implementation spam. It requires `#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]` on `lib.rs`. This is an secret, undocumented internal feature for the standard library, as far as I know. *Buuuuuut* there is a precedent of popular crates using it... namely serde! See https://docs.rs/serde/latest/src/serde/de/impls.rs.html#1480-1509 for a usage example and https://docs.rs/serde/latest/serde/trait.Deserialize.html#impl-Deserialize%3C'de%3E-for-(T,) for how it is rendered: <img width="961" alt="image" src="https://github.com/user-attachments/assets/a8d1f518-8b82-457b-86a6-7f41ca91fe8a"> The exact usage is: - Use the following annotation for the first impl: ```rust #[cfg_attr(docsrs, doc(fake_variadic))] #[cfg_attr( docsrs, doc = "This trait is implemented for tuples up to 16 items long." )] ``` - use `#[cfg_attr(docsrs, doc(hidden))]` on the other impls