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