Derive std::mem::ManuallyDrop from Clone and Copy.

Although types that don't implement Drop can't be Copyable, this can
still be useful when ManuallyDrop is used inside a generic type. This
doesn't derive from Copy as that would require T: Copy + Clone, instead
it provides an impl of Clone for T: Clone.
This commit is contained in:
Lance Roy 2017-09-03 23:27:20 -07:00
parent e22a3cf7e1
commit 6276dbd953

View file

@ -821,6 +821,7 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
/// ```
#[stable(feature = "manually_drop", since = "1.20.0")]
#[allow(unions_with_drop_fields)]
#[derive(Copy)]
pub union ManuallyDrop<T>{ value: T }
impl<T> ManuallyDrop<T> {
@ -899,6 +900,19 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> {
}
}
#[stable(feature = "manually_drop", since = "1.20.0")]
impl<T: Clone> Clone for ManuallyDrop<T> {
fn clone(&self) -> Self {
use ::ops::Deref;
ManuallyDrop::new(self.deref().clone())
}
fn clone_from(&mut self, source: &Self) {
use ::ops::DerefMut;
self.deref_mut().clone_from(source);
}
}
/// Tells LLVM that this point in the code is not reachable, enabling further
/// optimizations.
///