2017-10-24 15:20:47 -05:00
|
|
|
// Basic test for liveness constraints: the region (`R1`) that appears
|
2017-12-20 10:20:07 -06:00
|
|
|
// in the type of `p` must include everything until `p` is dropped
|
|
|
|
// because of destructor. (Note that the stderr also identifies this
|
|
|
|
// destructor in the error message.)
|
2017-10-24 15:20:47 -05:00
|
|
|
|
|
|
|
#![allow(warnings)]
|
|
|
|
#![feature(dropck_eyepatch)]
|
|
|
|
|
|
|
|
fn use_x(_: usize) -> bool { true }
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut v = [1, 2, 3];
|
2017-12-20 10:20:07 -06:00
|
|
|
let p: WrapMayNotDangle<&usize> = WrapMayNotDangle { value: &v[0] };
|
2017-10-24 15:20:47 -05:00
|
|
|
if true {
|
|
|
|
use_x(*p.value);
|
|
|
|
} else {
|
|
|
|
use_x(22);
|
2018-12-27 03:23:15 -06:00
|
|
|
v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
|
2017-10-24 15:20:47 -05:00
|
|
|
}
|
|
|
|
|
2018-12-27 03:23:15 -06:00
|
|
|
v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
|
2017-10-24 15:20:47 -05:00
|
|
|
}
|
|
|
|
|
2017-12-20 10:20:07 -06:00
|
|
|
struct WrapMayNotDangle<T> {
|
2017-10-24 15:20:47 -05:00
|
|
|
value: T
|
|
|
|
}
|
|
|
|
|
2017-12-20 10:20:07 -06:00
|
|
|
impl<T> Drop for WrapMayNotDangle<T> {
|
2017-10-24 15:20:47 -05:00
|
|
|
fn drop(&mut self) { }
|
|
|
|
}
|