]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/drop-may-dangle.rs
Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
[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 // check-pass
6
7 #![allow(warnings)]
8 #![feature(dropck_eyepatch)]
9
10 fn use_x(_: usize) -> bool { true }
11
12 fn main() {
13     let mut v = [1, 2, 3];
14     let p: WrapMayDangle<& /* R4 */ usize> = WrapMayDangle { value: &v[0] };
15     if true {
16         // `p` will get dropped at end of this block. However, because of
17         // the `#[may_dangle]` attribute, we do not need to consider R4
18         // live after this point.
19         use_x(*p.value);
20     } else {
21         v[0] += 1;
22         use_x(22);
23     }
24
25     v[0] += 1;
26 }
27
28 struct WrapMayDangle<T> {
29     value: T
30 }
31
32 unsafe impl<#[may_dangle] T> Drop for WrapMayDangle<T> {
33     fn drop(&mut self) { }
34 }