@@ -2,14 +2,9 @@ use proc_macro2::{Ident, Span};
22use syn:: {
33 parenthesized,
44 parse:: { ParseBuffer , ParseStream } ,
5- parse2 , Attribute , DeriveInput , Expr , ExprPath , GenericParam , LitStr , Token , WherePredicate ,
5+ Attribute , DeriveInput , Expr , ExprPath , GenericParam , LitStr , Token , WherePredicate ,
66} ;
77
8- // pub struct MapFieldAttribute {
9- // // from_ty: Option<syn::Type>,
10- // map_func: syn::ExprPath,
11- // }
12-
138/// Attributes that are applied to fields.
149#[ derive( Default , Debug , Clone ) ]
1510pub struct FieldAttributesInfo {
@@ -154,12 +149,7 @@ fn parse_rename(input: &ParseBuffer) -> Result<LitStr, syn::Error> {
154149impl syn:: parse:: Parse for FieldAttributesInfo {
155150 fn parse ( input : ParseStream ) -> syn:: Result < Self > {
156151 let mut this = FieldAttributesInfo :: default ( ) ;
157- // parse starting right after #[deserr .... ]
158- // so first get the content inside the parentheses
159152
160- let content;
161- let _ = parenthesized ! ( content in input) ;
162- let input = content;
163153 // consumed input: #[deserr( .... )]
164154
165155 loop {
@@ -168,7 +158,7 @@ impl syn::parse::Parse for FieldAttributesInfo {
168158 // consumed input: #[deserr( ... attr_name ... )]
169159 match attr_name. to_string ( ) . as_str ( ) {
170160 "rename" => {
171- other. rename = Some ( parse_rename ( & input) ?) ;
161+ other. rename = Some ( parse_rename ( input) ?) ;
172162 }
173163 "default" => {
174164 if input. peek ( Token ! [ =] ) {
@@ -201,12 +191,12 @@ impl syn::parse::Parse for FieldAttributesInfo {
201191 other. map = Some ( func) ;
202192 }
203193 "from" => {
204- let from_attr = parse_attribute_from ( attr_name. span ( ) , & input) ?;
194+ let from_attr = parse_attribute_from ( attr_name. span ( ) , input) ?;
205195 // #[deserr( .. from(from_ty) = function::path::<_>)]
206196 other. from = Some ( from_attr) ;
207197 }
208198 "try_from" => {
209- let try_from_attr = parse_attribute_try_from ( attr_name. span ( ) , & input) ?;
199+ let try_from_attr = parse_attribute_try_from ( attr_name. span ( ) , input) ?;
210200 // #[deserr( .. try_from(from_ty) = function::path::<_> -> to_ty )]
211201 other. try_from = Some ( try_from_attr) ;
212202 }
@@ -243,11 +233,11 @@ pub fn read_deserr_field_attributes(
243233) -> Result < FieldAttributesInfo , syn:: Error > {
244234 let mut this = FieldAttributesInfo :: default ( ) ;
245235 for attribute in attributes {
246- if let Some ( ident) = attribute. path . get_ident ( ) {
236+ if let Some ( ident) = attribute. path ( ) . get_ident ( ) {
247237 if ident != "deserr" {
248238 continue ;
249239 }
250- let other = parse2 :: < FieldAttributesInfo > ( attribute. tokens . clone ( ) ) ?;
240+ let other: FieldAttributesInfo = attribute. parse_args ( ) ?;
251241 this. merge ( other) ?;
252242 } else {
253243 continue ;
@@ -519,20 +509,15 @@ fn parse_attribute_try_from(
519509impl syn:: parse:: Parse for ContainerAttributesInfo {
520510 fn parse ( input : ParseStream ) -> syn:: Result < Self > {
521511 let mut this = ContainerAttributesInfo :: default ( ) ;
522- // parse starting right after #[deserr .... ]
523- // so first get the content inside the parentheses
524512
525- let content;
526- let _ = parenthesized ! ( content in input) ;
527- let input = content;
528513 // consumed input: #[deserr( .... )]
529514
530515 loop {
531516 let attr_name = input. parse :: < Ident > ( ) ?;
532517 // consumed input: #[deserr( ... attr_name ... )]
533518 match attr_name. to_string ( ) . as_str ( ) {
534519 "rename_all" => {
535- let rename_all = parse_rename_all ( & input) ?;
520+ let rename_all = parse_rename_all ( input) ?;
536521 this. rename_all = Some ( rename_all) ;
537522 this. rename_all_span = Some ( attr_name. span ( ) ) ;
538523 }
@@ -561,20 +546,20 @@ impl syn::parse::Parse for ContainerAttributesInfo {
561546 this. deny_unknown_fields_span = Some ( attr_name. span ( ) ) ;
562547 }
563548 "from" => {
564- let from_attr = parse_attribute_from ( attr_name. span ( ) , & input) ?;
549+ let from_attr = parse_attribute_from ( attr_name. span ( ) , input) ?;
565550 // #[deserr( .. from(from_ty) = function::path::<_>)]
566551 this. from = Some ( from_attr) ;
567552 }
568553 "try_from" => {
569- let try_from_attr = parse_attribute_try_from ( attr_name. span ( ) , & input) ?;
554+ let try_from_attr = parse_attribute_try_from ( attr_name. span ( ) , input) ?;
570555 // #[deserr( .. try_from(from_ty) = function::path::<_> -> to_ty )]
571556 this. try_from = Some ( try_from_attr) ;
572557 }
573558 "validate" => {
574559 // #[deserr( ... validate .. )]
575560 let _eq = input. parse :: < Token ! [ =] > ( ) ?;
576561 // #[deserr( ... validate = .. )]
577- let validate_func = parse_function_returning_error ( & input) ?;
562+ let validate_func = parse_function_returning_error ( input) ?;
578563 // #[deserr( ... validate = some::func<T> )]
579564 this. validate = Some ( validate_func) ;
580565 }
@@ -655,11 +640,11 @@ pub fn read_deserr_container_attributes(
655640) -> Result < ContainerAttributesInfo , syn:: Error > {
656641 let mut this = ContainerAttributesInfo :: default ( ) ;
657642 for attribute in attributes {
658- if let Some ( ident) = attribute. path . get_ident ( ) {
643+ if let Some ( ident) = attribute. path ( ) . get_ident ( ) {
659644 if ident != "deserr" {
660645 continue ;
661646 }
662- let other = parse2 :: < ContainerAttributesInfo > ( attribute. tokens . clone ( ) ) ?;
647+ let other: ContainerAttributesInfo = attribute. parse_args ( ) ?;
663648 this. merge ( other) ?;
664649 } else {
665650 continue ;
@@ -726,23 +711,18 @@ impl VariantAttributesInfo {
726711impl syn:: parse:: Parse for VariantAttributesInfo {
727712 fn parse ( input : ParseStream ) -> syn:: Result < Self > {
728713 let mut this = VariantAttributesInfo :: default ( ) ;
729- // parse starting right after #[deserr .... ]
730- // so first get the content inside the parentheses
731714
732- let content;
733- let _ = parenthesized ! ( content in input) ;
734- let input = content;
735715 // consumed input: #[deserr( .... )]
736716
737717 loop {
738718 let attr_name = input. parse :: < Ident > ( ) ?;
739719 // consumed input: #[deserr( ... attr_name ... )]
740720 match attr_name. to_string ( ) . as_str ( ) {
741721 "rename" => {
742- this. rename = Some ( parse_rename ( & input) ?) ;
722+ this. rename = Some ( parse_rename ( input) ?) ;
743723 }
744724 "rename_all" => {
745- this. rename_all = Some ( parse_rename_all ( & input) ?) ;
725+ this. rename_all = Some ( parse_rename_all ( input) ?) ;
746726 this. rename_all_span = Some ( attr_name. span ( ) ) ;
747727 }
748728 _ => {
@@ -774,11 +754,11 @@ pub fn read_deserr_variant_attributes(
774754) -> Result < VariantAttributesInfo , syn:: Error > {
775755 let mut this = VariantAttributesInfo :: default ( ) ;
776756 for attribute in attributes {
777- if let Some ( ident) = attribute. path . get_ident ( ) {
757+ if let Some ( ident) = attribute. path ( ) . get_ident ( ) {
778758 if ident != "deserr" {
779759 continue ;
780760 }
781- let other = parse2 :: < VariantAttributesInfo > ( attribute. tokens . clone ( ) ) ?;
761+ let other: VariantAttributesInfo = attribute. parse_args ( ) ?;
782762 this. merge ( other) ?;
783763 } else {
784764 continue ;
0 commit comments