summaryrefslogtreecommitdiffstats
path: root/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.rs
blob: 704a026d29b7929150f6aa7c2379eefcc4727925 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Test where we might in theory be able to see that the relationship
// between two bound regions is true within closure and hence have no
// need to propagate; but in fact we do because identity of free
// regions is erased.

// compile-flags:-Zverbose
// check-pass

#![feature(rustc_attrs)]

use std::cell::Cell;

// In theory, callee knows that:
//
// 'x: 'a
// 'a: 'y
//
// and hence could satisfy that `'x: 'y` locally. However, in our
// checking, we ignore the precise free regions that come into the
// region and just assign each position a distinct universally bound
// region. Hence, we propagate a constraint to our caller that will
// wind up being solvable.
fn establish_relationships<'a, F>(
    _cell_a: Cell<&'a u32>,
    _closure: F,
) where
    F: for<'x, 'y> FnMut(
        Cell<&'a &'x u32>, // shows that 'x: 'a
        Cell<&'y &'a u32>, // shows that 'a: 'y
        Cell<&'x u32>,
        Cell<&'y u32>,
    ),
{
}

fn demand_y<'x, 'y>(_cell_x: Cell<&'x u32>, _cell_y: Cell<&'y u32>, _y: &'y u32) {}

#[rustc_regions]
fn supply<'a>(cell_a: Cell<&'a u32>) {
    establish_relationships(
        cell_a,
        |_outlives1, _outlives2, x, y| {
            // Only works if 'x: 'y:
            let p = x.get();
            demand_y(x, y, p)
        },
    );
}

fn main() {}