summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/user-annotations/closure-substs.rs
blob: f7af54e8df44a148e588b4d9c2c91c3198301502 (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
// Test that we enforce user-provided type annotations on closures.

fn foo<'a>() {
    // Here `x` is free in the closure sig:
    |x: &'a i32| -> &'static i32 {
        return x; //~ ERROR lifetime may not live long enough
    };
}

fn foo1() {
    // Here `x` is bound in the closure sig:
    |x: &i32| -> &'static i32 {
        return x; //~ ERROR lifetime may not live long enough
    };
}

fn bar<'a>() {
    // Here `x` is free in the closure sig:
    |x: &'a i32, b: fn(&'static i32)| {
        b(x); //~ ERROR lifetime may not live long enough
    };
}

fn bar1() {
    // Here `x` is bound in the closure sig:
    |x: &i32, b: fn(&'static i32)| {
        b(x); //~ ERROR borrowed data escapes outside of closure
    };
}

fn main() {}