]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/drop-no-may-dangle.rs
Rollup merge of #105216 - GuillaumeGomez:rm-unused-gui-test, r=notriddle
[rust.git] / src / test / ui / nll / drop-no-may-dangle.rs
1 // Basic test for liveness constraints: the region (`R1`) that appears
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.)
5
6 #![allow(warnings)]
7 #![feature(dropck_eyepatch)]
8
9 fn use_x(_: usize) -> bool { true }
10
11 fn main() {
12     let mut v = [1, 2, 3];
13     let p: WrapMayNotDangle<&usize> = WrapMayNotDangle { value: &v[0] };
14     if true {
15         use_x(*p.value);
16     } else {
17         use_x(22);
18         v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
19     }
20
21     v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
22 }
23
24 struct WrapMayNotDangle<T> {
25     value: T
26 }
27
28 impl<T> Drop for WrapMayNotDangle<T> {
29     fn drop(&mut self) { }
30 }