From de72cd33be9988df5902b32c66a585d0c85d4985 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 3 Sep 2024 11:27:34 -0700 Subject: [PATCH] Elaborate on deriving vs implementing `Copy` --- core/src/marker.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/marker.rs b/core/src/marker.rs index 5654f5aa4b8d2..91ec046eeabdd 100644 --- a/core/src/marker.rs +++ b/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`? ///