]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_8.rs
Auto merge of #45111 - aidanhs:aphs-bubble-worker-failures, r=alexcrichton
[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.node4.SimplifyCfg-qualify-consts.after.mir
31 // fn main() -> () {
32 //    let mut _0: ();
33 //    let _1: D;
34 //    let _2: &'21_1rs D;
35 //    let mut _3: ();
36 //    let mut _4: [closure@NodeId(22) r:&'21_1rs D];
37 //    let mut _5: &'21_1rs D;
38 //    bb0: {
39 //        StorageLive(_1);
40 //        _1 = D::{{constructor}}(const 0i32,);
41 //        StorageLive(_2);
42 //        _2 = &'21_1rs _1;
43 //        StorageLive(_4);
44 //        StorageLive(_5);
45 //        _5 = _2;
46 //        _4 = [closure@NodeId(22)] { r: _5 };
47 //        StorageDead(_5);
48 //        _3 = const foo(_4) -> [return: bb1, unwind: bb3];
49 //    }
50 //    bb1: {
51 //        StorageDead(_4);
52 //        _0 = ();
53 //        EndRegion('21_1rs);
54 //        StorageDead(_2);
55 //        drop(_1) -> bb4;
56 //    }
57 //    bb2: {
58 //        resume;
59 //    }
60 //    bb3: {
61 //        EndRegion('21_1rs);
62 //        drop(_1) -> bb2;
63 //    }
64 //    bb4: {
65 //        StorageDead(_1);
66 //        return;
67 //    }
68 // }
69 // END rustc.node4.SimplifyCfg-qualify-consts.after.mir
70
71 // START rustc.node22.SimplifyCfg-qualify-consts.after.mir
72 // fn main::{{closure}}(_1: [closure@NodeId(22) r:&'21_1rs D]) -> i32 {
73 //     let mut _0: i32;
74 //     let mut _2: i32;
75 //
76 //     bb0: {
77 //         StorageLive(_2);
78 //         _2 = ((*(_1.0: &'21_1rs D)).0: i32);
79 //         _0 = _2;
80 //         StorageDead(_2);
81 //         return;
82 //     }
83 // }
84 // END rustc.node22.SimplifyCfg-qualify-consts.after.mir