1 // Copyright 2014 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 // Test that this fairly specialized, but also reasonable, pattern
12 // typechecks. The pattern involves regions bound in closures that
13 // wind up related to inference variables.
15 // NB. Changes to the region implementatiosn have broken this pattern
16 // a few times, but it happens to be used in the compiler so those
17 // changes were caught. However, those uses in the compiler could
18 // easily get changed or refactored away in the future.
24 struct Foo<'a,'tcx:'a> {
28 impl<'a,'tcx> Foo<'a,'tcx> {
29 fn bother(&mut self) -> int {
30 self.elaborate_bounds(|this| {
31 // (*) Here: type of `this` is `&'f0 Foo<&'f1, '_2>`,
32 // where `'f0` and `'f1` are fresh, free regions that
33 // result from the bound regions on the closure, and `'2`
34 // is a region inference variable created by the call. Due
35 // to the constraints on the type, we find that `'_2 : 'f1
36 // + 'f2` must hold (and can be assumed by the callee).
37 // Region inference has to do some clever stuff to avoid
38 // inferring `'_2` to be `'static` in this case, because
39 // it is created outside the closure but then related to
40 // regions bound by the closure itself. See the
41 // `region_inference.rs` file (and the `givens` field, in
42 // particular) for more details.
47 fn foo(&mut self) -> int {
53 mk_cand: for<'b>|this: &mut Foo<'b, 'tcx>| -> int)
62 let cx = Ctxt { x: &v };
63 let mut foo = Foo { cx: &cx };
64 assert_eq!(foo.bother(), 22); // just so the code is not dead, basically