@@ -85,12 +85,6 @@ impl Parse for PropsMacroInput {
85
85
) )
86
86
}
87
87
} ;
88
- if props. is_empty ( ) {
89
- return Err ( syn:: Error :: new (
90
- proc_macro2:: Span :: call_site ( ) ,
91
- "Struct must have at least one field with the #[property(…)] attribute" ,
92
- ) ) ;
93
- }
94
88
Ok ( Self {
95
89
wrapper_ty : attrs. wrapper_ty ,
96
90
ext_trait : attrs. ext_trait ,
@@ -513,6 +507,7 @@ fn expand_set_property_fn(props: &[PropDesc]) -> TokenStream2 {
513
507
} )
514
508
} ) ;
515
509
quote ! (
510
+ #[ allow( unreachable_code) ]
516
511
fn derived_set_property( & self ,
517
512
id: usize ,
518
513
value: & #crate_ident:: Value ,
@@ -662,29 +657,43 @@ fn name_to_enum_ident(name: String) -> syn::Ident {
662
657
}
663
658
664
659
fn expand_properties_enum ( props : & [ PropDesc ] ) -> TokenStream2 {
665
- let properties: Vec < syn:: Ident > = props
666
- . iter ( )
667
- . map ( |p| {
668
- let name: String = p. name . value ( ) ;
660
+ if props. is_empty ( ) {
661
+ quote ! {
662
+ #[ derive( Debug , Copy , Clone ) ]
663
+ enum DerivedPropertiesEnum { }
664
+ impl std:: convert:: TryFrom <usize > for DerivedPropertiesEnum {
665
+ type Error = usize ;
669
666
670
- name_to_enum_ident ( name)
671
- } )
672
- . collect ( ) ;
673
- let props = properties. iter ( ) ;
674
- let indices = 0 ..properties. len ( ) ;
675
- quote ! {
676
- #[ repr( usize ) ]
677
- #[ derive( Debug , Copy , Clone ) ]
678
- enum DerivedPropertiesEnum {
679
- #( #props, ) *
667
+ fn try_from( item: usize ) -> :: core:: result:: Result <Self , <Self as std:: convert:: TryFrom <usize >>:: Error > {
668
+ :: core:: result:: Result :: Err ( item)
669
+ }
670
+ }
680
671
}
681
- impl std:: convert:: TryFrom <usize > for DerivedPropertiesEnum {
682
- type Error = usize ;
672
+ } else {
673
+ let properties: Vec < syn:: Ident > = props
674
+ . iter ( )
675
+ . map ( |p| {
676
+ let name: String = p. name . value ( ) ;
683
677
684
- fn try_from( item: usize ) -> :: core:: result:: Result <Self , <Self as std:: convert:: TryFrom <usize >>:: Error > {
685
- match item {
686
- #( #indices => :: core:: result:: Result :: Ok ( Self :: #properties) , ) *
687
- _ => :: core:: result:: Result :: Err ( item)
678
+ name_to_enum_ident ( name)
679
+ } )
680
+ . collect ( ) ;
681
+ let props = properties. iter ( ) ;
682
+ let indices = 0 ..properties. len ( ) ;
683
+ quote ! {
684
+ #[ repr( usize ) ]
685
+ #[ derive( Debug , Copy , Clone ) ]
686
+ enum DerivedPropertiesEnum {
687
+ #( #props, ) *
688
+ }
689
+ impl std:: convert:: TryFrom <usize > for DerivedPropertiesEnum {
690
+ type Error = usize ;
691
+
692
+ fn try_from( item: usize ) -> :: core:: result:: Result <Self , <Self as std:: convert:: TryFrom <usize >>:: Error > {
693
+ match item {
694
+ #( #indices => :: core:: result:: Result :: Ok ( Self :: #properties) , ) *
695
+ _ => :: core:: result:: Result :: Err ( item)
696
+ }
688
697
}
689
698
}
690
699
}
0 commit comments