]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/drop-no-may-dangle.rs
Rollup merge of #83807 - sjakobi:77548-remove-ignore-annotations, r=Mark-Simulacrum
[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 // compile-flags:-Zborrowck=mir
7
8 #![allow(warnings)]
9 #![feature(dropck_eyepatch)]
10
11 fn use_x(_: usize) -> bool { true }
12
13 fn main() {
14     let mut v = [1, 2, 3];
15     let p: WrapMayNotDangle<&usize> = WrapMayNotDangle { value: &v[0] };
16     if true {
17         use_x(*p.value);
18     } else {
19         use_x(22);
20         v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
21     }
22
23     v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
24 }
25
26 struct WrapMayNotDangle<T> {
27     value: T
28 }
29
30 impl<T> Drop for WrapMayNotDangle<T> {
31     fn drop(&mut self) { }
32 }