]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_9.rs
Unit test for proper EndRegion emission on a cyclic reference.
[rust.git] / src / test / mir-opt / end_region_9.rs
1 // Copyright 2017 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 // compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
12 // ignore-tidy-linelength
13
14 // This test models a scenario that arielb1 found during review.
15 // Namely, any filtering of EndRegions must ensure to continue to emit
16 // any necessary EndRegions that occur earlier in the source than the
17 // first borrow involving that region.
18 //
19 // It is tricky to actually construct examples of this, which is the
20 // main reason that I am keeping this test even though I have now
21 // removed the pre-filter that motivated the test in the first place.
22
23 fn main() {
24     let mut second_iter = false;
25     let x = 3;
26     'a: loop {
27         let mut y;
28         loop {
29             if second_iter {
30                 break 'a; // want to generate `EndRegion('a)` here
31             } else {
32                 y = &/*'a*/ x;
33             }
34             second_iter = true;
35         }
36     }
37 }
38
39 // END RUST SOURCE
40 // START rustc.node4.SimplifyCfg-qualify-consts.after.mir
41 // fn main() -> () {
42 //     let mut _0: ();
43 //     let mut _1: bool;
44 //     let _2: i32;
45 //     let mut _4: &'33_0rs i32;
46 //     let mut _3: ();
47 //     let mut _5: !;
48 //     let mut _6: ();
49 //     let mut _7: bool;
50 //     let mut _8: !;
51 //
52 //     bb0: {
53 //        StorageLive(_1);
54 //        _1 = const false;
55 //        StorageLive(_2);
56 //        _2 = const 3i32;
57 //        StorageLive(_4);
58 //        goto -> bb1;
59 //    }
60 //
61 //    bb1: {
62 //        StorageLive(_7);
63 //        _7 = _1;
64 //        switchInt(_7) -> [0u8: bb3, otherwise: bb2];
65 //    }
66 //
67 //    bb2: {
68 //        _0 = ();
69 //        StorageDead(_7);
70 //        EndRegion('33_0rs);
71 //        StorageDead(_4);
72 //        StorageDead(_2);
73 //        StorageDead(_1);
74 //        return;
75 //    }
76 //
77 //    bb3: {
78 //        _4 = &'33_0rs _2;
79 //        _6 = ();
80 //        StorageDead(_7);
81 //        _1 = const true;
82 //        _3 = ();
83 //        goto -> bb1;
84 //    }
85 // }
86 // END rustc.node4.SimplifyCfg-qualify-consts.after.mir