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.
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.
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 &.
18 fn with<R, F>(f: F) -> R where F: FnOnce(&int) -> R {
22 fn return_it<'a>() -> &'a int {
24 //~^ ERROR cannot infer
29 println!("foo={}", *x);