1818
1919use proc_macro2:: TokenStream ;
2020use quote:: quote;
21- use syn:: { parse:: Parse , spanned:: Spanned , AttrStyle , Attribute , Lit , Meta , NestedMeta , Variant } ;
21+ use syn:: {
22+ parse:: Parse , spanned:: Spanned , AttrStyle , Attribute , Expr , ExprLit , Lit , Meta , Variant ,
23+ } ;
2224
2325/// Look for a `#[codec(index = $int)]` attribute on a variant. If no attribute
2426/// is found, fall back to the discriminant or just the variant index.
@@ -43,9 +45,13 @@ pub fn maybe_index(variant: &Variant) -> Option<u8> {
4345 . filter ( |attr| attr. style == AttrStyle :: Outer ) ;
4446
4547 codec_meta_item ( outer_attrs, |meta| {
46- if let NestedMeta :: Meta ( Meta :: NameValue ( ref nv) ) = meta {
48+ if let Meta :: NameValue ( ref nv) = meta {
4749 if nv. path . is_ident ( "index" ) {
48- if let Lit :: Int ( ref v) = nv. lit {
50+ if let Expr :: Lit ( ExprLit {
51+ lit : Lit :: Int ( ref v) ,
52+ ..
53+ } ) = nv. value
54+ {
4955 let byte = v
5056 . base10_parse :: < u8 > ( )
5157 . expect ( "Internal error. `#[codec(index = …)]` attribute syntax must be checked in `parity-scale-codec`. This is a bug." ) ;
@@ -65,7 +71,7 @@ pub fn is_compact(field: &syn::Field) -> bool {
6571 . iter ( )
6672 . filter ( |attr| attr. style == AttrStyle :: Outer ) ;
6773 codec_meta_item ( outer_attrs, |meta| {
68- if let NestedMeta :: Meta ( Meta :: Path ( ref path) ) = meta {
74+ if let Meta :: Path ( ref path) = meta {
6975 if path. is_ident ( "compact" ) {
7076 return Some ( ( ) ) ;
7177 }
@@ -79,7 +85,7 @@ pub fn is_compact(field: &syn::Field) -> bool {
7985/// Look for a `#[codec(skip)]` in the given attributes.
8086pub fn should_skip ( attrs : & [ Attribute ] ) -> bool {
8187 codec_meta_item ( attrs. iter ( ) , |meta| {
82- if let NestedMeta :: Meta ( Meta :: Path ( ref path) ) = meta {
88+ if let Meta :: Path ( ref path) = meta {
8389 if path. is_ident ( "skip" ) {
8490 return Some ( path. span ( ) ) ;
8591 }
@@ -106,7 +112,7 @@ where
106112 M : Parse ,
107113{
108114 itr. find_map ( |attr| {
109- attr. path
115+ attr. path ( )
110116 . is_ident ( kind)
111117 . then ( || pred ( attr. parse_args ( ) . ok ( ) ?) )
112118 . flatten ( )
0 commit comments