@@ -34,35 +34,18 @@ fn parse_field_lua_attr(attrs: &[Attribute]) -> syn::Result<LuaAttr> {
3434 Ok ( lua_attr)
3535}
3636
37- /// Strip `#[lua(...)]` attributes from a field, keeping all others.
38- fn strip_lua_attrs ( attrs : & [ Attribute ] ) -> Vec < Attribute > {
39- ( attrs. iter ( ) )
40- . filter ( |attr| !attr. path ( ) . is_ident ( "lua" ) )
41- . cloned ( )
42- . collect ( )
43- }
44-
45- pub fn userdata_type ( attr : TokenStream , item : TokenStream ) -> TokenStream {
46- if !attr. is_empty ( ) {
47- return Error :: new_spanned (
48- proc_macro2:: TokenStream :: from ( attr) ,
49- "`#[userdata]` does not accept arguments" ,
50- )
51- . to_compile_error ( )
52- . into ( ) ;
53- }
54-
55- let mut input = parse_macro_input ! ( item as DeriveInput ) ;
37+ pub fn userdata_type ( item : TokenStream ) -> TokenStream {
38+ let input = parse_macro_input ! ( item as DeriveInput ) ;
5639 let type_name = & input. ident ;
5740
58- let mut named_fields: Option < & mut FieldsNamed > = match & mut input. data {
59- Data :: Struct ( data) => match & mut data. fields {
41+ let named_fields: Option < & FieldsNamed > = match & input. data {
42+ Data :: Struct ( data) => match & data. fields {
6043 Fields :: Named ( fields) => Some ( fields) ,
6144 Fields :: Unnamed ( _) | Fields :: Unit => None ,
6245 } ,
6346 Data :: Enum ( _) => None ,
6447 Data :: Union ( _) => {
65- return Error :: new_spanned ( & input, "`#[userdata ]` cannot be applied to unions" )
48+ return Error :: new_spanned ( & input, "`#[derive(UserData) ]` cannot be applied to unions" )
6649 . to_compile_error ( )
6750 . into ( ) ;
6851 }
@@ -73,14 +56,14 @@ pub fn userdata_type(attr: TokenStream, item: TokenStream) -> TokenStream {
7356 if has_type_params {
7457 return Error :: new_spanned (
7558 & input. generics ,
76- "`#[userdata ]` does not support generic type parameters. Wrap the generic type in a concrete newtype instead."
59+ "`#[derive(UserData) ]` does not support generic type parameters. Wrap the generic type in a concrete newtype instead."
7760 )
7861 . to_compile_error ( )
7962 . into ( ) ;
8063 }
8164
8265 let mut field_registrations = Vec :: new ( ) ;
83- if let Some ( fields) = & mut named_fields {
66+ if let Some ( fields) = & named_fields {
8467 for field in & fields. named {
8568 let field_name = field. ident . as_ref ( ) . unwrap ( ) ;
8669
@@ -114,19 +97,12 @@ pub fn userdata_type(attr: TokenStream, item: TokenStream) -> TokenStream {
11497 field_registrations. push ( with_cfg ( tokens, & field. attrs ) ) ;
11598 }
11699 }
117-
118- // Strip mlua-specific attributes from fields before re-emitting
119- for field in & mut fields. named {
120- field. attrs = strip_lua_attrs ( & field. attrs ) ;
121- }
122100 }
123101
124102 let registration_type_name = format_ident ! ( "__MluaUserDataRegistration_{type_name}" ) ;
125103 let register_fields_fn_name = format_ident ! ( "__mlua_register_{type_name}_fields" ) ;
126104
127105 let output = quote ! {
128- #input
129-
130106 #[ doc( hidden) ]
131107 #[ allow( non_camel_case_types) ]
132108 struct #registration_type_name {
0 commit comments