Globally upgrade to syn 2.x and latest quote and proc_macro2 1x versions (#13846)

* globally upgrade quote to latest 1.0.x (1.0.26)

* globally upgrade syn to final 1.0.x version (1.0.109)

* globally upgrade proc-macro2 to 1.0.56

* upgrade to syn v2.0.13 and fix everything except NestedMeta

* fix parse nested metadata code in decl_runtime_apis.rs

* Port more stuff to syn 2.0

* Make the rest compile

* Ignore error

* update to syn 2.0.14

---------

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Sam Johnson
2023-04-12 14:42:22 -04:00
committed by GitHub
parent 03c99fe003
commit b83bf4784e
62 changed files with 402 additions and 478 deletions
@@ -17,7 +17,6 @@
use frame_support_procedural_tools::generate_crate_access_2018;
use quote::ToTokens;
use std::str::FromStr;
// Derive `PalletError`
pub fn derive_pallet_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
@@ -117,38 +116,24 @@ fn generate_field_types(
let attrs = &field.attrs;
for attr in attrs {
if attr.path.is_ident("codec") {
match attr.parse_meta()? {
syn::Meta::List(ref meta_list) if meta_list.nested.len() == 1 => {
match meta_list
.nested
.first()
.expect("Just checked that there is one item; qed")
{
syn::NestedMeta::Meta(syn::Meta::Path(path))
if path.get_ident().map_or(false, |i| i == "skip") =>
return Ok(None),
if attr.path().is_ident("codec") {
let mut res = None;
syn::NestedMeta::Meta(syn::Meta::Path(path))
if path.get_ident().map_or(false, |i| i == "compact") =>
{
let field_ty = &field.ty;
return Ok(Some(quote::quote!(#scrate::codec::Compact<#field_ty>)))
},
attr.parse_nested_meta(|meta| {
if meta.path.is_ident("skip") {
res = Some(None);
} else if meta.path.is_ident("compact") {
let field_ty = &field.ty;
res = Some(Some(quote::quote!(#scrate::codec::Compact<#field_ty>)));
} else if meta.path.is_ident("compact") {
res = Some(Some(meta.value()?.parse()?));
}
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
path,
lit: syn::Lit::Str(lit_str),
..
})) if path.get_ident().map_or(false, |i| i == "encoded_as") => {
let ty = proc_macro2::TokenStream::from_str(&lit_str.value())?;
return Ok(Some(ty))
},
Ok(())
})?;
_ => (),
}
},
_ => (),
if let Some(v) = res {
return Ok(v)
}
}
}
@@ -163,22 +148,18 @@ fn generate_variant_field_types(
let attrs = &variant.attrs;
for attr in attrs {
if attr.path.is_ident("codec") {
match attr.parse_meta()? {
syn::Meta::List(ref meta_list) if meta_list.nested.len() == 1 => {
match meta_list
.nested
.first()
.expect("Just checked that there is one item; qed")
{
syn::NestedMeta::Meta(syn::Meta::Path(path))
if path.get_ident().map_or(false, |i| i == "skip") =>
return Ok(None),
if attr.path().is_ident("codec") {
let mut skip = false;
_ => (),
}
},
_ => (),
// We ignore the error intentionally as this isn't `codec(skip)` when
// `parse_nested_meta` fails.
let _ = attr.parse_nested_meta(|meta| {
skip = meta.path.is_ident("skip");
Ok(())
});
if skip {
return Ok(None)
}
}
}