From 0fccdfed5cab4249137644a7e12fc9a58827ca5f Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 14 Apr 2023 01:09:50 +0100 Subject: [PATCH] Fix feature flags for owned types --- src/conversion.rs | 20 +++++++++++++------- src/function.rs | 7 ++++--- src/lib.rs | 2 +- src/lua.rs | 2 +- src/table.rs | 5 +++-- src/userdata.rs | 8 +++++--- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/conversion.rs b/src/conversion.rs index 4cd444b..ebd6343 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -18,7 +18,7 @@ use crate::types::{LightUserData, MaybeSend}; use crate::userdata::{AnyUserData, UserData, UserDataRef, UserDataRefMut}; use crate::value::{FromLua, IntoLua, Nil, Value}; -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] use crate::{function::OwnedFunction, table::OwnedTable, userdata::OwnedAnyUserData}; #[cfg(feature = "async")] @@ -79,7 +79,8 @@ impl<'lua> FromLua<'lua> for Table<'lua> { } } -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> IntoLua<'lua> for OwnedTable { #[inline] fn into_lua(self, lua: &'lua Lua) -> Result> { @@ -87,7 +88,8 @@ impl<'lua> IntoLua<'lua> for OwnedTable { } } -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> FromLua<'lua> for OwnedTable { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result { @@ -116,7 +118,8 @@ impl<'lua> FromLua<'lua> for Function<'lua> { } } -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> IntoLua<'lua> for OwnedFunction { #[inline] fn into_lua(self, lua: &'lua Lua) -> Result> { @@ -124,7 +127,8 @@ impl<'lua> IntoLua<'lua> for OwnedFunction { } } -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> FromLua<'lua> for OwnedFunction { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result { @@ -189,7 +193,8 @@ impl<'lua> FromLua<'lua> for AnyUserData<'lua> { } } -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> IntoLua<'lua> for OwnedAnyUserData { #[inline] fn into_lua(self, lua: &'lua Lua) -> Result> { @@ -197,7 +202,8 @@ impl<'lua> IntoLua<'lua> for OwnedAnyUserData { } } -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] impl<'lua> FromLua<'lua> for OwnedAnyUserData { #[inline] fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result { diff --git a/src/function.rs b/src/function.rs index 8e9513d..813517b 100644 --- a/src/function.rs +++ b/src/function.rs @@ -33,6 +33,7 @@ pub struct OwnedFunction(pub(crate) crate::types::LuaOwnedRef); #[cfg(feature = "unstable")] impl OwnedFunction { /// Get borrowed handle to the underlying Lua function. + #[cfg_attr(feature = "send", allow(unused))] pub const fn to_ref(&self) -> Function { Function(self.0.to_ref()) } @@ -400,8 +401,8 @@ impl<'lua> Function<'lua> { } /// Convert this handle to owned version. - #[cfg(feature = "unstable")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] + #[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] + #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] #[inline] pub fn into_owned(self) -> OwnedFunction { OwnedFunction(self.0.into_owned()) @@ -476,6 +477,6 @@ mod assertions { static_assertions::assert_not_impl_any!(Function: Send); - #[cfg(feature = "unstable")] + #[cfg(all(feature = "unstable", not(feature = "send")))] static_assertions::assert_not_impl_any!(OwnedFunction: Send); } diff --git a/src/lib.rs b/src/lib.rs index 3733aee..c81a149 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,7 +151,7 @@ pub mod serde; extern crate mlua_derive; // Unstable features -#[cfg(all(feature = "unstable", not(feature = "send")))] +#[cfg(feature = "unstable")] pub use crate::{function::OwnedFunction, table::OwnedTable, userdata::OwnedAnyUserData}; /// Create a type that implements [`AsChunk`] and can capture Rust variables. diff --git a/src/lua.rs b/src/lua.rs index 2ca7281..e5decdf 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -2472,7 +2472,7 @@ impl Lua { } } - #[cfg(feature = "unstable")] + #[cfg(all(feature = "unstable", not(feature = "send")))] pub(crate) fn adopt_owned_ref(&self, loref: crate::types::LuaOwnedRef) -> LuaRef { assert!( Arc::ptr_eq(&loref.lua.0, &self.0), diff --git a/src/table.rs b/src/table.rs index 015172d..13eeeb6 100644 --- a/src/table.rs +++ b/src/table.rs @@ -33,6 +33,7 @@ pub struct OwnedTable(pub(crate) crate::types::LuaOwnedRef); #[cfg(feature = "unstable")] impl OwnedTable { /// Get borrowed handle to the underlying Lua table. + #[cfg_attr(feature = "send", allow(unused))] pub const fn to_ref(&self) -> Table { Table(self.0.to_ref()) } @@ -584,8 +585,8 @@ impl<'lua> Table<'lua> { } /// Convert this handle to owned version. - #[cfg(feature = "unstable")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] + #[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] + #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] #[inline] pub fn into_owned(self) -> OwnedTable { OwnedTable(self.0.into_owned()) diff --git a/src/userdata.rs b/src/userdata.rs index 44de70d..c623fda 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -746,6 +746,8 @@ pub struct OwnedAnyUserData(pub(crate) crate::types::LuaOwnedRef); #[cfg(feature = "unstable")] impl OwnedAnyUserData { + /// Get borrowed handle to the underlying Lua userdata. + #[cfg_attr(feature = "send", allow(unused))] pub const fn to_ref(&self) -> AnyUserData { AnyUserData(self.0.to_ref()) } @@ -1029,8 +1031,8 @@ impl<'lua> AnyUserData<'lua> { } } - #[cfg(feature = "unstable")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] + #[cfg(all(feature = "unstable", any(not(feature = "send"), doc)))] + #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", not(feature = "send")))))] #[inline] pub fn into_owned(self) -> OwnedAnyUserData { OwnedAnyUserData(self.0.into_owned()) @@ -1285,6 +1287,6 @@ mod assertions { static_assertions::assert_not_impl_any!(AnyUserData: Send); - #[cfg(feature = "unstable")] + #[cfg(all(feature = "unstable", not(feature = "send")))] static_assertions::assert_not_impl_any!(OwnedAnyUserData: Send); }