2014-07-22 09:27:46 +00: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 13:12:18 +00:00
|
|
|
fn foo<F:FnOnce()+'static>(_p: F) { }
|
2014-07-22 09:27:46 +00:00
|
|
|
|
2015-01-08 10:54:35 +00:00
|
|
|
static i: isize = 3;
|
2014-07-22 09:27:46 +00:00
|
|
|
|
|
|
|
fn capture_local() {
|
2015-01-31 16:23:42 +00:00
|
|
|
let x = 3;
|
2014-07-22 09:27:46 +00:00
|
|
|
let y = &x; //~ ERROR `x` does not live long enough
|
2014-11-26 13:12:18 +00:00
|
|
|
foo(move|| {
|
2014-07-22 09:27:46 +00:00
|
|
|
let _a = *y;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn capture_static() {
|
|
|
|
// Legal because &i can have static lifetime:
|
|
|
|
let y = &i;
|
2014-11-26 13:12:18 +00:00
|
|
|
foo(move|| {
|
2014-07-22 09:27:46 +00:00
|
|
|
let _a = *y;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|