Skip to content

Commit b3d2346

Browse files
committed
unsized ManuallyDrop
1 parent 88e0ff1 commit b3d2346

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/libcore/mem.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
956956
#[stable(feature = "manually_drop", since = "1.20.0")]
957957
#[lang = "manually_drop"]
958958
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
959-
pub struct ManuallyDrop<T> {
959+
pub struct ManuallyDrop<T: ?Sized> {
960960
value: T,
961961
}
962962

@@ -990,7 +990,9 @@ impl<T> ManuallyDrop<T> {
990990
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
991991
slot.value
992992
}
993+
}
993994

995+
impl<T: ?Sized> ManuallyDrop<T> {
994996
/// Manually drops the contained value.
995997
///
996998
/// # Safety
@@ -1006,7 +1008,7 @@ impl<T> ManuallyDrop<T> {
10061008
}
10071009

10081010
#[stable(feature = "manually_drop", since = "1.20.0")]
1009-
impl<T> Deref for ManuallyDrop<T> {
1011+
impl<T: ?Sized> Deref for ManuallyDrop<T> {
10101012
type Target = T;
10111013
#[inline]
10121014
fn deref(&self) -> &Self::Target {
@@ -1015,13 +1017,16 @@ impl<T> Deref for ManuallyDrop<T> {
10151017
}
10161018

10171019
#[stable(feature = "manually_drop", since = "1.20.0")]
1018-
impl<T> DerefMut for ManuallyDrop<T> {
1020+
impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
10191021
#[inline]
10201022
fn deref_mut(&mut self) -> &mut Self::Target {
10211023
&mut self.value
10221024
}
10231025
}
10241026

1027+
#[unstable(feature = "coerce_unsized", issue = "27732")]
1028+
impl<T: CoerceUnsized<U>, U> CoerceUnsized<ManuallyDrop<U>> for ManuallyDrop<T> {}
1029+
10251030
/// A pinned reference.
10261031
///
10271032
/// A pinned reference is a lot like a mutable reference, except that it is not

src/libcore/tests/manually_drop.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ fn smoke() {
2121

2222
let x = ManuallyDrop::new(TypeWithDrop);
2323
drop(x);
24+
25+
// also test unsizing
26+
let x : Box<ManuallyDrop<[TypeWithDrop]>> = Box::new(ManuallyDrop::new([TypeWithDrop]));
27+
drop(x);
2428
}

0 commit comments

Comments
 (0)