]>
git.proxmox.com Git - rustc.git/blob - tests/ui/nll/closure-requirements/propagate-approximated-ref.rs
1 // Rather convoluted setup where we infer a relationship between two
2 // free regions in the closure signature (`'a` and `'b`) on the basis
3 // of a relationship between two bound regions (`'x` and `'y`).
5 // The idea is that, thanks to invoking `demand_y`, `'x: 'y` must
6 // hold, where `'x` and `'y` are bound regions. The closure can't
7 // prove that directly, and because `'x` and `'y` are bound it cannot
8 // ask the caller to prove it either. But it has bounds on `'x` and
9 // `'y` in terms of `'a` and `'b`, and it can propagate a relationship
10 // between `'a` and `'b` to the caller.
12 // Note: the use of `Cell` here is to introduce invariance. One less
15 // compile-flags:-Zverbose
17 #![feature(rustc_attrs)]
26 // so if we are going to ensure that `'x: 'y`, then `'a: 'b` must
28 fn establish_relationships
<'a
, 'b
, F
>(_cell_a
: &Cell
<&'a
u32>, _cell_b
: &Cell
<&'b
u32>, _closure
: F
)
31 &Cell
<&'a
&'x
u32>, // shows that 'x: 'a
32 &Cell
<&'y
&'b
u32>, // shows that 'b: 'y
39 fn demand_y
<'x
, 'y
>(_cell_x
: &Cell
<&'x
u32>, _cell_y
: &Cell
<&'y
u32>, _y
: &'y
u32) {}
42 fn supply
<'a
, 'b
>(cell_a
: Cell
<&'a
u32>, cell_b
: Cell
<&'b
u32>) {
43 establish_relationships(&cell_a
, &cell_b
, |_outlives1
, _outlives2
, x
, y
| {
44 // Only works if 'x: 'y:
45 demand_y(x
, y
, x
.get())
46 //~^ ERROR lifetime may not live long enough