2014-07-22 05:27:46 -04:00
|
|
|
// Test that, when a variable of type `&T` is captured inside a proc,
|
|
|
|
|
// we correctly infer/require that its lifetime is 'static.
|
|
|
|
|
|
2014-11-26 08:12:18 -05:00
|
|
|
fn foo<F:FnOnce()+'static>(_p: F) { }
|
2014-07-22 05:27:46 -04:00
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
static i: isize = 3;
|
2014-07-22 05:27:46 -04:00
|
|
|
|
|
|
|
|
fn capture_local() {
|
2015-01-31 17:23:42 +01:00
|
|
|
let x = 3;
|
2014-07-22 05:27:46 -04:00
|
|
|
let y = &x; //~ ERROR `x` does not live long enough
|
2014-11-26 08:12:18 -05:00
|
|
|
foo(move|| {
|
2014-07-22 05:27:46 -04:00
|
|
|
let _a = *y;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn capture_static() {
|
|
|
|
|
// Legal because &i can have static lifetime:
|
|
|
|
|
let y = &i;
|
2014-11-26 08:12:18 -05:00
|
|
|
foo(move|| {
|
2014-07-22 05:27:46 -04:00
|
|
|
let _a = *y;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() { }
|