]>
Commit | Line | Data |
---|---|---|
ff7c6d11 XL |
1 | // Test closure that: |
2 | // | |
3 | // - takes an argument `y` | |
4 | // - stores `y` into another, longer-lived spot | |
5 | // | |
6 | // but is invoked with a spot that doesn't live long | |
7 | // enough to store `y`. | |
8 | // | |
9 | // The error is reported in the caller: invoking the closure links the | |
10 | // lifetime of the variable that is given as `y` (via subtyping) and | |
11 | // thus forces the corresponding borrow to live too long. This is | |
12 | // basically checking that the MIR type checker correctly enforces the | |
13 | // closure signature. | |
14 | ||
923072b8 | 15 | // compile-flags:-Zverbose |
ff7c6d11 XL |
16 | |
17 | #![feature(rustc_attrs)] | |
18 | ||
19 | #[rustc_regions] | |
20 | fn test() { | |
21 | let x = 44; | |
22 | let mut p = &x; | |
23 | ||
24 | { | |
25 | let y = 22; | |
26 | let mut closure = expect_sig(|p, y| *p = y); | |
27 | closure(&mut p, &y); | |
28 | //~^ ERROR `y` does not live long enough [E0597] | |
29 | } | |
30 | ||
31 | deref(p); | |
32 | } | |
33 | ||
34 | fn expect_sig<F>(f: F) -> F | |
35 | where F: for<'a, 'b> FnMut(&'a mut &'b i32, &'b i32) | |
36 | { | |
37 | f | |
38 | } | |
39 | ||
40 | fn deref(_p: &i32) { } | |
41 | ||
42 | fn main() { } |