diff options
Diffstat (limited to 'tests/ui/dropck/dropck-union.rs')
-rw-r--r-- | tests/ui/dropck/dropck-union.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/dropck/dropck-union.rs b/tests/ui/dropck/dropck-union.rs new file mode 100644 index 000000000..5a9965db5 --- /dev/null +++ b/tests/ui/dropck/dropck-union.rs @@ -0,0 +1,38 @@ +use std::cell::Cell; +use std::ops::Deref; +use std::mem::ManuallyDrop; + +union Wrap<T> { x: ManuallyDrop<T> } + +impl<T> Drop for Wrap<T> { + fn drop(&mut self) { + unsafe { std::ptr::drop_in_place(&mut *self.x as *mut T); } + } +} + +impl<T> Wrap<T> { + fn new(x: T) -> Self { + Wrap { x: ManuallyDrop::new(x) } + } +} + +impl<T> Deref for Wrap<T> { + type Target = T; + #[inline] + fn deref(&self) -> &Self::Target { + unsafe { + &self.x + } + } +} + +struct C<'a>(Cell<Option<&'a C<'a>>>); + +impl<'a> Drop for C<'a> { + fn drop(&mut self) {} +} + +fn main() { + let v : Wrap<C> = Wrap::new(C(Cell::new(None))); + v.0.set(Some(&v)); //~ ERROR: `v` does not live long enough +} |