|
| 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 mir-emit-retag -Z mir-opt-level=0 -Z span_free_formats |
| 13 | + |
| 14 | +#![allow(unused)] |
| 15 | + |
| 16 | +struct Test(i32); |
| 17 | + |
| 18 | +impl Test { |
| 19 | + // Make sure we run the pass on a method, not just on bare functions. |
| 20 | + fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 { x } |
| 21 | + fn foo_shr<'x>(&self, x: &'x i32) -> &'x i32 { x } |
| 22 | +} |
| 23 | + |
| 24 | +fn main() { |
| 25 | + let mut x = 0; |
| 26 | + { |
| 27 | + let v = Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor |
| 28 | + let w = { v }; // assignment |
| 29 | + let _w = w; // reborrow |
| 30 | + } |
| 31 | + |
| 32 | + // Also test closures |
| 33 | + let c: fn(&i32) -> &i32 = |x: &i32| -> &i32 { let _y = x; x }; |
| 34 | + let _w = c(&x); |
| 35 | + |
| 36 | + // need to call `foo_shr` or it doesn't even get generated |
| 37 | + Test(0).foo_shr(&0); |
| 38 | +} |
| 39 | + |
| 40 | +// END RUST SOURCE |
| 41 | +// START rustc.{{impl}}-foo.EraseRegions.after.mir |
| 42 | +// bb0: { |
| 43 | +// Retag([fn entry] _1); |
| 44 | +// Retag([fn entry] _2); |
| 45 | +// ... |
| 46 | +// _0 = &mut (*_3); |
| 47 | +// ... |
| 48 | +// return; |
| 49 | +// } |
| 50 | +// END rustc.{{impl}}-foo.EraseRegions.after.mir |
| 51 | +// START rustc.{{impl}}-foo_shr.EraseRegions.after.mir |
| 52 | +// bb0: { |
| 53 | +// Retag([fn entry] _1); |
| 54 | +// Retag([fn entry] _2); |
| 55 | +// ... |
| 56 | +// _0 = _2; |
| 57 | +// Retag(_0); |
| 58 | +// ... |
| 59 | +// return; |
| 60 | +// } |
| 61 | +// END rustc.{{impl}}-foo_shr.EraseRegions.after.mir |
| 62 | +// START rustc.main.EraseRegions.after.mir |
| 63 | +// fn main() -> () { |
| 64 | +// ... |
| 65 | +// bb0: { |
| 66 | +// ... |
| 67 | +// _3 = const Test::foo(move _4, move _6) -> bb1; |
| 68 | +// } |
| 69 | +// |
| 70 | +// bb1: { |
| 71 | +// Retag(_3); |
| 72 | +// ... |
| 73 | +// _9 = move _3; |
| 74 | +// Retag(_9); |
| 75 | +// _8 = &mut (*_9); |
| 76 | +// StorageDead(_9); |
| 77 | +// StorageLive(_10); |
| 78 | +// _10 = move _8; |
| 79 | +// Retag(_10); |
| 80 | +// ... |
| 81 | +// _13 = move _14(move _15) -> bb2; |
| 82 | +// } |
| 83 | +// |
| 84 | +// bb2: { |
| 85 | +// Retag(_13); |
| 86 | +// ... |
| 87 | +// } |
| 88 | +// ... |
| 89 | +// } |
| 90 | +// END rustc.main.EraseRegions.after.mir |
| 91 | +// START rustc.main-{{closure}}.EraseRegions.after.mir |
| 92 | +// fn main::{{closure}}(_1: &[closure@NodeId(117)], _2: &i32) -> &i32 { |
| 93 | +// ... |
| 94 | +// bb0: { |
| 95 | +// Retag([fn entry] _1); |
| 96 | +// Retag([fn entry] _2); |
| 97 | +// StorageLive(_3); |
| 98 | +// _3 = _2; |
| 99 | +// Retag(_3); |
| 100 | +// _0 = _2; |
| 101 | +// Retag(_0); |
| 102 | +// StorageDead(_3); |
| 103 | +// return; |
| 104 | +// } |
| 105 | +// } |
| 106 | +// END rustc.main-{{closure}}.EraseRegions.after.mir |
0 commit comments