diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25ea2ef..4cc37d9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,7 +67,8 @@ jobs: - name: Run compile tests if: ${{ matrix.os == 'ubuntu-18.04' && matrix.lua == 'lua53' }} run: | - cargo test --release --no-default-features --features "lua53 vendored async send" -- --ignored + cargo test --release --no-default-features --features "${{ matrix.lua }} vendored" -- --ignored + cargo test --release --no-default-features --features "${{ matrix.lua }} vendored async send" -- --ignored shell: bash rustfmt: diff --git a/tests/compile.rs b/tests/compile.rs new file mode 100644 index 0000000..e4d822a --- /dev/null +++ b/tests/compile.rs @@ -0,0 +1,24 @@ +#[test] +#[ignore] +fn test_compilation() { + let t = trybuild::TestCases::new(); + + t.compile_fail("tests/compile/function_borrow.rs"); + t.compile_fail("tests/compile/lua_norefunwindsafe.rs"); + t.compile_fail("tests/compile/ref_nounwindsafe.rs"); + t.compile_fail("tests/compile/scope_callback_capture.rs"); + t.compile_fail("tests/compile/scope_callback_inner.rs"); + t.compile_fail("tests/compile/scope_callback_outer.rs"); + t.compile_fail("tests/compile/scope_invariance.rs"); + t.compile_fail("tests/compile/scope_mutable_aliasing.rs"); + t.compile_fail("tests/compile/scope_userdata_borrow.rs"); + t.compile_fail("tests/compile/static_callback_args.rs"); + + #[cfg(feature = "async")] + t.compile_fail("tests/compile/async_nonstatic_userdata.rs"); + + #[cfg(feature = "send")] + t.compile_fail("tests/compile/non_send.rs"); + #[cfg(not(feature = "send"))] + t.pass("tests/compile/non_send.rs"); +} diff --git a/tests/compile_fail/async_nonstatic_userdata.rs b/tests/compile/async_nonstatic_userdata.rs similarity index 100% rename from tests/compile_fail/async_nonstatic_userdata.rs rename to tests/compile/async_nonstatic_userdata.rs diff --git a/tests/compile_fail/async_nonstatic_userdata.stderr b/tests/compile/async_nonstatic_userdata.stderr similarity index 86% rename from tests/compile_fail/async_nonstatic_userdata.stderr rename to tests/compile/async_nonstatic_userdata.stderr index 25e9e5d..a604cd4 100644 --- a/tests/compile_fail/async_nonstatic_userdata.stderr +++ b/tests/compile/async_nonstatic_userdata.stderr @@ -1,5 +1,5 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements - --> $DIR/scope_async_userdata.rs:11:72 + --> $DIR/async_nonstatic_userdata.rs:11:72 | 11 | methods.add_async_method("print", |_, data, ()| async move { | ________________________________________________________________________^ @@ -9,12 +9,12 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen | |_____________^ | note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 9:10... - --> $DIR/scope_async_userdata.rs:9:10 + --> $DIR/async_nonstatic_userdata.rs:9:10 | 9 | impl<'a> UserData for MyUserData<'a> { | ^^ note: ...so that the types are compatible - --> $DIR/scope_async_userdata.rs:11:72 + --> $DIR/async_nonstatic_userdata.rs:11:72 | 11 | methods.add_async_method("print", |_, data, ()| async move { | ________________________________________________________________________^ @@ -25,12 +25,12 @@ note: ...so that the types are compatible = note: expected `main::MyUserData<'_>` found `main::MyUserData<'a>` note: but, the lifetime must be valid for the lifetime `'lua` as defined on the method body at 10:24... - --> $DIR/scope_async_userdata.rs:10:24 + --> $DIR/async_nonstatic_userdata.rs:10:24 | 10 | fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { | ^^^^ note: ...so that the type `impl std::future::Future` will meet its required lifetime bounds - --> $DIR/scope_async_userdata.rs:11:21 + --> $DIR/async_nonstatic_userdata.rs:11:21 | 11 | methods.add_async_method("print", |_, data, ()| async move { | ^^^^^^^^^^^^^^^^ diff --git a/tests/compile_fail/function_borrow.rs b/tests/compile/function_borrow.rs similarity index 100% rename from tests/compile_fail/function_borrow.rs rename to tests/compile/function_borrow.rs diff --git a/tests/compile_fail/function_borrow.stderr b/tests/compile/function_borrow.stderr similarity index 100% rename from tests/compile_fail/function_borrow.stderr rename to tests/compile/function_borrow.stderr diff --git a/tests/compile_fail/lua_norefunwindsafe.rs b/tests/compile/lua_norefunwindsafe.rs similarity index 100% rename from tests/compile_fail/lua_norefunwindsafe.rs rename to tests/compile/lua_norefunwindsafe.rs diff --git a/tests/compile_fail/lua_norefunwindsafe.stderr b/tests/compile/lua_norefunwindsafe.stderr similarity index 91% rename from tests/compile_fail/lua_norefunwindsafe.stderr rename to tests/compile/lua_norefunwindsafe.stderr index 7d03bed..6dff810 100644 --- a/tests/compile_fail/lua_norefunwindsafe.stderr +++ b/tests/compile/lua_norefunwindsafe.stderr @@ -8,4 +8,4 @@ error[E0277]: the type `std::cell::UnsafeCell<()>` may contain interior mutabili = note: required because it appears within the type `std::marker::PhantomData>` = note: required because it appears within the type `mlua::lua::Lua` = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&mlua::lua::Lua` - = note: required because it appears within the type `[closure@$DIR/tests/compile_fail/lua_norefunwindsafe.rs:7:18: 7:48 lua:&mlua::lua::Lua]` + = note: required because it appears within the type `[closure@$DIR/tests/compile/lua_norefunwindsafe.rs:7:18: 7:48 lua:&mlua::lua::Lua]` diff --git a/tests/compile/non_send.rs b/tests/compile/non_send.rs new file mode 100644 index 0000000..fe030a5 --- /dev/null +++ b/tests/compile/non_send.rs @@ -0,0 +1,17 @@ +use std::cell::Cell; +use std::rc::Rc; + +use mlua::{Lua, Result}; + +fn main() -> Result<()> { + let lua = Lua::new(); + + let data = Rc::new(Cell::new(0)); + + lua.create_function(move |_, ()| { + Ok(data.get()) + })? + .call::<_, i32>(())?; + + Ok(()) +} diff --git a/tests/compile/non_send.stderr b/tests/compile/non_send.stderr new file mode 100644 index 0000000..e830d33 --- /dev/null +++ b/tests/compile/non_send.stderr @@ -0,0 +1,14 @@ +error[E0277]: `std::rc::Rc>` cannot be sent between threads safely + --> $DIR/non_send.rs:11:9 + | +11 | lua.create_function(move |_, ()| { + | _________^^^^^^^^^^^^^^^_- + | | | + | | `std::rc::Rc>` cannot be sent between threads safely +12 | | Ok(data.get()) +13 | | })? + | |_____- within this `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6 data:std::rc::Rc>]` + | + = help: within `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6 data:std::rc::Rc>]`, the trait `std::marker::Send` is not implemented for `std::rc::Rc>` + = note: required because it appears within the type `[closure@$DIR/tests/compile/non_send.rs:11:25: 13:6 data:std::rc::Rc>]` + = 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 data:std::rc::Rc>]` diff --git a/tests/compile_fail/ref_nounwindsafe.rs b/tests/compile/ref_nounwindsafe.rs similarity index 100% rename from tests/compile_fail/ref_nounwindsafe.rs rename to tests/compile/ref_nounwindsafe.rs diff --git a/tests/compile_fail/ref_nounwindsafe.stderr b/tests/compile/ref_nounwindsafe.stderr similarity index 92% rename from tests/compile_fail/ref_nounwindsafe.stderr rename to tests/compile/ref_nounwindsafe.stderr index 2d78b81..0b1b649 100644 --- a/tests/compile_fail/ref_nounwindsafe.stderr +++ b/tests/compile/ref_nounwindsafe.stderr @@ -10,4 +10,4 @@ error[E0277]: the type `std::cell::UnsafeCell<()>` may contain interior mutabili = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&mlua::lua::Lua` = note: required because it appears within the type `mlua::types::LuaRef<'_>` = note: required because it appears within the type `mlua::table::Table<'_>` - = note: required because it appears within the type `[closure@$DIR/tests/compile_fail/ref_nounwindsafe.rs:8:18: 8:54 table:mlua::table::Table<'_>]` + = note: required because it appears within the type `[closure@$DIR/tests/compile/ref_nounwindsafe.rs:8:18: 8:54 table:mlua::table::Table<'_>]` diff --git a/tests/compile_fail/scope_callback_capture.rs b/tests/compile/scope_callback_capture.rs similarity index 100% rename from tests/compile_fail/scope_callback_capture.rs rename to tests/compile/scope_callback_capture.rs diff --git a/tests/compile_fail/scope_callback_capture.stderr b/tests/compile/scope_callback_capture.stderr similarity index 100% rename from tests/compile_fail/scope_callback_capture.stderr rename to tests/compile/scope_callback_capture.stderr diff --git a/tests/compile_fail/scope_callback_inner.rs b/tests/compile/scope_callback_inner.rs similarity index 100% rename from tests/compile_fail/scope_callback_inner.rs rename to tests/compile/scope_callback_inner.rs diff --git a/tests/compile_fail/scope_callback_inner.stderr b/tests/compile/scope_callback_inner.stderr similarity index 100% rename from tests/compile_fail/scope_callback_inner.stderr rename to tests/compile/scope_callback_inner.stderr diff --git a/tests/compile_fail/scope_callback_outer.rs b/tests/compile/scope_callback_outer.rs similarity index 100% rename from tests/compile_fail/scope_callback_outer.rs rename to tests/compile/scope_callback_outer.rs diff --git a/tests/compile_fail/scope_callback_outer.stderr b/tests/compile/scope_callback_outer.stderr similarity index 100% rename from tests/compile_fail/scope_callback_outer.stderr rename to tests/compile/scope_callback_outer.stderr diff --git a/tests/compile_fail/scope_invariance.rs b/tests/compile/scope_invariance.rs similarity index 100% rename from tests/compile_fail/scope_invariance.rs rename to tests/compile/scope_invariance.rs diff --git a/tests/compile_fail/scope_invariance.stderr b/tests/compile/scope_invariance.stderr similarity index 100% rename from tests/compile_fail/scope_invariance.stderr rename to tests/compile/scope_invariance.stderr diff --git a/tests/compile_fail/scope_mutable_aliasing.rs b/tests/compile/scope_mutable_aliasing.rs similarity index 100% rename from tests/compile_fail/scope_mutable_aliasing.rs rename to tests/compile/scope_mutable_aliasing.rs diff --git a/tests/compile_fail/scope_mutable_aliasing.stderr b/tests/compile/scope_mutable_aliasing.stderr similarity index 100% rename from tests/compile_fail/scope_mutable_aliasing.stderr rename to tests/compile/scope_mutable_aliasing.stderr diff --git a/tests/compile_fail/scope_userdata_borrow.rs b/tests/compile/scope_userdata_borrow.rs similarity index 100% rename from tests/compile_fail/scope_userdata_borrow.rs rename to tests/compile/scope_userdata_borrow.rs diff --git a/tests/compile_fail/scope_userdata_borrow.stderr b/tests/compile/scope_userdata_borrow.stderr similarity index 100% rename from tests/compile_fail/scope_userdata_borrow.stderr rename to tests/compile/scope_userdata_borrow.stderr diff --git a/tests/compile_fail/static_callback_args.rs b/tests/compile/static_callback_args.rs similarity index 100% rename from tests/compile_fail/static_callback_args.rs rename to tests/compile/static_callback_args.rs diff --git a/tests/compile_fail/static_callback_args.stderr b/tests/compile/static_callback_args.stderr similarity index 100% rename from tests/compile_fail/static_callback_args.stderr rename to tests/compile/static_callback_args.stderr diff --git a/tests/compile_fail/userdata_borrow.rs b/tests/compile/userdata_borrow.rs similarity index 100% rename from tests/compile_fail/userdata_borrow.rs rename to tests/compile/userdata_borrow.rs diff --git a/tests/compile_fail/userdata_borrow.stderr b/tests/compile/userdata_borrow.stderr similarity index 100% rename from tests/compile_fail/userdata_borrow.stderr rename to tests/compile/userdata_borrow.stderr diff --git a/tests/compile_fail.rs b/tests/compile_fail.rs deleted file mode 100644 index 5c20a2a..0000000 --- a/tests/compile_fail.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[test] -#[ignore] -fn test_compile_fail() { - let t = trybuild::TestCases::new(); - t.compile_fail("tests/compile_fail/*.rs"); -}