Skip to content

Commit 6276dbd

Browse files
committed
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.
1 parent e22a3cf commit 6276dbd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcore/mem.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
821821
/// ```
822822
#[stable(feature = "manually_drop", since = "1.20.0")]
823823
#[allow(unions_with_drop_fields)]
824+
#[derive(Copy)]
824825
pub union ManuallyDrop<T>{ value: T }
825826

826827
impl<T> ManuallyDrop<T> {
@@ -899,6 +900,19 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> {
899900
}
900901
}
901902

903+
#[stable(feature = "manually_drop", since = "1.20.0")]
904+
impl<T: Clone> Clone for ManuallyDrop<T> {
905+
fn clone(&self) -> Self {
906+
use ::ops::Deref;
907+
ManuallyDrop::new(self.deref().clone())
908+
}
909+
910+
fn clone_from(&mut self, source: &Self) {
911+
use ::ops::DerefMut;
912+
self.deref_mut().clone_from(source);
913+
}
914+
}
915+
902916
/// Tells LLVM that this point in the code is not reachable, enabling further
903917
/// optimizations.
904918
///

0 commit comments

Comments
 (0)