mlua/tests/compile/scope_invariance.stderr

26 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

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