]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/nll/region-liveness-drop-no-may-dangle.rs
Auto merge of #46393 - kennytm:45861-step-2-3-make-tools-job-not-fail-fast, r=alexcri...
[rust.git] / src / test / mir-opt / nll / region-liveness-drop-no-may-dangle.rs
1 // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Basic test for liveness constraints: the region (`R1`) that appears
12 // in the type of `p` includes the points after `&v[0]` up to (but not
13 // including) the call to `use_x`. The `else` branch is not included.
14
15 // ignore-tidy-linelength
16 // compile-flags:-Znll -Zverbose
17 //                     ^^^^^^^^^ force compiler to dump more region information
18
19 #![allow(warnings)]
20
21 fn use_x(_: usize) -> bool { true }
22
23 fn main() {
24     let mut v = [1, 2, 3];
25     let p: Wrap<& /* R1 */ usize> = Wrap { value: &v[0] };
26     if true {
27         use_x(*p.value);
28     } else {
29         use_x(22);
30     }
31
32     // `p` will get dropped here. Because the `#[may_dangle]`
33     // attribute is not present on `Wrap`, we must conservatively
34     // assume that the dtor may access the `value` field, and hence we
35     // must consider R1 to be live.
36 }
37
38 struct Wrap<T> {
39     value: T
40 }
41
42 // Look ma, no `#[may_dangle]` attribute here.
43 impl<T> Drop for Wrap<T> {
44     fn drop(&mut self) { }
45 }
46
47 // END RUST SOURCE
48 // START rustc.main.nll.0.mir
49 // | '_#5r: {bb2[3], bb2[4], bb2[5], bb3[0], bb3[1], bb3[2], bb4[0], bb5[0], bb5[1], bb5[2], bb6[0], bb7[0], bb7[1], bb8[0]}
50 // END rustc.main.nll.0.mir