From 967cbb53b03def731a1d2ccbea2b0bd140564b9a Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 23 Aug 2022 23:12:37 +0100 Subject: [PATCH] Update compile tests --- tests/compile/async_nonstatic_userdata.rs | 4 +- tests/compile/async_nonstatic_userdata.stderr | 55 +++++-------------- tests/compile/function_borrow.stderr | 8 +-- tests/compile/lua_norefunwindsafe.stderr | 6 +- tests/compile/non_send.stderr | 9 ++- tests/compile/ref_nounwindsafe.stderr | 6 +- tests/compile/scope_invariance.stderr | 8 +-- tests/compile/static_callback_args.stderr | 46 ++++++++-------- 8 files changed, 63 insertions(+), 79 deletions(-) diff --git a/tests/compile/async_nonstatic_userdata.rs b/tests/compile/async_nonstatic_userdata.rs index 8aede32..8b5a7cf 100644 --- a/tests/compile/async_nonstatic_userdata.rs +++ b/tests/compile/async_nonstatic_userdata.rs @@ -1,8 +1,6 @@ -use mlua::{Lua, UserData, UserDataMethods}; +use mlua::{UserData, UserDataMethods}; fn main() { - let ref lua = Lua::new(); - #[derive(Clone)] struct MyUserData<'a>(&'a i64); diff --git a/tests/compile/async_nonstatic_userdata.stderr b/tests/compile/async_nonstatic_userdata.stderr index c03a56a..ac21155 100644 --- a/tests/compile/async_nonstatic_userdata.stderr +++ b/tests/compile/async_nonstatic_userdata.stderr @@ -1,41 +1,14 @@ -error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements - --> tests/compile/async_nonstatic_userdata.rs:11:72 - | -11 | methods.add_async_method("print", |_, data, ()| async move { - | ________________________________________________________________________^ -12 | | println!("{}", data.0); -13 | | Ok(()) -14 | | }); - | |_____________^ - | -note: first, the lifetime cannot outlive the lifetime `'a` as defined here... - --> tests/compile/async_nonstatic_userdata.rs:9:10 - | -9 | impl<'a> UserData for MyUserData<'a> { - | ^^ -note: ...so that the types are compatible - --> tests/compile/async_nonstatic_userdata.rs:11:72 - | -11 | methods.add_async_method("print", |_, data, ()| async move { - | ________________________________________________________________________^ -12 | | println!("{}", data.0); -13 | | Ok(()) -14 | | }); - | |_____________^ - = note: expected `(MyUserData<'_>,)` - found `(MyUserData<'a>,)` -note: but, the lifetime must be valid for the lifetime `'lua` as defined here... - --> tests/compile/async_nonstatic_userdata.rs:10:24 - | -10 | fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { - | ^^^^ -note: ...so that the type `impl Future` will meet its required lifetime bounds... - --> tests/compile/async_nonstatic_userdata.rs:11:21 - | -11 | methods.add_async_method("print", |_, data, ()| async move { - | ^^^^^^^^^^^^^^^^ -note: ...that is required by this bound - --> src/userdata.rs - | - | MR: 'lua + Future>; - | ^^^^ +error: lifetime may not live long enough + --> tests/compile/async_nonstatic_userdata.rs:9:13 + | +7 | impl<'a> UserData for MyUserData<'a> { + | -- lifetime `'a` defined here +8 | fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { + | ---- lifetime `'lua` defined here +9 | / methods.add_async_method("print", |_, data, ()| async move { +10 | | println!("{}", data.0); +11 | | Ok(()) +12 | | }); + | |______________^ argument requires that `'a` must outlive `'lua` + | + = help: consider adding the following bound: `'a: 'lua` diff --git a/tests/compile/function_borrow.stderr b/tests/compile/function_borrow.stderr index e99c287..16a78a3 100644 --- a/tests/compile/function_borrow.stderr +++ b/tests/compile/function_borrow.stderr @@ -1,10 +1,10 @@ -error[E0373]: closure may outlive the current function, but it borrows `test`, which is owned by the current function +error[E0373]: closure may outlive the current function, but it borrows `test.0`, which is owned by the current function --> tests/compile/function_borrow.rs:9:33 | 9 | let _ = lua.create_function(|_, ()| -> Result { - | ^^^^^^^^^^^^^^^^^^^^^^ may outlive borrowed value `test` + | ^^^^^^^^^^^^^^^^^^^^^^ may outlive borrowed value `test.0` 10 | Ok(test.0) - | ------ `test` is borrowed here + | ------ `test.0` is borrowed here | note: function requires argument type to outlive `'static` --> tests/compile/function_borrow.rs:9:13 @@ -14,7 +14,7 @@ note: function requires argument type to outlive `'static` 10 | | Ok(test.0) 11 | | }); | |______^ -help: to force the closure to take ownership of `test` (and any other referenced variables), use the `move` keyword +help: to force the closure to take ownership of `test.0` (and any other referenced variables), use the `move` keyword | 9 | let _ = lua.create_function(move |_, ()| -> Result { | ++++ diff --git a/tests/compile/lua_norefunwindsafe.stderr b/tests/compile/lua_norefunwindsafe.stderr index a441ec8..ca1ad84 100644 --- a/tests/compile/lua_norefunwindsafe.stderr +++ b/tests/compile/lua_norefunwindsafe.stderr @@ -10,7 +10,11 @@ error[E0277]: the type `UnsafeCell` may contain interior mu = note: required because it appears within the type `Arc>` = note: required because it appears within the type `Lua` = note: required because of the requirements on the impl of `UnwindSafe` for `&Lua` - = note: required because it appears within the type `[closure@$DIR/tests/compile/lua_norefunwindsafe.rs:7:18: 7:48]` +note: required because it's used within this closure + --> tests/compile/lua_norefunwindsafe.rs:7:18 + | +7 | catch_unwind(|| lua.create_table().unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `catch_unwind` --> $RUST/std/src/panic.rs | diff --git a/tests/compile/non_send.stderr b/tests/compile/non_send.stderr index ecec24c..394b1ee 100644 --- a/tests/compile/non_send.stderr +++ b/tests/compile/non_send.stderr @@ -10,7 +10,14 @@ error[E0277]: `Rc>` cannot be sent between threads safely | |_____- within this `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6]` | = help: within `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6]`, the trait `Send` is not implemented for `Rc>` - = note: required because it appears within the type `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6]` +note: required because it's used within this closure + --> tests/compile/non_send.rs:11:25 + | +11 | lua.create_function(move |_, ()| { + | _________________________^ +12 | | Ok(data.get()) +13 | | })? + | |_____^ = note: required because of the requirements on the impl of `mlua::types::MaybeSend` for `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6]` note: required by a bound in `Lua::create_function` --> src/lua.rs diff --git a/tests/compile/ref_nounwindsafe.stderr b/tests/compile/ref_nounwindsafe.stderr index 8d3704d..abfd705 100644 --- a/tests/compile/ref_nounwindsafe.stderr +++ b/tests/compile/ref_nounwindsafe.stderr @@ -12,7 +12,11 @@ error[E0277]: the type `UnsafeCell` may contain interior mu = note: required because of the requirements on the impl of `UnwindSafe` for `&Lua` = note: required because it appears within the type `mlua::types::LuaRef<'_>` = note: required because it appears within the type `LuaTable<'_>` - = note: required because it appears within the type `[closure@$DIR/tests/compile/ref_nounwindsafe.rs:8:18: 8:54]` +note: required because it's used within this closure + --> tests/compile/ref_nounwindsafe.rs:8:18 + | +8 | catch_unwind(move || table.set("a", "b").unwrap()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `catch_unwind` --> $RUST/std/src/panic.rs | diff --git a/tests/compile/scope_invariance.stderr b/tests/compile/scope_invariance.stderr index 9c91f6a..75a058d 100644 --- a/tests/compile/scope_invariance.stderr +++ b/tests/compile/scope_invariance.stderr @@ -1,13 +1,13 @@ -error[E0373]: closure may outlive the current function, but it borrows `test`, which is owned by the current function +error[E0373]: closure may outlive the current function, but it borrows `test.field`, which is owned by the current function --> tests/compile/scope_invariance.rs:14:38 | 9 | lua.scope(|scope| { | ----- has type `&mlua::Scope<'_, '1>` ... 14 | .create_function_mut(|_, ()| { - | ^^^^^^^ may outlive borrowed value `test` + | ^^^^^^^ may outlive borrowed value `test.field` 15 | test.field = 42; - | ---------- `test` is borrowed here + | ---------- `test.field` is borrowed here | note: function requires argument type to outlive `'1` --> tests/compile/scope_invariance.rs:13:13 @@ -19,7 +19,7 @@ note: function requires argument type to outlive `'1` 17 | | Ok(()) 18 | | })? | |__________________^ -help: to force the closure to take ownership of `test` (and any other referenced variables), use the `move` keyword +help: to force the closure to take ownership of `test.field` (and any other referenced variables), use the `move` keyword | 14 | .create_function_mut(move |_, ()| { | ++++ diff --git a/tests/compile/static_callback_args.stderr b/tests/compile/static_callback_args.stderr index 0683dee..bc61fa3 100644 --- a/tests/compile/static_callback_args.stderr +++ b/tests/compile/static_callback_args.stderr @@ -1,33 +1,31 @@ error[E0597]: `lua` does not live long enough --> tests/compile/static_callback_args.rs:12:5 | -12 | / lua.create_function(|_, table: Table| { -13 | | BAD_TIME.with(|bt| { -14 | | *bt.borrow_mut() = Some(table); -15 | | }); -16 | | Ok(()) -17 | | })? - | | ^ - | | | - | |______borrowed value does not live long enough - | argument requires that `lua` is borrowed for `'static` +12 | / lua.create_function(|_, table: Table| { +13 | | BAD_TIME.with(|bt| { + | |_________- +14 | || *bt.borrow_mut() = Some(table); +15 | || }); + | ||__________- argument requires that `lua` is borrowed for `'static` +16 | | Ok(()) +17 | | })? + | |______^ borrowed value does not live long enough ... -32 | } - | - `lua` dropped here while still borrowed +32 | } + | - `lua` dropped here while still borrowed error[E0505]: cannot move out of `lua` because it is borrowed --> tests/compile/static_callback_args.rs:22:10 | -12 | / lua.create_function(|_, table: Table| { -13 | | BAD_TIME.with(|bt| { -14 | | *bt.borrow_mut() = Some(table); -15 | | }); -16 | | Ok(()) -17 | | })? - | | - - | | | - | |______borrow of `lua` occurs here - | argument requires that `lua` is borrowed for `'static` +12 | / lua.create_function(|_, table: Table| { +13 | | BAD_TIME.with(|bt| { + | |_________- +14 | || *bt.borrow_mut() = Some(table); +15 | || }); + | ||__________- argument requires that `lua` is borrowed for `'static` +16 | | Ok(()) +17 | | })? + | |______- borrow of `lua` occurs here ... -22 | drop(lua); - | ^^^ move out of `lua` occurs here +22 | drop(lua); + | ^^^ move out of `lua` occurs here