]> git.lizzy.rs Git - rust.git/commitdiff
docs: clean up trait docs for tuples
authorMichael Howell <michael@notriddle.com>
Tue, 7 Jun 2022 18:23:06 +0000 (11:23 -0700)
committerMichael Howell <michael@notriddle.com>
Tue, 7 Jun 2022 18:24:57 +0000 (11:24 -0700)
library/core/src/fmt/mod.rs
library/core/src/hash/mod.rs
library/core/src/tuple.rs

index 63655ae8a240b70790d0478cdc857c92e617c47d..46b2b0c92bf7a5a8ae639cf28d701e4eca318cdb 100644 (file)
@@ -2313,23 +2313,39 @@ macro_rules! peel {
 macro_rules! tuple {
     () => ();
     ( $($name:ident,)+ ) => (
-        #[stable(feature = "rust1", since = "1.0.0")]
-        impl<$($name:Debug),+> Debug for ($($name,)+) where last_type!($($name,)+): ?Sized {
-            #[allow(non_snake_case, unused_assignments)]
-            fn fmt(&self, f: &mut Formatter<'_>) -> Result {
-                let mut builder = f.debug_tuple("");
-                let ($(ref $name,)+) = *self;
-                $(
-                    builder.field(&$name);
-                )+
-
-                builder.finish()
+        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)]
+                fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+                    let mut builder = f.debug_tuple("");
+                    let ($(ref $name,)+) = *self;
+                    $(
+                        builder.field(&$name);
+                    )+
+
+                    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,)+) };
index 3d168f62a09f5ff7e2b5e9e566c598343b0f64e6..ae3799d2a963cacd0b3509473d8f639a3bca4ad1 100644 (file)
@@ -883,18 +883,34 @@ fn hash<H: Hasher>(&self, _state: &mut H) {}
         );
 
         ( $($name:ident)+) => (
-            #[stable(feature = "rust1", since = "1.0.0")]
-            impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
-                #[allow(non_snake_case)]
-                #[inline]
-                fn hash<S: Hasher>(&self, state: &mut S) {
-                    let ($(ref $name,)+) = *self;
-                    $($name.hash(state);)+
+            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)]
+                    #[inline]
+                    fn hash<S: Hasher>(&self, state: &mut S) {
+                        let ($(ref $name,)+) = *self;
+                        $($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,)+) };
index 181717f35bd25dd3de4f763b032a624f349b5108..61fa0eea78a731629ada3350c7443a79e589aafd 100644 (file)
@@ -19,75 +19,103 @@ macro_rules! tuple_impls {
     };
     // "Private" internal implementation
     (@impl $( $T:ident )+) => {
-        #[stable(feature = "rust1", since = "1.0.0")]
-        impl<$($T:PartialEq),+> PartialEq for ($($T,)+)
-        where
-            last_type!($($T,)+): ?Sized
-        {
-            #[inline]
-            fn eq(&self, other: &($($T,)+)) -> bool {
-                $( ${ignore(T)} self.${index()} == other.${index()} )&&+
-            }
-            #[inline]
-            fn ne(&self, other: &($($T,)+)) -> bool {
-                $( ${ignore(T)} self.${index()} != other.${index()} )||+
+        maybe_tuple_doc! {
+            $($T)+ @
+            #[stable(feature = "rust1", since = "1.0.0")]
+            impl<$($T:PartialEq),+> PartialEq for ($($T,)+)
+            where
+                last_type!($($T,)+): ?Sized
+            {
+                #[inline]
+                fn eq(&self, other: &($($T,)+)) -> bool {
+                    $( ${ignore(T)} self.${index()} == other.${index()} )&&+
+                }
+                #[inline]
+                fn ne(&self, other: &($($T,)+)) -> bool {
+                    $( ${ignore(T)} self.${index()} != other.${index()} )||+
+                }
             }
         }
 
-        #[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:Eq),+> Eq for ($($T,)+)
+            where
+                last_type!($($T,)+): ?Sized
+            {}
+        }
 
-        #[stable(feature = "rust1", since = "1.0.0")]
-        impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
-        where
-            last_type!($($T,)+): ?Sized
-        {
-            #[inline]
-            fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
-                lexical_partial_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
-            }
-            #[inline]
-            fn lt(&self, other: &($($T,)+)) -> bool {
-                lexical_ord!(lt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
-            }
-            #[inline]
-            fn le(&self, other: &($($T,)+)) -> bool {
-                lexical_ord!(le, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
-            }
-            #[inline]
-            fn ge(&self, other: &($($T,)+)) -> bool {
-                lexical_ord!(ge, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
-            }
-            #[inline]
-            fn gt(&self, other: &($($T,)+)) -> bool {
-                lexical_ord!(gt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
+        maybe_tuple_doc! {
+            $($T)+ @
+            #[stable(feature = "rust1", since = "1.0.0")]
+            impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
+            where
+                last_type!($($T,)+): ?Sized
+            {
+                #[inline]
+                fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
+                    lexical_partial_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
+                }
+                #[inline]
+                fn lt(&self, other: &($($T,)+)) -> bool {
+                    lexical_ord!(lt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
+                }
+                #[inline]
+                fn le(&self, other: &($($T,)+)) -> bool {
+                    lexical_ord!(le, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
+                }
+                #[inline]
+                fn ge(&self, other: &($($T,)+)) -> bool {
+                    lexical_ord!(ge, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
+                }
+                #[inline]
+                fn gt(&self, other: &($($T,)+)) -> bool {
+                    lexical_ord!(gt, $( ${ignore(T)} self.${index()}, other.${index()} ),+)
+                }
             }
         }
 
-        #[stable(feature = "rust1", since = "1.0.0")]
-        impl<$($T:Ord),+> Ord for ($($T,)+)
-        where
-            last_type!($($T,)+): ?Sized
-        {
-            #[inline]
-            fn cmp(&self, other: &($($T,)+)) -> Ordering {
-                lexical_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
+        maybe_tuple_doc! {
+            $($T)+ @
+            #[stable(feature = "rust1", since = "1.0.0")]
+            impl<$($T:Ord),+> Ord for ($($T,)+)
+            where
+                last_type!($($T,)+): ?Sized
+            {
+                #[inline]
+                fn cmp(&self, other: &($($T,)+)) -> Ordering {
+                    lexical_cmp!($( ${ignore(T)} self.${index()}, other.${index()} ),+)
+                }
             }
         }
 
-        #[stable(feature = "rust1", since = "1.0.0")]
-        impl<$($T:Default),+> Default for ($($T,)+) {
-            #[inline]
-            fn default() -> ($($T,)+) {
-                ($({ let x: $T = Default::default(); x},)+)
+        maybe_tuple_doc! {
+            $($T)+ @
+            #[stable(feature = "rust1", since = "1.0.0")]
+            impl<$($T:Default),+> Default for ($($T,)+) {
+                #[inline]
+                fn default() -> ($($T,)+) {
+                    ($({ let x: $T = Default::default(); x},)+)
+                }
             }
         }
     }
 }
 
+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
 // `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, a1, b1, a2, b2,