Skip to content

Commit 577ea69

Browse files
committed
rustdoc: show tuple impls as impl Trait for (T, ...)
This commit adds a new unstable attribute, `#[doc(tuple_varadic)]`, that shows a 1-tuple as `(T, ...)` instead of just `(T,)`, and links to a section in the tuple primitive docs that talks about these.
1 parent 59abb1a commit 577ea69

File tree

5 files changed

+17
-36
lines changed

5 files changed

+17
-36
lines changed

core/src/fmt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,7 @@ macro_rules! tuple {
23352335

23362336
macro_rules! maybe_tuple_doc {
23372337
($a:ident @ #[$meta:meta] $item:item) => {
2338+
#[cfg_attr(not(bootstrap), doc(tuple_varadic))]
23382339
#[doc = "This trait is implemented for tuples up to twelve items long."]
23392340
#[$meta]
23402341
$item

core/src/hash/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ mod impls {
900900

901901
macro_rules! maybe_tuple_doc {
902902
($a:ident @ #[$meta:meta] $item:item) => {
903+
#[cfg_attr(not(bootstrap), doc(tuple_varadic))]
903904
#[doc = "This trait is implemented for tuples up to twelve items long."]
904905
#[$meta]
905906
$item

core/src/primitive_docs.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -916,24 +916,11 @@ mod prim_str {}
916916
///
917917
/// # Trait implementations
918918
///
919-
/// If every type inside a tuple implements one of the following traits, then a
920-
/// tuple itself also implements it.
921-
///
922-
/// * [`Clone`]
923-
/// * [`Copy`]
924-
/// * [`PartialEq`]
925-
/// * [`Eq`]
926-
/// * [`PartialOrd`]
927-
/// * [`Ord`]
928-
/// * [`Debug`]
929-
/// * [`Default`]
930-
/// * [`Hash`]
931-
///
932-
/// [`Debug`]: fmt::Debug
933-
/// [`Hash`]: hash::Hash
934-
///
935-
/// Due to a temporary restriction in Rust's type system, these traits are only
936-
/// implemented on tuples of arity 12 or less. In the future, this may change.
919+
/// In this documentation the shorthand `(T, ...)` is used to represent all
920+
/// tuples up to length twelve. When that is used, any trait bounds expressed
921+
/// on `T` applies to each field of the tuple independently. Note that this is
922+
/// a convenience notation to avoid repetitive documentation, not valid
923+
/// Rust syntax.
937924
///
938925
/// # Examples
939926
///
@@ -978,6 +965,7 @@ impl<T, U> (T, U) {}
978965
// Fake impl that's only really used for docs.
979966
#[cfg(doc)]
980967
#[stable(feature = "rust1", since = "1.0.0")]
968+
#[doc(tuple_varadic)]
981969
/// This trait is implemented on arbitrary-length tuples.
982970
impl<T: Clone> Clone for (T,) {
983971
fn clone(&self) -> Self {
@@ -988,6 +976,7 @@ impl<T: Clone> Clone for (T,) {
988976
// Fake impl that's only really used for docs.
989977
#[cfg(doc)]
990978
#[stable(feature = "rust1", since = "1.0.0")]
979+
#[doc(tuple_varadic)]
991980
/// This trait is implemented on arbitrary-length tuples.
992981
impl<T: Copy> Copy for (T,) {
993982
// empty

core/src/tuple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ macro_rules! tuple_impls {
105105

106106
macro_rules! maybe_tuple_doc {
107107
($a:ident @ #[$meta:meta] $item:item) => {
108+
#[cfg_attr(not(bootstrap), doc(tuple_varadic))]
108109
#[doc = "This trait is implemented for tuples up to twelve items long."]
109110
#[$meta]
110111
$item

std/src/primitive_docs.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -916,24 +916,11 @@ mod prim_str {}
916916
///
917917
/// # Trait implementations
918918
///
919-
/// If every type inside a tuple implements one of the following traits, then a
920-
/// tuple itself also implements it.
921-
///
922-
/// * [`Clone`]
923-
/// * [`Copy`]
924-
/// * [`PartialEq`]
925-
/// * [`Eq`]
926-
/// * [`PartialOrd`]
927-
/// * [`Ord`]
928-
/// * [`Debug`]
929-
/// * [`Default`]
930-
/// * [`Hash`]
931-
///
932-
/// [`Debug`]: fmt::Debug
933-
/// [`Hash`]: hash::Hash
934-
///
935-
/// Due to a temporary restriction in Rust's type system, these traits are only
936-
/// implemented on tuples of arity 12 or less. In the future, this may change.
919+
/// In this documentation the shorthand `(T, ...)` is used to represent all
920+
/// tuples up to length twelve. When that is used, any trait bounds expressed
921+
/// on `T` applies to each field of the tuple independently. Note that this is
922+
/// a convenience notation to avoid repetitive documentation, not valid
923+
/// Rust syntax.
937924
///
938925
/// # Examples
939926
///
@@ -978,6 +965,7 @@ impl<T, U> (T, U) {}
978965
// Fake impl that's only really used for docs.
979966
#[cfg(doc)]
980967
#[stable(feature = "rust1", since = "1.0.0")]
968+
#[doc(tuple_varadic)]
981969
/// This trait is implemented on arbitrary-length tuples.
982970
impl<T: Clone> Clone for (T,) {
983971
fn clone(&self) -> Self {
@@ -988,6 +976,7 @@ impl<T: Clone> Clone for (T,) {
988976
// Fake impl that's only really used for docs.
989977
#[cfg(doc)]
990978
#[stable(feature = "rust1", since = "1.0.0")]
979+
#[doc(tuple_varadic)]
991980
/// This trait is implemented on arbitrary-length tuples.
992981
impl<T: Copy> Copy for (T,) {
993982
// empty

0 commit comments

Comments
 (0)