rust/tests/ui/regions/regions-infer-proc-static-upvar.rs
2023-01-11 09:32:08 +00:00

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() { }