end_region_5.rs 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

// Unwinding should EndRegion for in-scope borrows: Borrowing via by-ref closure.

fn main() {
    let d = D(0);
    foo(|| -> i32 { d.0 });
}

struct D(i32);
impl Drop for D { fn drop(&mut self) { println!("dropping D({})", self.0); } }

fn foo<F>(f: F) where F: FnOnce() -> i32 {
    if f() > 0 { panic!("im positive"); }
}

// END RUST SOURCE
28
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
29
// fn main() -> () {
30
//     ...
31
//     let mut _0: ();
32
//     ...
33
//     let _1: D;
34
//     ...
35
//     let mut _2: ();
36 37
//     let mut _3: [closure@NodeId(18) d:&'14s D];
//     let mut _4: &'14s D;
38 39 40
//     bb0: {
//         StorageLive(_1);
//         _1 = D::{{constructor}}(const 0i32,);
41
//         StorageLive(_3);
42
//         StorageLive(_4);
43
//         _4 = &'14s _1;
44
//         _3 = [closure@NodeId(18)] { d: move _4 };
45
//         StorageDead(_4);
46
//         _2 = const foo(move _3) -> [return: bb2, unwind: bb3];
47 48
//     }
//     bb1: {
49 50 51
//         resume;
//     }
//     bb2: {
52
//         EndRegion('14s);
53
//         StorageDead(_3);
54
//         _0 = ();
55
//         drop(_1) -> [return: bb4, unwind: bb1];
56
//     }
57
//     bb3: {
58
//         EndRegion('14s);
59
//         drop(_1) -> bb1;
60 61 62 63 64 65
//     }
//     bb4: {
//         StorageDead(_1);
//         return;
//     }
// }
66
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
67

M
Mikhail Modin 已提交
68
// START rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir
69
// fn main::{{closure}}(_1: [closure@NodeId(18) d:&'14s D]) -> i32 {
70 71 72 73 74
//    let mut _0: i32;
//    let mut _2: i32;
//
//    bb0: {
//        StorageLive(_2);
75
//        _2 = ((*(_1.0: &'14s D)).0: i32);
76
//        _0 = move _2;
77 78 79
//        StorageDead(_2);
//        return;
//    }
M
Mikhail Modin 已提交
80
// END rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir