1 // Test that the borrow checker prevents pointers to temporaries
2 // with statement lifetimes from escaping.
6 static mut FLAGS
: u64 = 0;
8 struct StackBox
<T
> { f: T }
9 struct AddFlags { bits: u64 }
11 fn AddFlags(bits
: u64) -> AddFlags
{
12 AddFlags { bits: bits }
15 fn arg(x
: &AddFlags
) -> &AddFlags
{
20 fn get(&self) -> &AddFlags
{
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
);