]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / 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`).
4 //
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.
11 //
12 // Note: the use of `Cell` here is to introduce invariance. One less
13 // variable.
14
15 // compile-flags:-Zverbose
16
17 #![feature(rustc_attrs)]
18
19 use std::cell::Cell;
20
21 // Callee knows that:
22 //
23 // 'x: 'a
24 // 'b: 'y
25 //
26 // so if we are going to ensure that `'x: 'y`, then `'a: 'b` must
27 // hold.
28 fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
29 where
30 F: for<'x, 'y> FnMut(
31 &Cell<&'a &'x u32>, // shows that 'x: 'a
32 &Cell<&'y &'b u32>, // shows that 'b: 'y
33 &Cell<&'x u32>,
34 &Cell<&'y u32>,
35 ),
36 {
37 }
38
39 fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
40
41 #[rustc_regions]
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
47 });
48 }
49
50 fn main() {}