Use u8 field in the NoDrop Dropped variant

We need to ensure NoDrop<&T> and similar are not using the enum layout
optimization. Using an enum { Alive(T), Dropped(u8) } is a simple way to
do that. The NoDrop (non-unions version) was already always at least
1 byte large anyway.
This commit is contained in:
bluss
2017-02-23 20:19:11 +01:00
parent da459bcf78
commit 34459766c2
+3 -2
View File
@@ -42,7 +42,8 @@ mod imp {
#[repr(u8)] #[repr(u8)]
enum Flag<T> { enum Flag<T> {
Alive(T), Alive(T),
Dropped, // Dummy u8 field below, again to beat the enum layout opt
Dropped(u8),
} }
@@ -89,7 +90,7 @@ mod imp {
if needs_drop::<T>() { if needs_drop::<T>() {
// inhibit drop // inhibit drop
unsafe { unsafe {
ptr::write(&mut self.0, Flag::Dropped); ptr::write(&mut self.0, Flag::Dropped(0));
} }
} }
} }