]> git.proxmox.com Git - rustc.git/blob - src/test/mir-opt/end_region_5.rs
New upstream version 1.20.0+dfsg1
[rustc.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
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: ();
35 // let mut _4: [closure@NodeId(18) d: &'19mce D];
36 // let mut _5: &'19mce D;
37 //
38 // bb0: {
39 // StorageLive(_1);
40 // _1 = D::{{constructor}}(const 0i32,);
41 // StorageLive(_4);
42 // StorageLive(_5);
43 // _5 = &'19mce _1;
44 // _4 = [closure@NodeId(18)] { d: _5 };
45 // StorageDead(_5);
46 // _3 = const foo(_4) -> [return: bb2, unwind: bb3];
47 // }
48 // bb1: {
49 // resume;
50 // }
51 // bb2: {
52 // StorageDead(_4);
53 // EndRegion('19mce);
54 // _0 = ();
55 // drop(_1) -> bb4;
56 // }
57 // bb3: {
58 // EndRegion('19mce);
59 // drop(_1) -> bb1;
60 // }
61 // bb4: {
62 // StorageDead(_1);
63 // return;
64 // }
65 // }
66 // END rustc.node4.SimplifyCfg-qualify-consts.after.mir
67
68 // START rustc.node18.SimplifyCfg-qualify-consts.after.mir
69 // fn main::{{closure}}(_1: [closure@NodeId(18) d:&'19mce D]) -> i32 {
70 // let mut _0: i32;
71 // let mut _2: i32;
72 //
73 // bb0: {
74 // StorageLive(_2);
75 // _2 = ((*(_1.0: &'19mce D)).0: i32);
76 // _0 = _2;
77 // StorageDead(_2);
78 // return;
79 // }
80 // END rustc.node18.SimplifyCfg-qualify-consts.after.mir