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