2020-07-27 05:49:01 -04:00
|
|
|
error[E0521]: borrowed data escapes outside of closure
|
|
|
|
--> $DIR/scope_callback_inner.rs:7:17
|
2020-05-06 20:18:56 -04:00
|
|
|
|
|
|
|
|
5 | lua.scope(|scope| {
|
2020-07-27 05:49:01 -04:00
|
|
|
| -----
|
|
|
|
| |
|
|
|
|
| `scope` declared here, outside of the closure body
|
|
|
|
| `scope` is a reference that is only valid in the closure body
|
|
|
|
6 | let mut inner: Option<Table> = None;
|
|
|
|
7 | let f = scope
|
|
|
|
| _________________^
|
2020-05-06 20:18:56 -04:00
|
|
|
8 | | .create_function_mut(|_, t: Table| {
|
2020-07-27 05:49:01 -04:00
|
|
|
9 | | inner = Some(t);
|
|
|
|
10 | | Ok(())
|
|
|
|
11 | | })?;
|
|
|
|
| |______________^ `scope` escapes the closure body here
|
|
|
|
|
|
|
|
error[E0373]: closure may outlive the current function, but it borrows `inner`, which is owned by the current function
|
|
|
|
--> $DIR/scope_callback_inner.rs:8:34
|
2020-05-06 20:18:56 -04:00
|
|
|
|
|
2020-07-27 05:49:01 -04:00
|
|
|
5 | lua.scope(|scope| {
|
2020-12-29 18:20:06 -05:00
|
|
|
| ----- has type `&Scope<'_, '2>`
|
2020-07-27 05:49:01 -04:00
|
|
|
...
|
|
|
|
8 | .create_function_mut(|_, t: Table| {
|
|
|
|
| ^^^^^^^^^^^^^ may outlive borrowed value `inner`
|
|
|
|
9 | inner = Some(t);
|
|
|
|
| ----- `inner` is borrowed here
|
2020-05-06 20:18:56 -04:00
|
|
|
|
|
2020-07-27 05:49:01 -04:00
|
|
|
note: function requires argument type to outlive `'2`
|
|
|
|
--> $DIR/scope_callback_inner.rs:7:17
|
2020-05-06 20:18:56 -04:00
|
|
|
|
|
2020-07-27 05:49:01 -04:00
|
|
|
7 | let f = scope
|
|
|
|
| _________________^
|
2020-05-06 20:18:56 -04:00
|
|
|
8 | | .create_function_mut(|_, t: Table| {
|
2020-07-27 05:49:01 -04:00
|
|
|
9 | | inner = Some(t);
|
|
|
|
10 | | Ok(())
|
|
|
|
11 | | })?;
|
|
|
|
| |______________^
|
|
|
|
help: to force the closure to take ownership of `inner` (and any other referenced variables), use the `move` keyword
|
|
|
|
|
|
|
|
|
8 | .create_function_mut(move |_, t: Table| {
|
|
|
|
| ^^^^^^^^^^^^^^^^^^
|