Skip to content

Commit 145c5b3

Browse files
committed
Fix FromLua derive proc macro to cover more cases
1 parent e97e69a commit 145c5b3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

mlua_derive/src/from_lua.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ pub fn from_lua(input: TokenStream) -> TokenStream {
77
ident, generics, ..
88
} = parse_macro_input!(input as DeriveInput);
99

10+
let ident_str = ident.to_string();
11+
let (impl_generics, ty_generics, _) = generics.split_for_impl();
1012
let where_clause = match &generics.where_clause {
1113
Some(where_clause) => quote! { #where_clause, Self: 'static + Clone },
1214
None => quote! { where Self: 'static + Clone },
1315
};
14-
let ident_str = ident.to_string();
1516

1617
quote! {
17-
impl #generics ::mlua::FromLua<'_> for #ident #generics #where_clause {
18+
impl #impl_generics ::mlua::FromLua<'_> for #ident #ty_generics #where_clause {
1819
#[inline]
19-
fn from_lua(value: ::mlua::Value<'_>, lua: &'_ ::mlua::Lua) -> ::mlua::Result<Self> {
20+
fn from_lua(value: ::mlua::Value<'_>, _: &'_ ::mlua::Lua) -> ::mlua::Result<Self> {
2021
match value {
2122
::mlua::Value::UserData(ud) => Ok(ud.borrow::<Self>()?.clone()),
2223
_ => Err(::mlua::Error::FromLuaConversionError {

tests/userdata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,9 @@ fn test_userdata_derive() -> Result<()> {
991991
// More complex struct where generics and where clause
992992

993993
#[derive(Clone, Copy, mlua::FromLua)]
994-
struct MyUserData2<'a, T>(&'a T)
994+
struct MyUserData2<'a, T: ?Sized>(&'a T)
995995
where
996-
T: ?Sized;
996+
T: Copy;
997997

998998
lua.register_userdata_type::<MyUserData2<'static, i32>>(|reg| {
999999
reg.add_function("val", |_, this: MyUserData2<'static, i32>| Ok(*this.0));

0 commit comments

Comments
 (0)