3 // Test that this fairly specialized, but also reasonable, pattern
4 // typechecks. The pattern involves regions bound in closures that
5 // wind up related to inference variables.
7 // NB. Changes to the region implementations have broken this pattern
8 // a few times, but it happens to be used in the compiler so those
9 // changes were caught. However, those uses in the compiler could
10 // easily get changed or refactored away in the future.
16 struct Foo<'a,'tcx:'a> {
20 impl<'a,'tcx> Foo<'a,'tcx> {
21 fn bother(&mut self) -> isize {
22 self.elaborate_bounds(Box::new(|this| {
23 // (*) Here: type of `this` is `&'f0 Foo<&'f1, '_2>`,
24 // where `'f0` and `'f1` are fresh, free regions that
25 // result from the bound regions on the closure, and `'2`
26 // is a region inference variable created by the call. Due
27 // to the constraints on the type, we find that `'_2 : 'f1
28 // + 'f2` must hold (and can be assumed by the callee).
29 // Region inference has to do some clever stuff to avoid
30 // inferring `'_2` to be `'static` in this case, because
31 // it is created outside the closure but then related to
32 // regions bound by the closure itself. See the
33 // `region_constraints.rs` file (and the `givens` field, in
34 // particular) for more details.
39 fn foo(&mut self) -> isize {
45 mut mk_cand: Box<dyn for<'b> FnMut(&mut Foo<'b, 'tcx>) -> isize>)
54 let cx = Ctxt { x: &v };
55 let mut foo = Foo { cx: &cx };
56 assert_eq!(foo.bother(), 22); // just so the code is not dead, basically