Skip to content

Commit

Permalink
Auto merge of #135 - bluss:untagged-unions-with-manually-drop, r=mbru…
Browse files Browse the repository at this point in the history
…beck

Update union code to use ManuallyDrop

At the time of this writing, this breaking change is *proposed*, see rust-lang/rust/pull/56440.
Smallvec would have to be updated before the change can be merged upstream. Thanks!

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.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/135)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Dec 20, 2018
2 parents e244d0a + d6bfa84 commit e8999ec
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 e8999ec

Please sign in to comment.