From c5aa8794908425a36e71e9628a23c5d15f66c65e Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Wed, 4 May 2016 22:09:51 -0400 Subject: [PATCH] implement RFC 1521 Adds documentation to Clone, specifying that Copy types should have a trivial Clone impl. Fixes #33416. --- src/libcore/clone.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index ad2a205a82376..e8ea993c6940a 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -49,6 +49,11 @@ use marker::Sized; /// A common trait for cloning an object. /// /// This trait can be used with `#[derive]`. +/// +/// Types that are `Copy` should have a trivial implementation of `Clone`. More formally: +/// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`. +/// Manual implementations should be careful to uphold this invariant; however, unsafe code +/// must not rely on it to ensure memory safety. #[stable(feature = "rust1", since = "1.0.0")] pub trait Clone : Sized { /// Returns a copy of the value.