about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2024-09-03 11:27:34 -0700
committerGitHub <noreply@github.com>2024-09-03 11:27:34 -0700
commit65e78db8d7b41ec40fd9b789a96df12fd3d18180 (patch)
tree9889b3da427878c08d0619502ab4aa415013a41a
parentd6c8169c186ab16a3404cd0d0866674018e8a19e (diff)
downloadrust-65e78db8d7b41ec40fd9b789a96df12fd3d18180.tar.gz
rust-65e78db8d7b41ec40fd9b789a96df12fd3d18180.zip
Elaborate on deriving vs implementing `Copy`
-rw-r--r--library/core/src/marker.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs
index 5654f5aa4b8..91ec046eeab 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<T>;
+///
+/// impl<T: Copy> Copy for MyStruct<T> { }
+/// ```
+///
+/// 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`?
 ///