]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/nll/region-liveness-drop-may-dangle.rs
Update the tools CI to use --no-fail-fast and --save-toolstates.
[rust.git] / src / test / mir-opt / nll / region-liveness-drop-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 // compile-flags:-Znll -Zverbose
16 //                     ^^^^^^^^^ force compiler to dump more region information
17
18 #![allow(warnings)]
19 #![feature(dropck_eyepatch)]
20 #![feature(generic_param_attrs)]
21
22 fn use_x(_: usize) -> bool { true }
23
24 fn main() {
25     let mut v = [1, 2, 3];
26     let p: Wrap<& /* R4 */ usize> = Wrap { value: &v[0] };
27     if true {
28         use_x(*p.value);
29     } else {
30         use_x(22);
31     }
32
33     // `p` will get dropped here. However, because of the
34     // `#[may_dangle]` attribute, we do not need to consider R4 live.
35 }
36
37 struct Wrap<T> {
38     value: T
39 }
40
41 unsafe impl<#[may_dangle] T> Drop for Wrap<T> {
42     fn drop(&mut self) { }
43 }
44
45 // END RUST SOURCE
46 // START rustc.main.nll.0.mir
47 // | '_#5r: {bb1[3], bb1[4], bb1[5], bb2[0], bb2[1]}
48 // END rustc.main.nll.0.mir