From 7a935670055d87e17c381542f4eaab481e8bf17b Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 7 Jun 2022 12:12:49 -0700 Subject: [PATCH] docs: show Clone and Copy on () doc pages --- library/core/src/clone.rs | 1 - library/core/src/marker.rs | 1 - library/core/src/primitive_docs.rs | 34 ++++++++++++++++++++++++++++++ library/std/src/primitive_docs.rs | 34 ++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/library/core/src/clone.rs b/library/core/src/clone.rs index 70f3fe853d9..fd5624812f5 100644 --- a/library/core/src/clone.rs +++ b/library/core/src/clone.rs @@ -95,7 +95,6 @@ use crate::marker::Destruct; /// /// * Function item types (i.e., the distinct types defined for each function) /// * Function pointer types (e.g., `fn() -> i32`) -/// * Tuple types, if each component also implements `Clone` (e.g., `()`, `(i32, bool)`) /// * Closure types, if they capture no value from the environment /// or if all such captured values implement `Clone` themselves. /// Note that variables captured by shared reference always implement `Clone` diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 4a90ef9545d..2c57897956f 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -359,7 +359,6 @@ pub trait StructuralEq { /// /// * Function item types (i.e., the distinct types defined for each function) /// * Function pointer types (e.g., `fn() -> i32`) -/// * Tuple types, if each component also implements `Copy` (e.g., `()`, `(i32, bool)`) /// * Closure types, if they capture no value from the environment /// or if all such captured values implement `Copy` themselves. /// Note that variables captured by shared reference always implement `Copy` diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index 06e2a0eb2de..db2f7ec0e0e 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -444,6 +444,22 @@ mod prim_unit {} #[doc(hidden)] impl () {} +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for () { + fn clone(&self) -> Self { + loop {} + } +} + +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +impl Copy for () { + // empty +} + #[doc(primitive = "pointer")] #[doc(alias = "ptr")] #[doc(alias = "*")] @@ -959,6 +975,24 @@ mod prim_tuple {} #[doc(hidden)] impl (T, U) {} +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +/// This trait is implemented on arbitrary-length tuples. +impl Clone for (T,) { + fn clone(&self) -> Self { + loop {} + } +} + +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +/// This trait is implemented on arbitrary-length tuples. +impl Copy for (T,) { + // empty +} + #[doc(primitive = "f32")] /// A 32-bit floating point type (specifically, the "binary32" type defined in IEEE 754-2008). /// diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 06e2a0eb2de..db2f7ec0e0e 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -444,6 +444,22 @@ mod prim_unit {} #[doc(hidden)] impl () {} +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for () { + fn clone(&self) -> Self { + loop {} + } +} + +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +impl Copy for () { + // empty +} + #[doc(primitive = "pointer")] #[doc(alias = "ptr")] #[doc(alias = "*")] @@ -959,6 +975,24 @@ mod prim_tuple {} #[doc(hidden)] impl (T, U) {} +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +/// This trait is implemented on arbitrary-length tuples. +impl Clone for (T,) { + fn clone(&self) -> Self { + loop {} + } +} + +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[stable(feature = "rust1", since = "1.0.0")] +/// This trait is implemented on arbitrary-length tuples. +impl Copy for (T,) { + // empty +} + #[doc(primitive = "f32")] /// A 32-bit floating point type (specifically, the "binary32" type defined in IEEE 754-2008). ///