docs: clean up trait docs for tuples

This commit is contained in:
Michael Howell 2022-06-07 11:23:06 -07:00
parent 7fe2c4b00d
commit 9940ed0805
3 changed files with 131 additions and 71 deletions

View File

@ -2313,6 +2313,8 @@ macro_rules! peel {
macro_rules! tuple {
() => ();
( $($name:ident,)+ ) => (
maybe_tuple_doc! {
$($name)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($name:Debug),+> Debug for ($($name,)+) where last_type!($($name,)+): ?Sized {
#[allow(non_snake_case, unused_assignments)]
@ -2326,10 +2328,24 @@ macro_rules! tuple {
builder.finish()
}
}
}
peel! { $($name,)+ }
)
}
macro_rules! maybe_tuple_doc {
($a:ident @ #[$meta:meta] $item:item) => {
#[doc = "This trait is implemented for tuples up to twelve items long."]
#[$meta]
$item
};
($a:ident $($rest_a:ident)+ @ #[$meta:meta] $item:item) => {
#[doc(hidden)]
#[$meta]
$item
};
}
macro_rules! last_type {
($a:ident,) => { $a };
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };

View File

@ -883,6 +883,8 @@ mod impls {
);
( $($name:ident)+) => (
maybe_tuple_doc! {
$($name)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
#[allow(non_snake_case)]
@ -892,9 +894,23 @@ mod impls {
$($name.hash(state);)+
}
}
}
);
}
macro_rules! maybe_tuple_doc {
($a:ident @ #[$meta:meta] $item:item) => {
#[doc = "This trait is implemented for tuples up to twelve items long."]
#[$meta]
$item
};
($a:ident $($rest_a:ident)+ @ #[$meta:meta] $item:item) => {
#[doc(hidden)]
#[$meta]
$item
};
}
macro_rules! last_type {
($a:ident,) => { $a };
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };

View File

@ -19,6 +19,8 @@ macro_rules! tuple_impls {
};
// "Private" internal implementation
(@impl $( $T:ident )+) => {
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialEq),+> PartialEq for ($($T,)+)
where
@ -33,13 +35,19 @@ macro_rules! tuple_impls {
$( ${ignore(T)} self.${index()} != other.${index()} )||+
}
}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Eq),+> Eq for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
where
@ -66,7 +74,10 @@ macro_rules! tuple_impls {
lexical_ord!(gt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
}
}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Ord),+> Ord for ($($T,)+)
where
@ -77,7 +88,10 @@ macro_rules! tuple_impls {
lexical_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
}
}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Default),+> Default for ($($T,)+) {
#[inline]
@ -87,6 +101,20 @@ macro_rules! tuple_impls {
}
}
}
}
macro_rules! maybe_tuple_doc {
($a:ident @ #[$meta:meta] $item:item) => {
#[doc = "This trait is implemented for tuples up to twelve items long."]
#[$meta]
$item
};
($a:ident $($rest_a:ident)+ @ #[$meta:meta] $item:item) => {
#[doc(hidden)]
#[$meta]
$item
};
}
// Constructs an expression that performs a lexical ordering using method $rel.
// The values are interleaved, so the macro invocation for