]> git.proxmox.com Git - rustc.git/blame - src/test/ui/cleanup-rvalue-scopes-cf.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / cleanup-rvalue-scopes-cf.rs
CommitLineData
1a4d82fc
JJ
1// Test that the borrow checker prevents pointers to temporaries
2// with statement lifetimes from escaping.
3
4use std::ops::Drop;
5
6static mut FLAGS: u64 = 0;
7
48663c56 8struct StackBox<T> { f: T }
1a4d82fc
JJ
9struct AddFlags { bits: u64 }
10
11fn AddFlags(bits: u64) -> AddFlags {
12 AddFlags { bits: bits }
13}
14
15fn arg(x: &AddFlags) -> &AddFlags {
16 x
17}
18
19impl AddFlags {
20 fn get(&self) -> &AddFlags {
21 self
22 }
23}
24
25pub fn main() {
48663c56
XL
26 let x1 = arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
27 let x2 = AddFlags(1).get(); //~ ERROR temporary value dropped while borrowed
28 let x3 = &*arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
29 let ref x4 = *arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
30 let &ref x5 = arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
31 let x6 = AddFlags(1).get(); //~ ERROR temporary value dropped while borrowed
32 let StackBox { f: x7 } = StackBox { f: AddFlags(1).get() };
33 //~^ ERROR temporary value dropped while borrowed
34 (x1, x2, x3, x4, x5, x6, x7);
1a4d82fc 35}