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