From 34459766c27713017e77e3e88008243029f4f5c6 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 23 Feb 2017 20:19:11 +0100 Subject: [PATCH] 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. --- nodrop/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nodrop/src/lib.rs b/nodrop/src/lib.rs index 349bfce..eeea126 100644 --- a/nodrop/src/lib.rs +++ b/nodrop/src/lib.rs @@ -42,7 +42,8 @@ mod imp { #[repr(u8)] enum Flag { 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::() { // inhibit drop unsafe { - ptr::write(&mut self.0, Flag::Dropped); + ptr::write(&mut self.0, Flag::Dropped(0)); } } }