]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_8.rs
6f899a0db15d918f39cd62ca2c0fb9806fad3ec5
[rust.git] / src / test / mir-opt / end_region_8.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 // Unwinding should EndRegion for in-scope borrows: Move of borrow into closure.
15
16 fn main() {
17     let d = D(0);
18     let r = &d;
19     foo(move || -> i32 { r.0 });
20 }
21
22 struct D(i32);
23 impl Drop for D { fn drop(&mut self) { println!("dropping D({})", self.0); } }
24
25 fn foo<F>(f: F) where F: FnOnce() -> i32 {
26     if f() > 0 { panic!("im positive"); }
27 }
28
29 // END RUST SOURCE
30 // START rustc.main.SimplifyCfg-qualify-consts.after.mir
31 // fn main() -> () {
32 //    let mut _0: ();
33 //    ...
34 //    let _2: &'21_1rs D;
35 //    ...
36 //    let _1: D;
37 //    ...
38 //    let mut _3: ();
39 //    let mut _4: [closure@NodeId(22) r:&'19s D];
40 //    bb0: {
41 //        StorageLive(_1);
42 //        _1 = D::{{constructor}}(const 0i32,);
43 //        FakeRead(ForLet, _1);
44 //        StorageLive(_2);
45 //        _2 = &'21_1rs _1;
46 //        FakeRead(ForLet, _2);
47 //        StorageLive(_4);
48 //        _4 = [closure@NodeId(22)] { r: _2 };
49 //        _3 = const foo(move _4) -> [return: bb2, unwind: bb3];
50 //    }
51 //    bb1: {
52 //        resume;
53 //    }
54 //    bb2: {
55 //        EndRegion('19s);
56 //        StorageDead(_4);
57 //        _0 = ();
58 //        EndRegion('21_1rs);
59 //        StorageDead(_2);
60 //        drop(_1) -> [return: bb4, unwind: bb1];
61 //    }
62 //    bb3: {
63 //        EndRegion('19s);
64 //        EndRegion('21_1rs);
65 //        drop(_1) -> bb1;
66 //    }
67 //    bb4: {
68 //        StorageDead(_1);
69 //        return;
70 //    }
71 // }
72 // END rustc.main.SimplifyCfg-qualify-consts.after.mir
73
74 // START rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir
75 // fn main::{{closure}}(_1: [closure@NodeId(22) r:&'19s D]) -> i32 {
76 //     let mut _0: i32;
77 //
78 //     bb0: {
79 //         _0 = ((*(_1.0: &'21_1rs D)).0: i32);
80 //         return;
81 //     }
82 // }
83 // END rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir