Skip to content

Commit c5aa879

Browse files
committed
implement RFC 1521
Adds documentation to Clone, specifying that Copy types should have a trivial Clone impl. Fixes rust-lang#33416.
1 parent 7a0ccc4 commit c5aa879

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)