mlua/tests/compile/scope_callback_inner.stderr

43 lines
1.7 KiB
Plaintext
Raw Normal View History

2020-07-27 05:49:01 -04:00
error[E0521]: borrowed data escapes outside of closure
2021-11-27 08:42:22 -05:00
--> tests/compile/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
2021-11-27 08:42:22 -05:00
--> tests/compile/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| {
2022-04-13 09:30:52 -04:00
| ----- has type `&mlua::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`
2021-11-27 08:42:22 -05:00
--> tests/compile/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| {
2021-11-27 08:42:22 -05:00
| ++++