Elaborate on deriving vs implementing Copy · patricklam/verify-rust-std@de72cd3 (original) (raw)

Original file line number Diff line number Diff line change
@@ -288,8 +288,18 @@ marker_impls! {
288 288 /// }
289 289 /// ```
290 290 ///
291 -/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
292 -/// bound on type parameters, which isn't always desired.
291 +/// There is a small difference between the two. The `derive` strategy will also place a `Copy`
292 +/// bound on type parameters:
293 +///
294 +/// ```
295 +/// struct MyStruct;
296 +///
297 +/// impl<T: Copy> Copy for MyStruct { }
298 +/// ```
299 +///
300 +/// This isn't always desired. For example, shared references (`&T`) can be copied regardless of
301 +/// whether `T` is `Copy`. Likewise, a generic struct containing markers such as [`PhantomData`]
302 +/// could potentially be duplicated with a bit-wise copy.
293 303 ///
294 304 /// ## What's the difference between `Copy` and `Clone`?
295 305 ///