parent
0aa8d03202
commit
376a6b2663
4 changed files with 72 additions and 5 deletions
16
src/test/ui/dropck/dropck-union.nll.stderr
Normal file
16
src/test/ui/dropck/dropck-union.nll.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error[E0597]: `v` does not live long enough
|
||||
--> $DIR/dropck-union.rs:39:18
|
||||
|
|
||||
LL | v.0.set(Some(&v)); //~ ERROR: `v` does not live long enough
|
||||
| ^^ borrowed value does not live long enough
|
||||
LL | }
|
||||
| -
|
||||
| |
|
||||
| `v` dropped here while still borrowed
|
||||
| borrow later used here, when `v` is dropped
|
||||
|
|
||||
= note: values in a scope are dropped in the opposite order they are defined
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
40
src/test/ui/dropck/dropck-union.rs
Normal file
40
src/test/ui/dropck/dropck-union.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#![feature(untagged_unions)]
|
||||
|
||||
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
|
||||
}
|
||||
13
src/test/ui/dropck/dropck-union.stderr
Normal file
13
src/test/ui/dropck/dropck-union.stderr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
error[E0597]: `v` does not live long enough
|
||||
--> $DIR/dropck-union.rs:39:19
|
||||
|
|
||||
LL | v.0.set(Some(&v)); //~ ERROR: `v` does not live long enough
|
||||
| ^ borrowed value does not live long enough
|
||||
LL | }
|
||||
| - `v` dropped here while still borrowed
|
||||
|
|
||||
= note: values in a scope are dropped in the opposite order they are created
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue