Skip to content

Commit 544074e

Browse files
committed
Rollup merge of #33420 - durka:patch-20, r=alexcrichton
implement RFC 1521 Adds documentation to Clone, specifying that Copy types should have a trivial Clone impl. Fixes #33416. I tried to use "should" and "must" as defined [here](https://tools.ietf.org/html/rfc2119). cc @ubsan
2 parents deb97fe + c5aa879 commit 544074e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libcore/clone.rs

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ use marker::Sized;
4949
/// A common trait for cloning an object.
5050
///
5151
/// This trait can be used with `#[derive]`.
52+
///
53+
/// Types that are `Copy` should have a trivial implementation of `Clone`. More formally:
54+
/// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`.
55+
/// Manual implementations should be careful to uphold this invariant; however, unsafe code
56+
/// must not rely on it to ensure memory safety.
5257
#[stable(feature = "rust1", since = "1.0.0")]
5358
pub trait Clone : Sized {
5459
/// Returns a copy of the value.

0 commit comments

Comments
 (0)