Skip to content

Commit

Permalink
Update union code to use ManuallyDrop
Browse files Browse the repository at this point in the history
A Rust breaking change to the untagged_unions feature, means that no
union fields may have destructors, so we need use ManuallyDrop also
around the inline union field.
  • Loading branch information
bluss committed Dec 19, 2018
1 parent e244d0a commit d6bfa84
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib.rs
Expand Up @@ -60,7 +60,6 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::iter::{IntoIterator, FromIterator, repeat};
use std::mem;
#[cfg(not(feature = "union"))]
use std::mem::ManuallyDrop;
use std::ops;
use std::ptr;
Expand Down Expand Up @@ -268,9 +267,8 @@ impl<'a, T: 'a> Drop for Drain<'a,T> {
}

#[cfg(feature = "union")]
#[allow(unions_with_drop_fields)]
union SmallVecData<A: Array> {
inline: A,
inline: ManuallyDrop<A>,
heap: (*mut A::Item, usize),
}

Expand All @@ -286,10 +284,10 @@ impl<A: Array> SmallVecData<A> {
}
#[inline]
fn from_inline(inline: A) -> SmallVecData<A> {
SmallVecData { inline }
SmallVecData { inline: ManuallyDrop::new(inline) }
}
#[inline]
unsafe fn into_inline(self) -> A { self.inline }
unsafe fn into_inline(self) -> A { ManuallyDrop::into_inner(self.inline) }
#[inline]
unsafe fn heap(&self) -> (*mut A::Item, usize) {
self.heap
Expand Down

0 comments on commit d6bfa84

Please sign in to comment.