]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-23338-params-outlive-temps-of-body.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / issue-23338-params-outlive-temps-of-body.rs
1 // run-pass
2 // This is largely checking that we now accept code where temp values
3 // are borrowing from the input parameters (the `foo` case below).
4 //
5 // Compare to run-pass/issue-23338-params-outlive-temps-of-body.rs
6 //
7 // (The `foo2` case is just for parity with the above test, which
8 //  shows what happens when you move the `y`-binding to the inside of
9 //  the inner block.)
10
11 use std::cell::RefCell;
12
13 fn foo(x: RefCell<String>) -> String {
14     x.borrow().clone()
15 }
16
17 fn foo2(x: RefCell<String>) -> String {
18     let y = x;
19     let ret = {
20         y.borrow().clone()
21     };
22     ret
23 }
24
25 pub fn main() {
26     let r = RefCell::new(format!("data"));
27     assert_eq!(foo(r), "data");
28     let r = RefCell::new(format!("data"));
29     assert_eq!(foo2(r), "data");
30 }