1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(untagged_unions)]
15 use std::mem::ManuallyDrop;
17 union Wrap<T> { x: ManuallyDrop<T> }
19 impl<T> Drop for Wrap<T> {
21 unsafe { std::ptr::drop_in_place(&mut *self.x as *mut T); }
26 fn new(x: T) -> Self {
27 Wrap { x: ManuallyDrop::new(x) }
31 impl<T> Deref for Wrap<T> {
34 fn deref(&self) -> &Self::Target {
41 struct C<'a>(Cell<Option<&'a C<'a>>>);
43 impl<'a> Drop for C<'a> {
48 let v : Wrap<C> = Wrap::new(C(Cell::new(None)));
49 v.0.set(Some(&v)); //~ ERROR: `v` does not live long enough