]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/regions-ret-borrowed.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / regions / regions-ret-borrowed.rs
1 // Ensure that you cannot use generic types to return a region outside
2 // of its bound. Here, in the `return_it()` fn, we call with() but
3 // with R bound to &isize from the return_it. Meanwhile, with()
4 // provides a value that is only good within its own stack frame. This
5 // used to successfully compile because we failed to account for the
6 // fact that fn(x: &isize) rebound the region &.
7
8 fn with<R, F>(f: F) -> R where F: FnOnce(&isize) -> R {
9 f(&3)
10 }
11
12 fn return_it<'a>() -> &'a isize {
13 with(|o| o)
14 //~^ ERROR lifetime may not live long enough
15 }
16
17 fn main() {
18 let x = return_it();
19 println!("foo={}", *x);
20 }