mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 07:47:57 +00:00
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:
@@ -45,7 +45,7 @@ pub struct CallDef {
|
||||
/// The span of the pallet::call attribute.
|
||||
pub attr_span: proc_macro2::Span,
|
||||
/// Docs, specified on the impl Block.
|
||||
pub docs: Vec<syn::Lit>,
|
||||
pub docs: Vec<syn::Expr>,
|
||||
}
|
||||
|
||||
/// Definition of dispatchable typically: `#[weight...] fn foo(origin .., param1: ...) -> ..`
|
||||
@@ -62,7 +62,7 @@ pub struct CallVariantDef {
|
||||
/// Whether an explicit call index was specified.
|
||||
pub explicit_call_index: bool,
|
||||
/// Docs, used for metadata.
|
||||
pub docs: Vec<syn::Lit>,
|
||||
pub docs: Vec<syn::Expr>,
|
||||
/// Attributes annotated at the top of the dispatchable function.
|
||||
pub attrs: Vec<syn::Attribute>,
|
||||
}
|
||||
@@ -173,7 +173,7 @@ impl CallDef {
|
||||
let mut indices = HashMap::new();
|
||||
let mut last_index: Option<u8> = None;
|
||||
for item in &mut item_impl.items {
|
||||
if let syn::ImplItem::Method(method) = item {
|
||||
if let syn::ImplItem::Fn(method) = item {
|
||||
if !matches!(method.vis, syn::Visibility::Public(_)) {
|
||||
let msg = "Invalid pallet::call, dispatchable function must be public: \
|
||||
`pub fn`";
|
||||
|
||||
@@ -32,14 +32,14 @@ pub mod keyword {
|
||||
SlashReason(SlashReason),
|
||||
}
|
||||
|
||||
impl Spanned for CompositeKeyword {
|
||||
fn span(&self) -> proc_macro2::Span {
|
||||
impl ToTokens for CompositeKeyword {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
use CompositeKeyword::*;
|
||||
match self {
|
||||
FreezeReason(inner) => inner.span(),
|
||||
HoldReason(inner) => inner.span(),
|
||||
LockId(inner) => inner.span(),
|
||||
SlashReason(inner) => inner.span(),
|
||||
FreezeReason(inner) => inner.to_tokens(tokens),
|
||||
HoldReason(inner) => inner.to_tokens(tokens),
|
||||
LockId(inner) => inner.to_tokens(tokens),
|
||||
SlashReason(inner) => inner.to_tokens(tokens),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,14 +109,11 @@ impl CompositeDef {
|
||||
}
|
||||
|
||||
let has_derive_attr = item.attrs.iter().any(|attr| {
|
||||
attr.parse_meta()
|
||||
.ok()
|
||||
.map(|meta| match meta {
|
||||
syn::Meta::List(syn::MetaList { path, .. }) =>
|
||||
path.get_ident().map(|ident| ident == "derive").unwrap_or(false),
|
||||
_ => false,
|
||||
})
|
||||
.unwrap_or(false)
|
||||
if let syn::Meta::List(syn::MetaList { path, .. }) = &attr.meta {
|
||||
path.get_ident().map(|ident| ident == "derive").unwrap_or(false)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
|
||||
if !has_derive_attr {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub struct ConstMetadataDef {
|
||||
/// The type in Get, e.g. `u32` in `type Foo: Get<u32>;`, but `Self` is replaced by `T`
|
||||
pub type_: syn::Type,
|
||||
/// The doc associated
|
||||
pub doc: Vec<syn::Lit>,
|
||||
pub doc: Vec<syn::Expr>,
|
||||
}
|
||||
|
||||
impl TryFrom<&syn::TraitItemType> for ConstMetadataDef {
|
||||
@@ -124,23 +124,35 @@ impl syn::parse::Parse for DisableFrameSystemSupertraitCheck {
|
||||
}
|
||||
|
||||
/// Parse for `#[pallet::constant]`
|
||||
pub struct TypeAttrConst(proc_macro2::Span);
|
||||
|
||||
impl Spanned for TypeAttrConst {
|
||||
fn span(&self) -> proc_macro2::Span {
|
||||
self.0
|
||||
}
|
||||
pub struct TypeAttrConst {
|
||||
pound_token: syn::Token![#],
|
||||
bracket_token: syn::token::Bracket,
|
||||
pallet_ident: syn::Ident,
|
||||
path_sep_token: syn::token::PathSep,
|
||||
constant_keyword: keyword::constant,
|
||||
}
|
||||
|
||||
impl syn::parse::Parse for TypeAttrConst {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
input.parse::<syn::Token![#]>()?;
|
||||
let pound_token = input.parse::<syn::Token![#]>()?;
|
||||
let content;
|
||||
syn::bracketed!(content in input);
|
||||
content.parse::<syn::Ident>()?;
|
||||
content.parse::<syn::Token![::]>()?;
|
||||
let bracket_token = syn::bracketed!(content in input);
|
||||
let pallet_ident = content.parse::<syn::Ident>()?;
|
||||
let path_sep_token = content.parse::<syn::Token![::]>()?;
|
||||
let constant_keyword = content.parse::<keyword::constant>()?;
|
||||
|
||||
Ok(TypeAttrConst(content.parse::<keyword::constant>()?.span()))
|
||||
Ok(Self { pound_token, bracket_token, pallet_ident, path_sep_token, constant_keyword })
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for TypeAttrConst {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
self.pound_token.to_tokens(tokens);
|
||||
self.bracket_token.surround(tokens, |tokens| {
|
||||
self.pallet_ident.to_tokens(tokens);
|
||||
self.path_sep_token.to_tokens(tokens);
|
||||
self.constant_keyword.to_tokens(tokens);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct ErrorDef {
|
||||
/// The index of error item in pallet module.
|
||||
pub index: usize,
|
||||
/// Variants ident, optional field and doc literals (ordered as declaration order)
|
||||
pub variants: Vec<(syn::Ident, Option<VariantField>, Vec<syn::Lit>)>,
|
||||
pub variants: Vec<(syn::Ident, Option<VariantField>, Vec<syn::Expr>)>,
|
||||
/// A set of usage of instance, must be check for consistency with trait.
|
||||
pub instances: Vec<helper::InstanceUsage>,
|
||||
/// The keyword error used (contains span).
|
||||
|
||||
@@ -50,7 +50,7 @@ pub struct ExtraConstantDef {
|
||||
/// The type returned by the function
|
||||
pub type_: syn::Type,
|
||||
/// The doc associated
|
||||
pub doc: Vec<syn::Lit>,
|
||||
pub doc: Vec<syn::Expr>,
|
||||
/// Optional MetaData Name
|
||||
pub metadata_name: Option<syn::Ident>,
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl ExtraConstantsDef {
|
||||
|
||||
let mut extra_constants = vec![];
|
||||
for impl_item in &mut item.items {
|
||||
let method = if let syn::ImplItem::Method(method) = impl_item {
|
||||
let method = if let syn::ImplItem::Fn(method) = impl_item {
|
||||
method
|
||||
} else {
|
||||
let msg = "Invalid pallet::call, only method accepted";
|
||||
|
||||
@@ -54,7 +54,7 @@ where
|
||||
let attrs = if let Some(attrs) = item.mut_item_attrs() { attrs } else { return Ok(None) };
|
||||
|
||||
if let Some(index) = attrs.iter().position(|attr| {
|
||||
attr.path.segments.first().map_or(false, |segment| segment.ident == "pallet")
|
||||
attr.path().segments.first().map_or(false, |segment| segment.ident == "pallet")
|
||||
}) {
|
||||
let pallet_attr = attrs.remove(index);
|
||||
Ok(Some(syn::parse2(pallet_attr.into_token_stream())?))
|
||||
@@ -82,7 +82,7 @@ pub fn get_item_cfg_attrs(attrs: &[syn::Attribute]) -> Vec<syn::Attribute> {
|
||||
attrs
|
||||
.iter()
|
||||
.filter_map(|attr| {
|
||||
if attr.path.segments.first().map_or(false, |segment| segment.ident == "cfg") {
|
||||
if attr.path().segments.first().map_or(false, |segment| segment.ident == "cfg") {
|
||||
Some(attr.clone())
|
||||
} else {
|
||||
None
|
||||
@@ -101,7 +101,6 @@ impl MutItemAttrs for syn::Item {
|
||||
Self::ForeignMod(item) => Some(item.attrs.as_mut()),
|
||||
Self::Impl(item) => Some(item.attrs.as_mut()),
|
||||
Self::Macro(item) => Some(item.attrs.as_mut()),
|
||||
Self::Macro2(item) => Some(item.attrs.as_mut()),
|
||||
Self::Mod(item) => Some(item.attrs.as_mut()),
|
||||
Self::Static(item) => Some(item.attrs.as_mut()),
|
||||
Self::Struct(item) => Some(item.attrs.as_mut()),
|
||||
@@ -119,7 +118,7 @@ impl MutItemAttrs for syn::TraitItem {
|
||||
fn mut_item_attrs(&mut self) -> Option<&mut Vec<syn::Attribute>> {
|
||||
match self {
|
||||
Self::Const(item) => Some(item.attrs.as_mut()),
|
||||
Self::Method(item) => Some(item.attrs.as_mut()),
|
||||
Self::Fn(item) => Some(item.attrs.as_mut()),
|
||||
Self::Type(item) => Some(item.attrs.as_mut()),
|
||||
Self::Macro(item) => Some(item.attrs.as_mut()),
|
||||
_ => None,
|
||||
@@ -139,7 +138,7 @@ impl MutItemAttrs for syn::ItemMod {
|
||||
}
|
||||
}
|
||||
|
||||
impl MutItemAttrs for syn::ImplItemMethod {
|
||||
impl MutItemAttrs for syn::ImplItemFn {
|
||||
fn mut_item_attrs(&mut self) -> Option<&mut Vec<syn::Attribute>> {
|
||||
Some(&mut self.attrs)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ impl HooksDef {
|
||||
}
|
||||
|
||||
let has_runtime_upgrade = item.items.iter().any(|i| match i {
|
||||
syn::ImplItem::Method(method) => method.sig.ident == "on_runtime_upgrade",
|
||||
syn::ImplItem::Fn(method) => method.sig.ident == "on_runtime_upgrade",
|
||||
_ => false,
|
||||
});
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ pub struct StorageDef {
|
||||
/// The keys and value metadata of the storage.
|
||||
pub metadata: Metadata,
|
||||
/// The doc associated to the storage.
|
||||
pub docs: Vec<syn::Lit>,
|
||||
pub docs: Vec<syn::Expr>,
|
||||
/// A set of usage of instance, must be check for consistency with config.
|
||||
pub instances: Vec<helper::InstanceUsage>,
|
||||
/// Optional getter to generate. If some then query_kind is ensured to be some as well.
|
||||
@@ -270,7 +270,7 @@ enum StorageKind {
|
||||
/// Check the generics in the `map` contains the generics in `gen` may contains generics in
|
||||
/// `optional_gen`, and doesn't contains any other.
|
||||
fn check_generics(
|
||||
map: &HashMap<String, syn::Binding>,
|
||||
map: &HashMap<String, syn::AssocType>,
|
||||
mandatory_generics: &[&str],
|
||||
optional_generics: &[&str],
|
||||
storage_type_name: &str,
|
||||
@@ -331,9 +331,9 @@ fn check_generics(
|
||||
fn process_named_generics(
|
||||
storage: &StorageKind,
|
||||
args_span: proc_macro2::Span,
|
||||
args: &[syn::Binding],
|
||||
args: &[syn::AssocType],
|
||||
) -> syn::Result<(Option<StorageGenerics>, Metadata, Option<syn::Type>, bool)> {
|
||||
let mut parsed = HashMap::<String, syn::Binding>::new();
|
||||
let mut parsed = HashMap::<String, syn::AssocType>::new();
|
||||
|
||||
// Ensure no duplicate.
|
||||
for arg in args {
|
||||
@@ -610,12 +610,12 @@ fn process_generics(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
process_unnamed_generics(&storage_kind, args_span, &args, dev_mode)
|
||||
} else if args.args.iter().all(|gen| matches!(gen, syn::GenericArgument::Binding(_))) {
|
||||
} else if args.args.iter().all(|gen| matches!(gen, syn::GenericArgument::AssocType(_))) {
|
||||
let args = args
|
||||
.args
|
||||
.iter()
|
||||
.map(|gen| match gen {
|
||||
syn::GenericArgument::Binding(gen) => gen.clone(),
|
||||
syn::GenericArgument::AssocType(gen) => gen.clone(),
|
||||
_ => unreachable!("It is asserted above that all generics are bindings"),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct TypeValueDef {
|
||||
/// The span of the pallet::type_value attribute.
|
||||
pub attr_span: proc_macro2::Span,
|
||||
/// Docs on the item.
|
||||
pub docs: Vec<syn::Lit>,
|
||||
pub docs: Vec<syn::Expr>,
|
||||
}
|
||||
|
||||
impl TypeValueDef {
|
||||
@@ -57,9 +57,9 @@ impl TypeValueDef {
|
||||
|
||||
let mut docs = vec![];
|
||||
for attr in &item.attrs {
|
||||
if let Ok(syn::Meta::NameValue(meta)) = attr.parse_meta() {
|
||||
if let syn::Meta::NameValue(meta) = &attr.meta {
|
||||
if meta.path.get_ident().map_or(false, |ident| ident == "doc") {
|
||||
docs.push(meta.lit);
|
||||
docs.push(meta.value.clone());
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user