]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_5.rs
Rollup merge of #44378 - frehberg:rustdoc, r=dtolnay
[rust.git] / src / test / mir-opt / end_region_5.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: Borrowing via by-ref closure.
15
16 fn main() {
17     let d = D(0);
18     foo(|| -> i32 { d.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(18) d:&'14s D];
35 //     let mut _4: &'14s D;
36 //     bb0: {
37 //         StorageLive(_1);
38 //         _1 = D::{{constructor}}(const 0i32,);
39 //         StorageLive(_3);
40 //         StorageLive(_4);
41 //         _4 = &'14s _1;
42 //         _3 = [closure@NodeId(18)] { d: _4 };
43 //         StorageDead(_4);
44 //         _2 = const foo(_3) -> [return: bb1, unwind: bb3];
45 //     }
46 //     bb1: {
47 //         EndRegion('14s);
48 //         StorageDead(_3);
49 //         _0 = ();
50 //         drop(_1) -> bb4;
51 //     }
52 //     bb2: {
53 //         resume;
54 //     }
55 //     bb3: {
56 //         EndRegion('14s);
57 //         drop(_1) -> bb2;
58 //     }
59 //     bb4: {
60 //         StorageDead(_1);
61 //         return;
62 //     }
63 // }
64 // END rustc.node4.SimplifyCfg-qualify-consts.after.mir
65
66 // START rustc.node18.SimplifyCfg-qualify-consts.after.mir
67 // fn main::{{closure}}(_1: [closure@NodeId(18) d:&'14s D]) -> i32 {
68 //    let mut _0: i32;
69 //    let mut _2: i32;
70 //
71 //    bb0: {
72 //        StorageLive(_2);
73 //        _2 = ((*(_1.0: &'14s D)).0: i32);
74 //        _0 = _2;
75 //        StorageDead(_2);
76 //        return;
77 //    }
78 // END rustc.node18.SimplifyCfg-qualify-consts.after.mir