diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 8a74e7c6f1cc6..ea711c69393a4 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -956,7 +956,8 @@ pub fn discriminant(v: &T) -> Discriminant { #[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ManuallyDrop { +#[repr(transparent)] +pub struct ManuallyDrop { value: T, } @@ -990,7 +991,9 @@ impl ManuallyDrop { pub fn into_inner(slot: ManuallyDrop) -> T { slot.value } +} +impl ManuallyDrop { /// Manually drops the contained value. /// /// # Safety @@ -1006,7 +1009,7 @@ impl ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl Deref for ManuallyDrop { +impl Deref for ManuallyDrop { type Target = T; #[inline] fn deref(&self) -> &Self::Target { @@ -1015,7 +1018,7 @@ impl Deref for ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl DerefMut for ManuallyDrop { +impl DerefMut for ManuallyDrop { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.value diff --git a/src/libcore/tests/manually_drop.rs b/src/libcore/tests/manually_drop.rs index 96bc9247da6e7..82dfb8d4c0b2a 100644 --- a/src/libcore/tests/manually_drop.rs +++ b/src/libcore/tests/manually_drop.rs @@ -21,4 +21,9 @@ fn smoke() { let x = ManuallyDrop::new(TypeWithDrop); drop(x); + + // also test unsizing + let x : Box> = + Box::new(ManuallyDrop::new([TypeWithDrop, TypeWithDrop])); + drop(x); }