summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/regions-infer-proc-static-upvar.rs
blob: 5a64aa7345047d9873ea5a67449a7703447e03f4 (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
// Test that, when a variable of type `&T` is captured inside a proc,
// we correctly infer/require that its lifetime is 'static.

fn foo<F:FnOnce()+'static>(_p: F) { }

static i: isize = 3;

fn capture_local() {
    let x = 3;
    let y = &x; //~ ERROR `x` does not live long enough
    foo(move|| {
        let _a = *y;
    });
}

fn capture_static() {
    // Legal because &i can have static lifetime:
    let y = &i;
    foo(move|| {
        let _a = *y;
    });
}

fn main() { }