mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 19:55:40 +00:00
Fixes parsing for config attrs in pallet macros (#2677)
This commit is contained in:
@@ -241,6 +241,15 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let cfg_attrs = methods
|
||||
.iter()
|
||||
.map(|method| {
|
||||
let attrs =
|
||||
method.cfg_attrs.iter().map(|attr| attr.to_token_stream()).collect::<Vec<_>>();
|
||||
quote::quote!( #( #attrs )* )
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let feeless_check = methods.iter().map(|method| &method.feeless_check).collect::<Vec<_>>();
|
||||
let feeless_check_result =
|
||||
feeless_check.iter().zip(args_name.iter()).map(|(feeless_check, arg_name)| {
|
||||
@@ -297,6 +306,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#frame_support::Never,
|
||||
),
|
||||
#(
|
||||
#cfg_attrs
|
||||
#[doc = #fn_doc]
|
||||
#[codec(index = #call_index)]
|
||||
#fn_name {
|
||||
@@ -310,6 +320,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
|
||||
impl<#type_impl_gen> #call_ident<#type_use_gen> #where_clause {
|
||||
#(
|
||||
#cfg_attrs
|
||||
#[doc = #new_call_variant_doc]
|
||||
pub fn #new_call_variant_fn_name(
|
||||
#( #args_name_stripped: #args_type ),*
|
||||
@@ -328,6 +339,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
fn get_dispatch_info(&self) -> #frame_support::dispatch::DispatchInfo {
|
||||
match *self {
|
||||
#(
|
||||
#cfg_attrs
|
||||
Self::#fn_name { #( #args_name_pattern_ref, )* } => {
|
||||
let __pallet_base_weight = #fn_weight;
|
||||
|
||||
@@ -365,6 +377,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
fn is_feeless(&self, origin: &Self::Origin) -> bool {
|
||||
match *self {
|
||||
#(
|
||||
#cfg_attrs
|
||||
Self::#fn_name { #( #args_name_pattern_ref, )* } => {
|
||||
#feeless_check_result
|
||||
},
|
||||
@@ -379,13 +392,13 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
{
|
||||
fn get_call_name(&self) -> &'static str {
|
||||
match *self {
|
||||
#( Self::#fn_name { .. } => stringify!(#fn_name), )*
|
||||
#( #cfg_attrs Self::#fn_name { .. } => stringify!(#fn_name), )*
|
||||
Self::__Ignore(_, _) => unreachable!("__PhantomItem cannot be used."),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_call_names() -> &'static [&'static str] {
|
||||
&[ #( stringify!(#fn_name), )* ]
|
||||
&[ #( #cfg_attrs stringify!(#fn_name), )* ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,13 +407,13 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
{
|
||||
fn get_call_index(&self) -> u8 {
|
||||
match *self {
|
||||
#( Self::#fn_name { .. } => #call_index, )*
|
||||
#( #cfg_attrs Self::#fn_name { .. } => #call_index, )*
|
||||
Self::__Ignore(_, _) => unreachable!("__PhantomItem cannot be used."),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_call_indices() -> &'static [u8] {
|
||||
&[ #( #call_index, )* ]
|
||||
&[ #( #cfg_attrs #call_index, )* ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,6 +429,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#frame_support::dispatch_context::run_in_context(|| {
|
||||
match self {
|
||||
#(
|
||||
#cfg_attrs
|
||||
Self::#fn_name { #( #args_name_pattern, )* } => {
|
||||
#frame_support::__private::sp_tracing::enter_span!(
|
||||
#frame_support::__private::sp_tracing::trace_span!(stringify!(#fn_name))
|
||||
|
||||
@@ -16,10 +16,14 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
pallet::{parse::error::VariantField, Def},
|
||||
pallet::{
|
||||
parse::error::{VariantDef, VariantField},
|
||||
Def,
|
||||
},
|
||||
COUNTER,
|
||||
};
|
||||
use frame_support_procedural_tools::get_doc_literals;
|
||||
use quote::ToTokens;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
///
|
||||
@@ -67,20 +71,23 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
)
|
||||
);
|
||||
|
||||
let as_str_matches = error.variants.iter().map(|(variant, field_ty, _)| {
|
||||
let variant_str = variant.to_string();
|
||||
match field_ty {
|
||||
Some(VariantField { is_named: true }) => {
|
||||
quote::quote_spanned!(error.attr_span => Self::#variant { .. } => #variant_str,)
|
||||
},
|
||||
Some(VariantField { is_named: false }) => {
|
||||
quote::quote_spanned!(error.attr_span => Self::#variant(..) => #variant_str,)
|
||||
},
|
||||
None => {
|
||||
quote::quote_spanned!(error.attr_span => Self::#variant => #variant_str,)
|
||||
},
|
||||
}
|
||||
});
|
||||
let as_str_matches = error.variants.iter().map(
|
||||
|VariantDef { ident: variant, field: field_ty, docs: _, cfg_attrs }| {
|
||||
let variant_str = variant.to_string();
|
||||
let cfg_attrs = cfg_attrs.iter().map(|attr| attr.to_token_stream());
|
||||
match field_ty {
|
||||
Some(VariantField { is_named: true }) => {
|
||||
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant { .. } => #variant_str,)
|
||||
},
|
||||
Some(VariantField { is_named: false }) => {
|
||||
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant(..) => #variant_str,)
|
||||
},
|
||||
None => {
|
||||
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant => #variant_str,)
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let error_item = {
|
||||
let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[error.index];
|
||||
|
||||
Reference in New Issue
Block a user