]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_9.rs
Fix tests and assertions; add some comments
[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.main.SimplifyCfg-qualify-consts.after.mir
41 // fn main() -> () {
42 //     let mut _0: ();
43 //     ...
44 //     let mut _4: &'37_0rs i32;
45 //     ...
46 //     let _2: i32;
47 //     ...
48 //     let mut _1: bool;
49 //     ...
50 //     let mut _3: ();
51 //     let mut _5: !;
52 //     let mut _6: ();
53 //     let mut _7: bool;
54 //     let mut _8: !;
55 //     bb0: {
56 //        StorageLive(_1);
57 //        _1 = const false;
58 //        FakeRead(ForLet, _1);
59 //        StorageLive(_2);
60 //        _2 = const 3i32;
61 //        FakeRead(ForLet, _2);
62 //        falseUnwind -> [real: bb2, cleanup: bb1];
63 //    }
64 //    bb1: {
65 //        ...
66 //    }
67 //    bb2: {
68 //        StorageLive(_4);
69 //        goto -> bb3;
70 //    }
71 //    bb3: {
72 //        falseUnwind -> [real: bb4, cleanup: bb1];
73 //    }
74 //    bb4: {
75 //        StorageLive(_7);
76 //        _7 = _1;
77 //        switchInt(move _7) -> [false: bb6, otherwise: bb5];
78 //    }
79 //    bb5: {
80 //        _0 = ();
81 //        StorageDead(_7);
82 //        EndRegion('37_0rs);
83 //        StorageDead(_4);
84 //        StorageDead(_2);
85 //        StorageDead(_1);
86 //        return;
87 //    }
88 //    bb6: {
89 //        _4 = &'37_0rs _2;
90 //        _6 = ();
91 //        StorageDead(_7);
92 //        _1 = const true;
93 //        _3 = ();
94 //        goto -> bb3;
95 //    }
96 // }
97 // END rustc.main.SimplifyCfg-qualify-consts.after.mir