diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index ec7d366c3f5ce..f7f58a02437c5 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1512,6 +1512,19 @@ impl UnsafeCell { } } +#[stable(feature = "unsafe_cell_copy_clone_conservative", since = "1.31.0")] +impl Clone for UnsafeCell { + fn clone(&self) -> UnsafeCell { + // NOTE: we are explicitly not calling `.clone()` here, to enforce the + // use of Copy, rather than relying on what could be a custom impl + // of Clone + UnsafeCell::new(self.value) + } +} + +#[stable(feature = "unsafe_cell_copy_clone_conservative", since = "1.31.0")] +impl Copy for UnsafeCell {} + #[stable(feature = "unsafe_cell_default", since = "1.10.0")] impl Default for UnsafeCell { /// Creates an `UnsafeCell`, with the `Default` value for T.