]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_5.rs
Auto merge of #45806 - alexcrichton:update-llvm-for-mips, r=michaelwoerister
[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.main.SimplifyCfg-qualify-consts.after.mir
30 // fn main() -> () {
31 //     ...
32 //     let mut _0: ();
33 //     ...
34 //     let _1: D;
35 //     ...
36 //     let mut _2: ();
37 //     let mut _3: [closure@NodeId(18) d:&'14s D];
38 //     let mut _4: &'14s D;
39 //     bb0: {
40 //         StorageLive(_1);
41 //         _1 = D::{{constructor}}(const 0i32,);
42 //         StorageLive(_3);
43 //         StorageLive(_4);
44 //         _4 = &'14s _1;
45 //         _3 = [closure@NodeId(18)] { d: _4 };
46 //         StorageDead(_4);
47 //         _2 = const foo(_3) -> [return: bb1, unwind: bb3];
48 //     }
49 //     bb1: {
50 //         EndRegion('14s);
51 //         StorageDead(_3);
52 //         _0 = ();
53 //         drop(_1) -> bb4;
54 //     }
55 //     bb2: {
56 //         resume;
57 //     }
58 //     bb3: {
59 //         EndRegion('14s);
60 //         drop(_1) -> bb2;
61 //     }
62 //     bb4: {
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(18) d:&'14s D]) -> i32 {
71 //    let mut _0: i32;
72 //    let mut _2: i32;
73 //
74 //    bb0: {
75 //        StorageLive(_2);
76 //        _2 = ((*(_1.0: &'14s D)).0: i32);
77 //        _0 = _2;
78 //        StorageDead(_2);
79 //        return;
80 //    }
81 // END rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir