]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-ret-borrowed.rs
Do not use entropy during gen_weighted_bool(1)
[rust.git] / src / test / compile-fail / regions-ret-borrowed.rs
1 // Copyright 2012 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 // Ensure that you cannot use generic types to return a region outside
12 // of its bound.  Here, in the `return_it()` fn, we call with() but
13 // with R bound to &int from the return_it.  Meanwhile, with()
14 // provides a value that is only good within its own stack frame. This
15 // used to successfully compile because we failed to account for the
16 // fact that fn(x: &int) rebound the region &.
17
18 fn with<R>(f: |x: &int| -> R) -> R {
19     f(&3)
20 }
21
22 fn return_it<'a>() -> &'a int {
23     with(|o| o)
24         //~^ ERROR cannot infer
25 }
26
27 fn main() {
28     let x = return_it();
29     println!("foo={}", *x);
30 }