]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.rs
Auto merge of #66911 - eddyb:nicer-rustc_regions, r=matthewjasper
[rust.git] / src / test / ui / nll / closure-requirements / propagate-fail-to-approximate-longer-no-bounds.rs
1 // Similarly to escape-argument-callee, a test case where the closure
2 // requires a relationship between 2 unrelated higher-ranked regions,
3 // with no helpful relations between the HRRs and free regions.
4 //
5 // In this case, the error is reported by the closure itself. This is
6 // because it is unable to approximate the higher-ranked region `'x`,
7 // as it knows of no relationships between `'x` and any
8 // non-higher-ranked regions.
9
10 // compile-flags:-Zborrowck=mir -Zverbose
11
12 #![feature(rustc_attrs)]
13
14 use std::cell::Cell;
15
16 // Callee knows that:
17 //
18 // 'b: 'y
19 //
20 // but this doesn't really help us in proving that `'x: 'y`, so closure gets an error.
21 fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
22 where
23     F: for<'x, 'y> FnMut(
24         &Cell<&'y &'b u32>, // shows that 'b: 'y
25         &Cell<&'x u32>,
26         &Cell<&'y u32>,
27     ),
28 {
29 }
30
31 fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
32
33 #[rustc_regions]
34 fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
35     establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
36         // Only works if 'x: 'y:
37         demand_y(x, y, x.get())
38         //~^ ERROR
39     });
40 }
41
42 fn main() {}