]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/regions/regions-relate-bound-regions-on-closures-to-inference-variables.rs
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.
12 #![feature(box_syntax)]
18 struct Foo
<'a
,'tcx
:'a
> {
22 impl<'a
,'tcx
> Foo
<'a
,'tcx
> {
23 fn bother(&mut self) -> isize {
24 self.elaborate_bounds(Box
::new(|this
| {
25 // (*) Here: type of `this` is `&'f0 Foo<&'f1, '_2>`,
26 // where `'f0` and `'f1` are fresh, free regions that
27 // result from the bound regions on the closure, and `'2`
28 // is a region inference variable created by the call. Due
29 // to the constraints on the type, we find that `'_2 : 'f1
30 // + 'f2` must hold (and can be assumed by the callee).
31 // Region inference has to do some clever stuff to avoid
32 // inferring `'_2` to be `'static` in this case, because
33 // it is created outside the closure but then related to
34 // regions bound by the closure itself. See the
35 // `region_constraints.rs` file (and the `givens` field, in
36 // particular) for more details.
41 fn foo(&mut self) -> isize {
47 mut mk_cand
: Box
<dyn for<'b
> FnMut(&mut Foo
<'b
, 'tcx
>) -> isize>)
56 let cx
= Ctxt { x: &v }
;
57 let mut foo
= Foo { cx: &cx }
;
58 assert_eq
!(foo
.bother(), 22); // just so the code is not dead, basically