2020-05-06 20:18:56 -04:00
|
|
|
error[E0373]: closure may outlive the current function, but it borrows `test`, which is owned by the current function
|
|
|
|
--> $DIR/scope_invariance.rs:14:38
|
|
|
|
|
|
|
|
|
9 | lua.scope(|scope| {
|
2020-12-29 18:20:06 -05:00
|
|
|
| ----- has type `&Scope<'_, '1>`
|
2020-05-06 20:18:56 -04:00
|
|
|
...
|
|
|
|
14 | .create_function_mut(|_, ()| {
|
|
|
|
| ^^^^^^^ may outlive borrowed value `test`
|
|
|
|
15 | test.field = 42;
|
2021-09-15 19:49:17 -04:00
|
|
|
| ---------- `test` is borrowed here
|
2020-05-06 20:18:56 -04:00
|
|
|
|
|
|
|
|
note: function requires argument type to outlive `'1`
|
|
|
|
--> $DIR/scope_invariance.rs:13:13
|
|
|
|
|
|
|
|
|
13 | / scope
|
|
|
|
14 | | .create_function_mut(|_, ()| {
|
|
|
|
15 | | test.field = 42;
|
|
|
|
16 | | //~^ error: `test` does not live long enough
|
|
|
|
17 | | Ok(())
|
|
|
|
18 | | })?
|
|
|
|
| |__________________^
|
|
|
|
help: to force the closure to take ownership of `test` (and any other referenced variables), use the `move` keyword
|
|
|
|
|
|
|
|
|
14 | .create_function_mut(move |_, ()| {
|
|
|
|
| ^^^^^^^^^^^^
|