]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/drop-may-dangle.rs
Rollup merge of #89468 - FabianWolff:issue-89358, r=jackh726
[rust.git] / src / test / ui / nll / drop-may-dangle.rs
1 // Basic test for liveness constraints: the region (`R1`) that appears
2 // in the type of `p` includes the points after `&v[0]` up to (but not
3 // including) the call to `use_x`. The `else` branch is not included.
4
5 // compile-flags:-Zborrowck=mir
6 // check-pass
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: WrapMayDangle<& /* R4 */ usize> = WrapMayDangle { value: &v[0] };
16     if true {
17         // `p` will get dropped at end of this block. However, because of
18         // the `#[may_dangle]` attribute, we do not need to consider R4
19         // live after this point.
20         use_x(*p.value);
21     } else {
22         v[0] += 1;
23         use_x(22);
24     }
25
26     v[0] += 1;
27 }
28
29 struct WrapMayDangle<T> {
30     value: T
31 }
32
33 unsafe impl<#[may_dangle] T> Drop for WrapMayDangle<T> {
34     fn drop(&mut self) { }
35 }