diff options
| author | bors <bors@rust-lang.org> | 2019-01-01 20:50:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-01 20:50:13 +0000 |
| commit | b2b7a063af39455d7362524da3123c34c3f4842e (patch) | |
| tree | d1e48844f738b33ec821d5ec22ef21ae60256c3b /src/libcore | |
| parent | cae164753f557f668cb75610abda4f790981e5e6 (diff) | |
| parent | bbc8c932fb05dfaed7b5bfe252712bede722b764 (diff) | |
| download | rust-b2b7a063af39455d7362524da3123c34c3f4842e.tar.gz rust-b2b7a063af39455d7362524da3123c34c3f4842e.zip | |
Auto merge of #57125 - doitian:inconsistent-clone-doc, r=bluss
Fix inconsistent Clone documentation. Now, arrays of any size Clone if the element type is Clone. So remove the the document that uses this as an example. refs #57123
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/clone.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 74b3ce4f978..ed90b7de264 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -53,6 +53,17 @@ /// This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d /// implementation of [`clone`] calls [`clone`] on each field. /// +/// For a generic struct, `#[derive]` implements `Clone` conditionally by adding bound `Clone` on +/// generic parameters. +/// +/// ``` +/// // `derive` implements Clone for Reading<T> when T is Clone. +/// #[derive(Clone)] +/// struct Reading<T> { +/// frequency: T, +/// } +/// ``` +/// /// ## How can I implement `Clone`? /// /// Types that are [`Copy`] should have a trivial implementation of `Clone`. More formally: @@ -60,21 +71,21 @@ /// Manual implementations should be careful to uphold this invariant; however, unsafe code /// must not rely on it to ensure memory safety. /// -/// An example is an array holding more than 32 elements of a type that is `Clone`; the standard -/// library only implements `Clone` up until arrays of size 32. In this case, the implementation of -/// `Clone` cannot be `derive`d, but can be implemented as: +/// An example is a generic struct holding a function pointer. In this case, the +/// implementation of `Clone` cannot be `derive`d, but can be implemented as: /// /// [`Copy`]: ../../std/marker/trait.Copy.html /// [`clone`]: trait.Clone.html#tymethod.clone /// /// ``` -/// #[derive(Copy)] -/// struct Stats { -/// frequencies: [i32; 100], -/// } +/// struct Generate<T>(fn() -> T); +/// +/// impl<T> Copy for Generate<T> {} /// -/// impl Clone for Stats { -/// fn clone(&self) -> Stats { *self } +/// impl<T> Clone for Generate<T> { +/// fn clone(&self) -> Self { +/// *self +/// } /// } /// ``` /// |
