From c3ab89ba66daa7e5bf5d8be62d67f9c33d18928d Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 13 May 2025 23:45:46 +0100 Subject: [PATCH] Fix tests --- .github/workflows/main.yml | 4 +- src/lib.rs | 2 +- tests/compile/lua_norefunwindsafe.stderr | 80 ++++------- tests/compile/non_send.stderr | 2 +- tests/compile/ref_nounwindsafe.stderr | 151 ++++++++++++++------ tests/compile/scope_callback_capture.stderr | 2 +- tests/compile/scope_invariance.stderr | 2 +- tests/compile/scope_mutable_aliasing.stderr | 2 +- tests/compile/scope_userdata_borrow.stderr | 2 +- 9 files changed, 141 insertions(+), 106 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd12c62..f19601c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -129,8 +129,8 @@ jobs: - name: Run compile tests (macos lua54) if: ${{ matrix.os == 'macos-latest' && matrix.lua == 'lua54' }} run: | - TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored" -- --ignored - TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored,async,send,serialize,macros" -- --ignored + TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored" --tests -- --ignored + TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored,async,send,serialize,macros" --tests -- --ignored shell: bash test_with_sanitizer: diff --git a/src/lib.rs b/src/lib.rs index ce8e84f..bbf947c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -210,7 +210,7 @@ pub use mlua_derive::FromLua; /// /// You can register multiple entrypoints as required. /// -/// ``` +/// ```ignore /// use mlua::{Lua, Result, Table}; /// /// #[mlua::lua_module] diff --git a/tests/compile/lua_norefunwindsafe.stderr b/tests/compile/lua_norefunwindsafe.stderr index ea2442b..a482a8d 100644 --- a/tests/compile/lua_norefunwindsafe.stderr +++ b/tests/compile/lua_norefunwindsafe.stderr @@ -1,32 +1,28 @@ -error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary +error[E0277]: the type `UnsafeCell<*mut lua_State>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary --> tests/compile/lua_norefunwindsafe.rs:7:18 | 7 | catch_unwind(|| lua.create_table().unwrap()); - | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<*mut lua_State>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary | | | required by a bound introduced by this call | - = help: within `Lua`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell`, which is required by `{closure@$DIR/tests/compile/lua_norefunwindsafe.rs:7:18: 7:20}: UnwindSafe` -note: required because it appears within the type `lock_api::remutex::ReentrantMutex` - --> $CARGO/lock_api-0.4.12/src/remutex.rs + = help: within `mlua::types::sync::inner::ReentrantMutex`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell<*mut lua_State>` +note: required because it appears within the type `Cell<*mut lua_State>` + --> $RUST/core/src/cell.rs | - | pub struct ReentrantMutex { - | ^^^^^^^^^^^^^^ -note: required because it appears within the type `alloc::sync::ArcInner>` - --> $RUST/alloc/src/sync.rs + | pub struct Cell { + | ^^^^ +note: required because it appears within the type `mlua::state::raw::RawLua` + --> src/state/raw.rs | - | struct ArcInner { - | ^^^^^^^^ -note: required because it appears within the type `PhantomData>>` - --> $RUST/core/src/marker.rs + | pub struct RawLua { + | ^^^^^^ +note: required because it appears within the type `mlua::types::sync::inner::ReentrantMutex` + --> src/types/sync.rs | - | pub struct PhantomData; - | ^^^^^^^^^^^ -note: required because it appears within the type `Arc>` - --> $RUST/alloc/src/sync.rs - | - | pub struct Arc< - | ^^^ + | pub(crate) struct ReentrantMutex(T); + | ^^^^^^^^^^^^^^ + = note: required for `Rc>` to implement `RefUnwindSafe` note: required because it appears within the type `Lua` --> src/state.rs | @@ -44,45 +40,27 @@ note: required by a bound in `std::panic::catch_unwind` | pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { | ^^^^^^^^^^ required by this bound in `catch_unwind` -error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary +error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary --> tests/compile/lua_norefunwindsafe.rs:7:18 | 7 | catch_unwind(|| lua.create_table().unwrap()); - | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary | | | required by a bound introduced by this call | - = help: within `Lua`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell`, which is required by `{closure@$DIR/tests/compile/lua_norefunwindsafe.rs:7:18: 7:20}: UnwindSafe` -note: required because it appears within the type `Cell` - --> $RUST/core/src/cell.rs + = help: the trait `RefUnwindSafe` is not implemented for `UnsafeCell` + = note: required for `Rc>` to implement `RefUnwindSafe` +note: required because it appears within the type `mlua::state::raw::RawLua` + --> src/state/raw.rs | - | pub struct Cell { - | ^^^^ -note: required because it appears within the type `lock_api::remutex::RawReentrantMutex` - --> $CARGO/lock_api-0.4.12/src/remutex.rs + | pub struct RawLua { + | ^^^^^^ +note: required because it appears within the type `mlua::types::sync::inner::ReentrantMutex` + --> src/types/sync.rs | - | pub struct RawReentrantMutex { - | ^^^^^^^^^^^^^^^^^ -note: required because it appears within the type `lock_api::remutex::ReentrantMutex` - --> $CARGO/lock_api-0.4.12/src/remutex.rs - | - | pub struct ReentrantMutex { - | ^^^^^^^^^^^^^^ -note: required because it appears within the type `alloc::sync::ArcInner>` - --> $RUST/alloc/src/sync.rs - | - | struct ArcInner { - | ^^^^^^^^ -note: required because it appears within the type `PhantomData>>` - --> $RUST/core/src/marker.rs - | - | pub struct PhantomData; - | ^^^^^^^^^^^ -note: required because it appears within the type `Arc>` - --> $RUST/alloc/src/sync.rs - | - | pub struct Arc< - | ^^^ + | pub(crate) struct ReentrantMutex(T); + | ^^^^^^^^^^^^^^ + = note: required for `Rc>` to implement `RefUnwindSafe` note: required because it appears within the type `Lua` --> src/state.rs | diff --git a/tests/compile/non_send.stderr b/tests/compile/non_send.stderr index c7e28da..c94b720 100644 --- a/tests/compile/non_send.stderr +++ b/tests/compile/non_send.stderr @@ -8,7 +8,7 @@ error[E0277]: `Rc>` cannot be sent between threads safely | | within this `{closure@$DIR/tests/compile/non_send.rs:11:25: 11:37}` | required by a bound introduced by this call | - = help: within `{closure@$DIR/tests/compile/non_send.rs:11:25: 11:37}`, the trait `Send` is not implemented for `Rc>`, which is required by `{closure@$DIR/tests/compile/non_send.rs:11:25: 11:37}: MaybeSend` + = help: within `{closure@$DIR/tests/compile/non_send.rs:11:25: 11:37}`, the trait `Send` is not implemented for `Rc>` note: required because it's used within this closure --> tests/compile/non_send.rs:11:25 | diff --git a/tests/compile/ref_nounwindsafe.stderr b/tests/compile/ref_nounwindsafe.stderr index 39e7081..048f9d3 100644 --- a/tests/compile/ref_nounwindsafe.stderr +++ b/tests/compile/ref_nounwindsafe.stderr @@ -1,38 +1,38 @@ -error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary +error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary --> tests/compile/ref_nounwindsafe.rs:8:18 | 8 | catch_unwind(move || table.set("a", "b").unwrap()); - | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary | | | required by a bound introduced by this call | - = help: within `alloc::sync::ArcInner>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell`, which is required by `{closure@$DIR/tests/compile/ref_nounwindsafe.rs:8:18: 8:25}: UnwindSafe` -note: required because it appears within the type `lock_api::remutex::ReentrantMutex` - --> $CARGO/lock_api-0.4.12/src/remutex.rs + = help: within `rc::RcInner>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell` +note: required because it appears within the type `Cell` + --> $RUST/core/src/cell.rs | - | pub struct ReentrantMutex { - | ^^^^^^^^^^^^^^ -note: required because it appears within the type `alloc::sync::ArcInner>` - --> $RUST/alloc/src/sync.rs + | pub struct Cell { + | ^^^^ +note: required because it appears within the type `rc::RcInner>` + --> $RUST/alloc/src/rc.rs | - | struct ArcInner { - | ^^^^^^^^ - = note: required for `NonNull>>` to implement `UnwindSafe` -note: required because it appears within the type `std::sync::Weak>` - --> $RUST/alloc/src/sync.rs + | struct RcInner { + | ^^^^^^^ + = note: required for `NonNull>>` to implement `UnwindSafe` +note: required because it appears within the type `std::rc::Weak>` + --> $RUST/alloc/src/rc.rs | | pub struct Weak< | ^^^^ -note: required because it appears within the type `mlua::state::WeakLua` +note: required because it appears within the type `WeakLua` --> src/state.rs | - | pub(crate) struct WeakLua(XWeak>); - | ^^^^^^^ -note: required because it appears within the type `mlua::types::ValueRef` - --> src/types.rs + | pub struct WeakLua(XWeak>); + | ^^^^^^^ +note: required because it appears within the type `mlua::types::value_ref::ValueRef` + --> src/types/value_ref.rs | - | pub(crate) struct ValueRef { - | ^^^^^^^^ + | pub struct ValueRef { + | ^^^^^^^^ note: required because it appears within the type `LuaTable` --> src/table.rs | @@ -49,51 +49,108 @@ note: required by a bound in `std::panic::catch_unwind` | pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { | ^^^^^^^^^^ required by this bound in `catch_unwind` -error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary +error[E0277]: the type `UnsafeCell<*mut lua_State>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary --> tests/compile/ref_nounwindsafe.rs:8:18 | 8 | catch_unwind(move || table.set("a", "b").unwrap()); - | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<*mut lua_State>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary | | | required by a bound introduced by this call | - = help: within `alloc::sync::ArcInner>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell`, which is required by `{closure@$DIR/tests/compile/ref_nounwindsafe.rs:8:18: 8:25}: UnwindSafe` -note: required because it appears within the type `Cell` + = help: within `rc::RcInner>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell<*mut lua_State>` +note: required because it appears within the type `Cell<*mut lua_State>` --> $RUST/core/src/cell.rs | | pub struct Cell { | ^^^^ -note: required because it appears within the type `lock_api::remutex::RawReentrantMutex` - --> $CARGO/lock_api-0.4.12/src/remutex.rs +note: required because it appears within the type `mlua::state::raw::RawLua` + --> src/state/raw.rs | - | pub struct RawReentrantMutex { - | ^^^^^^^^^^^^^^^^^ -note: required because it appears within the type `lock_api::remutex::ReentrantMutex` - --> $CARGO/lock_api-0.4.12/src/remutex.rs + | pub struct RawLua { + | ^^^^^^ +note: required because it appears within the type `mlua::types::sync::inner::ReentrantMutex` + --> src/types/sync.rs | - | pub struct ReentrantMutex { - | ^^^^^^^^^^^^^^ -note: required because it appears within the type `alloc::sync::ArcInner>` - --> $RUST/alloc/src/sync.rs + | pub(crate) struct ReentrantMutex(T); + | ^^^^^^^^^^^^^^ +note: required because it appears within the type `rc::RcInner>` + --> $RUST/alloc/src/rc.rs | - | struct ArcInner { - | ^^^^^^^^ - = note: required for `NonNull>>` to implement `UnwindSafe` -note: required because it appears within the type `std::sync::Weak>` - --> $RUST/alloc/src/sync.rs + | struct RcInner { + | ^^^^^^^ + = note: required for `NonNull>>` to implement `UnwindSafe` +note: required because it appears within the type `std::rc::Weak>` + --> $RUST/alloc/src/rc.rs | | pub struct Weak< | ^^^^ -note: required because it appears within the type `mlua::state::WeakLua` +note: required because it appears within the type `WeakLua` --> src/state.rs | - | pub(crate) struct WeakLua(XWeak>); - | ^^^^^^^ -note: required because it appears within the type `mlua::types::ValueRef` - --> src/types.rs + | pub struct WeakLua(XWeak>); + | ^^^^^^^ +note: required because it appears within the type `mlua::types::value_ref::ValueRef` + --> src/types/value_ref.rs | - | pub(crate) struct ValueRef { - | ^^^^^^^^ + | pub struct ValueRef { + | ^^^^^^^^ +note: required because it appears within the type `LuaTable` + --> src/table.rs + | + | pub struct Table(pub(crate) ValueRef); + | ^^^^^ +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 `std::panic::catch_unwind` + --> $RUST/std/src/panic.rs + | + | pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { + | ^^^^^^^^^^ required by this bound in `catch_unwind` + +error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary + --> tests/compile/ref_nounwindsafe.rs:8:18 + | +8 | catch_unwind(move || table.set("a", "b").unwrap()); + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary + | | + | required by a bound introduced by this call + | + = help: the trait `RefUnwindSafe` is not implemented for `UnsafeCell` + = note: required for `Rc>` to implement `RefUnwindSafe` +note: required because it appears within the type `mlua::state::raw::RawLua` + --> src/state/raw.rs + | + | pub struct RawLua { + | ^^^^^^ +note: required because it appears within the type `mlua::types::sync::inner::ReentrantMutex` + --> src/types/sync.rs + | + | pub(crate) struct ReentrantMutex(T); + | ^^^^^^^^^^^^^^ +note: required because it appears within the type `rc::RcInner>` + --> $RUST/alloc/src/rc.rs + | + | struct RcInner { + | ^^^^^^^ + = note: required for `NonNull>>` to implement `UnwindSafe` +note: required because it appears within the type `std::rc::Weak>` + --> $RUST/alloc/src/rc.rs + | + | pub struct Weak< + | ^^^^ +note: required because it appears within the type `WeakLua` + --> src/state.rs + | + | pub struct WeakLua(XWeak>); + | ^^^^^^^ +note: required because it appears within the type `mlua::types::value_ref::ValueRef` + --> src/types/value_ref.rs + | + | pub struct ValueRef { + | ^^^^^^^^ note: required because it appears within the type `LuaTable` --> src/table.rs | diff --git a/tests/compile/scope_callback_capture.stderr b/tests/compile/scope_callback_capture.stderr index a699391..94844dc 100644 --- a/tests/compile/scope_callback_capture.stderr +++ b/tests/compile/scope_callback_capture.stderr @@ -2,7 +2,7 @@ error[E0373]: closure may outlive the current function, but it borrows `inner`, --> tests/compile/scope_callback_capture.rs:7:43 | 5 | lua.scope(|scope| { - | ----- has type `&'1 mut mlua::scope::Scope<'1, '_>` + | ----- has type `&'1 mlua::Scope<'1, '_>` 6 | let mut inner: Option = None; 7 | let f = scope.create_function_mut(|_, t: Table| { | ^^^^^^^^^^^^^ may outlive borrowed value `inner` diff --git a/tests/compile/scope_invariance.stderr b/tests/compile/scope_invariance.stderr index 91158aa..a3f218d 100644 --- a/tests/compile/scope_invariance.stderr +++ b/tests/compile/scope_invariance.stderr @@ -2,7 +2,7 @@ error[E0373]: closure may outlive the current function, but it borrows `test.fie --> tests/compile/scope_invariance.rs:13:39 | 9 | lua.scope(|scope| { - | ----- has type `&'1 mut mlua::scope::Scope<'1, '_>` + | ----- has type `&'1 mlua::Scope<'1, '_>` ... 13 | scope.create_function_mut(|_, ()| { | ^^^^^^^ may outlive borrowed value `test.field` diff --git a/tests/compile/scope_mutable_aliasing.stderr b/tests/compile/scope_mutable_aliasing.stderr index 362cf91..e6e57f1 100644 --- a/tests/compile/scope_mutable_aliasing.stderr +++ b/tests/compile/scope_mutable_aliasing.stderr @@ -2,7 +2,7 @@ error[E0499]: cannot borrow `i` as mutable more than once at a time --> tests/compile/scope_mutable_aliasing.rs:12:51 | 10 | lua.scope(|scope| { - | ----- has type `&mut mlua::scope::Scope<'_, '1>` + | ----- has type `&mlua::Scope<'_, '1>` 11 | let _a = scope.create_userdata(MyUserData(&mut i)).unwrap(); | ----------------------------------------- | | | diff --git a/tests/compile/scope_userdata_borrow.stderr b/tests/compile/scope_userdata_borrow.stderr index 043a99b..43025dd 100644 --- a/tests/compile/scope_userdata_borrow.stderr +++ b/tests/compile/scope_userdata_borrow.stderr @@ -2,7 +2,7 @@ error[E0597]: `ibad` does not live long enough --> tests/compile/scope_userdata_borrow.rs:15:46 | 11 | lua.scope(|scope| { - | ----- has type `&mut mlua::scope::Scope<'_, '1>` + | ----- has type `&mlua::Scope<'_, '1>` ... 14 | let ibad = 42; | ---- binding `ibad` declared here