]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/end_region_6.rs
Update the tools CI to use --no-fail-fast and --save-toolstates.
[rust.git] / src / test / mir-opt / end_region_6.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: 2nd borrow within by-ref closure.
15
16 fn main() {
17     let d = D(0);
18     foo(|| -> 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:&'19s D];
37 //     let mut _4: &'19s D;
38 //     bb0: {
39 //         StorageLive(_1);
40 //         _1 = D::{{constructor}}(const 0i32,);
41 //         StorageLive(_3);
42 //         StorageLive(_4);
43 //         _4 = &'19s _1;
44 //         _3 = [closure@NodeId(22)] { d: move _4 };
45 //         StorageDead(_4);
46 //         _2 = const foo(move _3) -> [return: bb1, unwind: bb3];
47 //     }
48 //     bb1: {
49 //         EndRegion('19s);
50 //         StorageDead(_3);
51 //         _0 = ();
52 //         drop(_1) -> bb4;
53 //     }
54 //     bb2: {
55 //         resume;
56 //     }
57 //     bb3: {
58 //         EndRegion('19s);
59 //         drop(_1) -> bb2;
60 //     }
61 //     bb4: {
62 //         StorageDead(_1);
63 //         return;
64 //     }
65 // END rustc.main.SimplifyCfg-qualify-consts.after.mir
66
67 // START rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir
68 // fn main::{{closure}}(_1: [closure@NodeId(22) d:&'19s D]) -> i32 {
69 //     let mut _0: i32;
70 //     ...
71 //     let _2: &'15_0rs D;
72 //     ...
73 //     let mut _3: i32;
74 //     bb0: {
75 //         StorageLive(_2);
76 //         _2 = &'15_0rs (*(_1.0: &'19s D));
77 //         StorageLive(_3);
78 //         _3 = ((*_2).0: i32);
79 //         _0 = move _3;
80 //         StorageDead(_3);
81 //         EndRegion('15_0rs);
82 //         StorageDead(_2);
83 //         return;
84 //     }
85 // END rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir