]>
Commit | Line | Data |
---|---|---|
abe05a73 | 1 | // Basic test for liveness constraints: the region (`R1`) that appears |
ff7c6d11 XL |
2 | // in the type of `p` must include everything until `p` is dropped |
3 | // because of destructor. (Note that the stderr also identifies this | |
4 | // destructor in the error message.) | |
abe05a73 | 5 | |
83c7162d | 6 | // compile-flags:-Zborrowck=mir |
abe05a73 XL |
7 | |
8 | #![allow(warnings)] | |
9 | #![feature(dropck_eyepatch)] | |
abe05a73 XL |
10 | |
11 | fn use_x(_: usize) -> bool { true } | |
12 | ||
13 | fn main() { | |
14 | let mut v = [1, 2, 3]; | |
ff7c6d11 | 15 | let p: WrapMayNotDangle<&usize> = WrapMayNotDangle { value: &v[0] }; |
abe05a73 XL |
16 | if true { |
17 | use_x(*p.value); | |
18 | } else { | |
19 | use_x(22); | |
0731742a | 20 | v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed |
abe05a73 XL |
21 | } |
22 | ||
0731742a | 23 | v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed |
abe05a73 XL |
24 | } |
25 | ||
ff7c6d11 | 26 | struct WrapMayNotDangle<T> { |
abe05a73 XL |
27 | value: T |
28 | } | |
29 | ||
ff7c6d11 | 30 | impl<T> Drop for WrapMayNotDangle<T> { |
abe05a73 XL |
31 | fn drop(&mut self) { } |
32 | } |