]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cleanup-rvalue-scopes-cf.rs
Auto merge of #60132 - davidtwco:issue-60075, r=estebank
[rust.git] / src / test / ui / cleanup-rvalue-scopes-cf.rs
1 // ignore-compare-mode-nll
2
3 // Test that the borrow checker prevents pointers to temporaries
4 // with statement lifetimes from escaping.
5
6 use std::ops::Drop;
7
8 static mut FLAGS: u64 = 0;
9
10 struct Box<T> { f: T }
11 struct AddFlags { bits: u64 }
12
13 fn AddFlags(bits: u64) -> AddFlags {
14     AddFlags { bits: bits }
15 }
16
17 fn arg(x: &AddFlags) -> &AddFlags {
18     x
19 }
20
21 impl AddFlags {
22     fn get(&self) -> &AddFlags {
23         self
24     }
25 }
26
27 pub fn main() {
28     let _x = arg(&AddFlags(1)); //~ ERROR value does not live long enough
29     let _x = AddFlags(1).get(); //~ ERROR value does not live long enough
30     let _x = &*arg(&AddFlags(1)); //~ ERROR value does not live long enough
31     let ref _x = *arg(&AddFlags(1)); //~ ERROR value does not live long enough
32     let &ref _x = arg(&AddFlags(1)); //~ ERROR value does not live long enough
33     let _x = AddFlags(1).get(); //~ ERROR value does not live long enough
34     let Box { f: _x } = Box { f: AddFlags(1).get() }; //~ ERROR value does not live long enough
35 }