]>
Commit | Line | Data |
---|---|---|
abe05a73 XL |
1 | // Copyright 2012-2016 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. | |
4 | // | |
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. | |
10 | ||
11 | // Basic test for liveness constraints: the region (`R1`) that appears | |
12 | // in the type of `p` includes the points after `&v[0]` up to (but not | |
13 | // including) the call to `use_x`. The `else` branch is not included. | |
14 | ||
83c7162d XL |
15 | // compile-flags:-Zborrowck=mir |
16 | // compile-pass | |
abe05a73 XL |
17 | |
18 | #![allow(warnings)] | |
19 | #![feature(dropck_eyepatch)] | |
abe05a73 XL |
20 | |
21 | fn use_x(_: usize) -> bool { true } | |
22 | ||
23 | fn main() { | |
24 | let mut v = [1, 2, 3]; | |
ff7c6d11 | 25 | let p: WrapMayDangle<& /* R4 */ usize> = WrapMayDangle { value: &v[0] }; |
abe05a73 | 26 | if true { |
ff7c6d11 XL |
27 | // `p` will get dropped at end of this block. However, because of |
28 | // the `#[may_dangle]` attribute, we do not need to consider R4 | |
29 | // live after this point. | |
abe05a73 XL |
30 | use_x(*p.value); |
31 | } else { | |
ff7c6d11 | 32 | v[0] += 1; |
abe05a73 XL |
33 | use_x(22); |
34 | } | |
35 | ||
ff7c6d11 | 36 | v[0] += 1; |
abe05a73 XL |
37 | } |
38 | ||
ff7c6d11 | 39 | struct WrapMayDangle<T> { |
abe05a73 XL |
40 | value: T |
41 | } | |
42 | ||
ff7c6d11 | 43 | unsafe impl<#[may_dangle] T> Drop for WrapMayDangle<T> { |
abe05a73 XL |
44 | fn drop(&mut self) { } |
45 | } |