]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-infer-proc-static-upvar.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / regions / regions-infer-proc-static-upvar.rs
1 // Test that, when a variable of type `&T` is captured inside a proc,
2 // we correctly infer/require that its lifetime is 'static.
3
4 fn foo<F:FnOnce()+'static>(_p: F) { }
5
6 static i: isize = 3;
7
8 fn capture_local() {
9     let x = 3;
10     let y = &x; //~ ERROR `x` does not live long enough
11     foo(move|| {
12         let _a = *y;
13     });
14 }
15
16 fn capture_static() {
17     // Legal because &i can have static lifetime:
18     let y = &i;
19     foo(move|| {
20         let _a = *y;
21     });
22 }
23
24 fn main() { }