mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
25 lines
484 B
Rust
25 lines
484 B
Rust
// Test that, when a variable of type `&T` is captured inside a proc,
|
|
// we correctly infer/require that its lifetime is 'static.
|
|
|
|
fn foo<F:FnOnce()+'static>(_p: F) { }
|
|
|
|
static i: isize = 3;
|
|
|
|
fn capture_local() {
|
|
let x = 3;
|
|
let y = &x; //~ ERROR `x` does not live long enough
|
|
foo(move|| {
|
|
let _a = *y;
|
|
});
|
|
}
|
|
|
|
fn capture_static() {
|
|
// Legal because &i can have static lifetime:
|
|
let y = &i;
|
|
foo(move|| {
|
|
let _a = *y;
|
|
});
|
|
}
|
|
|
|
fn main() { }
|