]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/issue-23338-locals-die-before-temps-of-body.rs
Rollup merge of #87922 - Manishearth:c-enum-target-spec, r=nagisa,eddyb
[rust.git] / src / test / ui / span / issue-23338-locals-die-before-temps-of-body.rs
1 // This is just checking that we still reject code where temp values
2 // are borrowing values for longer than they will be around.
3 //
4 // Compare to run-pass/issue-23338-params-outlive-temps-of-body.rs
5
6 use std::cell::RefCell;
7
8 fn foo(x: RefCell<String>) -> String {
9     let y = x;
10     y.borrow().clone()
11 }
12 //~^^ ERROR `y` does not live long enough
13
14 fn foo2(x: RefCell<String>) -> String {
15     let ret = {
16         let y = x;
17         y.borrow().clone()
18     };
19     //~^^ ERROR `y` does not live long enough
20     ret
21 }
22
23 fn main() {
24     let r = RefCell::new(format!("data"));
25     assert_eq!(foo(r), "data");
26     let r = RefCell::new(format!("data"));
27     assert_eq!(foo2(r), "data");
28 }