Skip to content

Commit a7c5a24

Browse files
committed
mlua_derive: Deny #[lua = "..."] syntax
1 parent b7c98ad commit a7c5a24

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

mlua_derive/src/userdata/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ pub(crate) fn with_cfg(tokens: proc_macro2::TokenStream, attrs: &[Attribute]) ->
2525
fn parse_field_lua_attr(attrs: &[Attribute]) -> syn::Result<LuaAttr> {
2626
let mut lua_attr = LuaAttr::default();
2727
for attr in attrs {
28-
if attr.path().is_ident("lua")
29-
&& let Meta::List(_) = &attr.meta
30-
{
31-
attr.parse_nested_meta(|meta| lua_attr.parse_inner(meta))?;
28+
if !attr.path().is_ident("lua") {
29+
continue;
30+
}
31+
match &attr.meta {
32+
Meta::List(_) => {
33+
attr.parse_nested_meta(|meta| lua_attr.parse_inner(meta))?;
34+
}
35+
Meta::Path(_) => {}
36+
Meta::NameValue(_) => {
37+
return Err(syn::Error::new_spanned(
38+
attr,
39+
"`#[lua = \"...\"]` is not supported: use `#[lua(attr = \"...\")]`",
40+
));
41+
}
3242
}
3343
}
3444
Ok(lua_attr)

mlua_derive/src/userdata/userdata_impl.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,20 @@ fn strip_item_attrs(attrs: &[Attribute]) -> Vec<Attribute> {
177177
fn parse_lua_attr(attrs: &[Attribute]) -> syn::Result<LuaAttr> {
178178
let mut lua_attr = LuaAttr::default();
179179
for attr in attrs {
180-
if attr.path().is_ident("lua")
181-
&& let Meta::List(_) = &attr.meta
182-
{
183-
attr.parse_nested_meta(|meta| lua_attr.parse_inner(meta))?;
180+
if !attr.path().is_ident("lua") {
181+
continue;
182+
}
183+
match &attr.meta {
184+
Meta::List(_) => {
185+
attr.parse_nested_meta(|meta| lua_attr.parse_inner(meta))?;
186+
}
187+
Meta::Path(_) => {}
188+
Meta::NameValue(_) => {
189+
return Err(syn::Error::new_spanned(
190+
attr,
191+
"`#[lua = \"...\"]` is not supported: use `#[lua(attr = \"...\")]`",
192+
));
193+
}
184194
}
185195
}
186196
Ok(lua_attr)

0 commit comments

Comments
 (0)