]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cleanup-rvalue-scopes-cf.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / cleanup-rvalue-scopes-cf.rs
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.
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-compare-mode-nll
12
13 // Test that the borrow checker prevents pointers to temporaries
14 // with statement lifetimes from escaping.
15
16 use std::ops::Drop;
17
18 static mut FLAGS: u64 = 0;
19
20 struct Box<T> { f: T }
21 struct AddFlags { bits: u64 }
22
23 fn AddFlags(bits: u64) -> AddFlags {
24     AddFlags { bits: bits }
25 }
26
27 fn arg(x: &AddFlags) -> &AddFlags {
28     x
29 }
30
31 impl AddFlags {
32     fn get(&self) -> &AddFlags {
33         self
34     }
35 }
36
37 pub fn main() {
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
45 }