From 65e78db8d7b41ec40fd9b789a96df12fd3d18180 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 3 Sep 2024 11:27:34 -0700 Subject: [PATCH 1/5] Elaborate on deriving vs implementing `Copy` --- library/core/src/marker.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 5654f5aa4b8d2..91ec046eeabdd 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -288,8 +288,18 @@ marker_impls! { /// } /// ``` /// -/// There is a small difference between the two: the `derive` strategy will also place a `Copy` -/// bound on type parameters, which isn't always desired. +/// There is a small difference between the two. The `derive` strategy will also place a `Copy` +/// bound on type parameters: +/// +/// ``` +/// struct MyStruct; +/// +/// impl Copy for MyStruct { } +/// ``` +/// +/// This isn't always desired. For example, shared references (`&T`) can be copied regardless of +/// whether `T` is `Copy`. Likewise, a generic struct containing markers such as [`PhantomData`] +/// could potentially be duplicated with a bit-wise copy. /// /// ## What's the difference between `Copy` and `Clone`? /// From 3626b66af05e00b7b836a620e0d5236a64f3a89b Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 3 Sep 2024 11:43:03 -0700 Subject: [PATCH 2/5] Update marker.rs --- library/core/src/marker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 91ec046eeabdd..dfc988c885e25 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -299,7 +299,7 @@ marker_impls! { /// /// This isn't always desired. For example, shared references (`&T`) can be copied regardless of /// whether `T` is `Copy`. Likewise, a generic struct containing markers such as [`PhantomData`] -/// could potentially be duplicated with a bit-wise copy. +/// could potentially be duplicated with a bit-wise copy. /// /// ## What's the difference between `Copy` and `Clone`? /// From efc20deb57b142af1a0ce59af9d60479bef5b902 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 3 Sep 2024 12:18:46 -0700 Subject: [PATCH 3/5] Update marker.rs --- library/core/src/marker.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index dfc988c885e25..62f35c1bfa2a6 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -292,9 +292,10 @@ marker_impls! { /// bound on type parameters: /// /// ``` +/// #[derive(Clone)] /// struct MyStruct; /// -/// impl Copy for MyStruct { } +/// impl Copy for MyStruct { } /// ``` /// /// This isn't always desired. For example, shared references (`&T`) can be copied regardless of From 277a08c7d800880863a1386e19379efb98ca3f07 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 3 Sep 2024 12:20:36 -0700 Subject: [PATCH 4/5] Update marker.rs --- library/core/src/marker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 62f35c1bfa2a6..a13cef26dee07 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -293,7 +293,7 @@ marker_impls! { /// /// ``` /// #[derive(Clone)] -/// struct MyStruct; +/// struct MyStruct(T); /// /// impl Copy for MyStruct { } /// ``` From e45b53efc0ef0f86df82918720cfae78e295e3ac Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 3 Sep 2024 12:29:23 -0700 Subject: [PATCH 5/5] Update marker.rs --- library/core/src/marker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index a13cef26dee07..d9f197d9510ef 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -295,7 +295,7 @@ marker_impls! { /// #[derive(Clone)] /// struct MyStruct(T); /// -/// impl Copy for MyStruct { } +/// impl Copy for MyStruct { } /// ``` /// /// This isn't always desired. For example, shared references (`&T`) can be copied regardless of