1 // Copyright 2014 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.
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.
11 // ignore-compare-mode-nll
13 // Test that the borrow checker prevents pointers to temporaries
14 // with statement lifetimes from escaping.
18 static mut FLAGS: u64 = 0;
20 struct Box<T> { f: T }
21 struct AddFlags { bits: u64 }
23 fn AddFlags(bits: u64) -> AddFlags {
24 AddFlags { bits: bits }
27 fn arg(x: &AddFlags) -> &AddFlags {
32 fn get(&self) -> &AddFlags {
38 let _x = arg(&AddFlags(1)); //~ ERROR value does not live long enough
39 let _x = AddFlags(1).get(); //~ ERROR value does not live long enough
40 let _x = &*arg(&AddFlags(1)); //~ ERROR value does not live long enough
41 let ref _x = *arg(&AddFlags(1)); //~ ERROR value does not live long enough
42 let &ref _x = arg(&AddFlags(1)); //~ ERROR value does not live long enough
43 let _x = AddFlags(1).get(); //~ ERROR value does not live long enough
44 let Box { f: _x } = Box { f: AddFlags(1).get() }; //~ ERROR value does not live long enough