diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-03 18:02:34 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-03 18:09:20 +0200 |
| commit | b3d2346230736b253d8f2a9df461901b7de67abd (patch) | |
| tree | 99d3cec56d67d886fd59a5a6370258d796137181 /src | |
| parent | 88e0ff14a81a2122222e32cf7c285f585c516cfd (diff) | |
| download | rust-b3d2346230736b253d8f2a9df461901b7de67abd.tar.gz rust-b3d2346230736b253d8f2a9df461901b7de67abd.zip | |
unsized ManuallyDrop
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/mem.rs | 11 | ||||
| -rw-r--r-- | src/libcore/tests/manually_drop.rs | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 8a74e7c6f1c..1eec4def1bb 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -956,7 +956,7 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> { #[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ManuallyDrop<T> { +pub struct ManuallyDrop<T: ?Sized> { value: T, } @@ -990,7 +990,9 @@ impl<T> ManuallyDrop<T> { pub fn into_inner(slot: ManuallyDrop<T>) -> T { slot.value } +} +impl<T: ?Sized> ManuallyDrop<T> { /// Manually drops the contained value. /// /// # Safety @@ -1006,7 +1008,7 @@ impl<T> ManuallyDrop<T> { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl<T> Deref for ManuallyDrop<T> { +impl<T: ?Sized> Deref for ManuallyDrop<T> { type Target = T; #[inline] fn deref(&self) -> &Self::Target { @@ -1015,13 +1017,16 @@ impl<T> Deref for ManuallyDrop<T> { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl<T> DerefMut for ManuallyDrop<T> { +impl<T: ?Sized> DerefMut for ManuallyDrop<T> { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.value } } +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl<T: CoerceUnsized<U>, U> CoerceUnsized<ManuallyDrop<U>> for ManuallyDrop<T> {} + /// A pinned reference. /// /// A pinned reference is a lot like a mutable reference, except that it is not diff --git a/src/libcore/tests/manually_drop.rs b/src/libcore/tests/manually_drop.rs index 96bc9247da6..b8826ad4087 100644 --- a/src/libcore/tests/manually_drop.rs +++ b/src/libcore/tests/manually_drop.rs @@ -21,4 +21,8 @@ fn smoke() { let x = ManuallyDrop::new(TypeWithDrop); drop(x); + + // also test unsizing + let x : Box<ManuallyDrop<[TypeWithDrop]>> = Box::new(ManuallyDrop::new([TypeWithDrop])); + drop(x); } |
