2017-10-24 20:20:47 +00:00
|
|
|
// Basic test for liveness constraints: the region (`R1`) that appears
|
|
|
|
// in the type of `p` includes the points after `&v[0]` up to (but not
|
|
|
|
// including) the call to `use_x`. The `else` branch is not included.
|
|
|
|
|
2020-01-23 00:00:00 +00:00
|
|
|
// check-pass
|
2017-10-24 20:20:47 +00:00
|
|
|
|
|
|
|
#![allow(warnings)]
|
|
|
|
#![feature(dropck_eyepatch)]
|
|
|
|
|
|
|
|
fn use_x(_: usize) -> bool { true }
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut v = [1, 2, 3];
|
2017-12-20 16:20:07 +00:00
|
|
|
let p: WrapMayDangle<& /* R4 */ usize> = WrapMayDangle { value: &v[0] };
|
2017-10-24 20:20:47 +00:00
|
|
|
if true {
|
2017-12-20 16:20:07 +00:00
|
|
|
// `p` will get dropped at end of this block. However, because of
|
|
|
|
// the `#[may_dangle]` attribute, we do not need to consider R4
|
|
|
|
// live after this point.
|
2017-10-24 20:20:47 +00:00
|
|
|
use_x(*p.value);
|
|
|
|
} else {
|
2017-12-20 16:20:07 +00:00
|
|
|
v[0] += 1;
|
2017-10-24 20:20:47 +00:00
|
|
|
use_x(22);
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:20:07 +00:00
|
|
|
v[0] += 1;
|
2017-10-24 20:20:47 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 16:20:07 +00:00
|
|
|
struct WrapMayDangle<T> {
|
2017-10-24 20:20:47 +00:00
|
|
|
value: T
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:20:07 +00:00
|
|
|
unsafe impl<#[may_dangle] T> Drop for WrapMayDangle<T> {
|
2017-10-24 20:20:47 +00:00
|
|
|
fn drop(&mut self) { }
|
|
|
|
}
|