]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/validate_1.rs
Unit test for proper EndRegion emission on a cyclic reference.
[rust.git] / src / test / mir-opt / validate_1.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 // ignore-tidy-linelength
12 // compile-flags: -Z verbose -Z mir-emit-validate=1 -Z span_free_formats
13
14 struct Test(i32);
15
16 impl Test {
17     // Make sure we run the pass on a method, not just on bare functions.
18     fn foo(&self, _x: &mut i32) {}
19 }
20
21 fn main() {
22     let mut x = 0;
23     Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor
24
25     // Also test closures
26     let c = |x: &mut i32| { let y = &*x; *y };
27     c(&mut x);
28 }
29
30 // END RUST SOURCE
31 // START rustc.node12.EraseRegions.after.mir
32 //     bb0: {
33 //         Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(0:5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]);
34 //         return;
35 //     }
36 // END rustc.node12.EraseRegions.after.mir
37 // START rustc.node23.EraseRegions.after.mir
38 // fn main() -> () {
39 //     bb0: {
40 //         Validate(Suspend(ReScope(Node(ItemLocalId(10)))), [_1: i32]);
41 //         _6 = &ReErased mut _1;
42 //         Validate(Acquire, [(*_6): i32/ReScope(Node(ItemLocalId(10)))]);
43 //         Validate(Suspend(ReScope(Node(ItemLocalId(10)))), [(*_6): i32/ReScope(Node(ItemLocalId(10)))]);
44 //         _5 = &ReErased mut (*_6);
45 //         Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(10)))]);
46 //         Validate(Release, [_2: (), _3: &ReScope(Node(ItemLocalId(10))) Test, _5: &ReScope(Node(ItemLocalId(10))) mut i32]);
47 //         _2 = const Test::foo(_3, _5) -> bb1;
48 //     }
49 //
50 //     bb1: {
51 //         Validate(Acquire, [_2: ()]);
52 //         EndRegion(ReScope(Node(ItemLocalId(10))));
53 //         return;
54 //     }
55 // }
56 // END rustc.node23.EraseRegions.after.mir
57 // START rustc.node50.EraseRegions.after.mir
58 // fn main::{{closure}}(_1: &ReErased [closure@NodeId(50)], _2: &ReErased mut i32) -> i32 {
59 //     bb0: {
60 //         Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:11) => validate_1/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(1:11) => validate_1/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
61 //         StorageLive(_3);
62 //         _3 = _2;
63 //         StorageLive(_4);
64 //         Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(22), first_statement_index: 0 }))), [(*_3): i32]);
65 //         _4 = &ReErased (*_3);
66 //         Validate(Acquire, [(*_4): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(22), first_statement_index: 0 })) (imm)]);
67 //         StorageLive(_5);
68 //         _5 = (*_4);
69 //         _0 = _5;
70 //         StorageDead(_5);
71 //         EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(22), first_statement_index: 0 })));
72 //         StorageDead(_4);
73 //         StorageDead(_3);
74 //         return;
75 //     }
76 // }
77 // END rustc.node50.EraseRegions.after.mir