]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_7.rs
Rollup merge of #45095 - bluss:discriminant-send-sync, r=alexcrichton
[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.node4.SimplifyCfg-qualify-consts.after.mir
30 // fn main() -> () {
31 //     let mut _0: ();
32 //     let _1: D;
33 //     let mut _2: ();
34 //     let mut _3: [closure@NodeId(22) d:D];
35 //     let mut _4: D;
36 //
37 //     bb0: {
38 //         StorageLive(_1);
39 //         _1 = D::{{constructor}}(const 0i32,);
40 //         StorageLive(_3);
41 //         StorageLive(_4);
42 //         _4 = _1;
43 //         _3 = [closure@NodeId(22)] { d: _4 };
44 //         drop(_4) -> [return: bb4, unwind: bb3];
45 //     }
46 //     bb1: {
47 //         resume;
48 //     }
49 //     bb2: {
50 //         drop(_1) -> bb1;
51 //     }
52 //     bb3: {
53 //         drop(_3) -> bb2;
54 //     }
55 //     bb4: {
56 //         StorageDead(_4);
57 //         _2 = const foo(_3) -> [return: bb5, unwind: bb3];
58 //     }
59 //     bb5: {
60 //         drop(_3) -> [return: bb6, unwind: bb2];
61 //     }
62 //     bb6: {
63 //         StorageDead(_3);
64 //         _0 = ();
65 //         drop(_1) -> bb7;
66 //     }
67 //     bb7: {
68 //         StorageDead(_1);
69 //         return;
70 //     }
71 // }
72 // END rustc.node4.SimplifyCfg-qualify-consts.after.mir
73
74 // START rustc.node22.SimplifyCfg-qualify-consts.after.mir
75 // fn main::{{closure}}(_1: [closure@NodeId(22) d:D]) -> i32 {
76 //     let mut _0: i32;
77 //     let _2: &'15_0rs D;
78 //     let mut _3: i32;
79 //
80 //     bb0: {
81 //         StorageLive(_2);
82 //         _2 = &'15_0rs (_1.0: D);
83 //         StorageLive(_3);
84 //         _3 = ((*_2).0: i32);
85 //         _0 = _3;
86 //         StorageDead(_3);
87 //         EndRegion('15_0rs);
88 //         StorageDead(_2);
89 //         drop(_1) -> bb1;
90 //     }
91 //     bb1: {
92 //         return;
93 //     }
94 // }
95 // END rustc.node22.SimplifyCfg-qualify-consts.after.mir