summaryrefslogtreecommitdiffstats
path: root/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.rs
blob: afe6f10a52f08fc14253849a7436bb72da72cb84 (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
// Test a case where we setup relationships like `'x: 'a` or `'a: 'x`,
// where `'x` is bound in closure type but `'a` is free. This forces
// us to approximate `'x` one way or the other.

// compile-flags:-Zverbose

#![feature(rustc_attrs)]

use std::cell::Cell;

fn foo<'a, F>(_cell: Cell<&'a u32>, _f: F)
where
    F: for<'x> FnOnce(Cell<&'a u32>, Cell<&'x u32>),
{
}

#[rustc_regions]
fn case1() {
    let a = 0;
    let cell = Cell::new(&a);
    foo(cell, |cell_a, cell_x| {
        cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
        //~^ ERROR
    })
}

#[rustc_regions]
fn case2() {
    let a = 0;
    let cell = Cell::new(&a);
    //~^ ERROR `a` does not live long enough

    // As you can see in the stderr output, this closure propoagates a
    // requirement that `'a: 'static'.
    foo(cell, |cell_a, cell_x| {
        cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
    })
}

fn main() { }