From cbec0d12fa48887358b5d09f758bc964334a8979 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 25 May 2022 16:15:51 +0100 Subject: [PATCH 01/11] Allow construct_runtime to take cfg attributes for pallets --- Cargo.lock | 11 + frame/support/procedural/Cargo.toml | 2 + .../src/construct_runtime/expand/call.rs | 32 ++- .../src/construct_runtime/expand/config.rs | 24 ++- .../src/construct_runtime/expand/event.rs | 49 ++++- .../src/construct_runtime/expand/inherent.rs | 58 +++-- .../src/construct_runtime/expand/metadata.rs | 13 ++ .../src/construct_runtime/expand/origin.rs | 51 ++++- .../src/construct_runtime/expand/unsigned.rs | 24 ++- .../procedural/src/construct_runtime/mod.rs | 198 ++++++++++++++---- .../procedural/src/construct_runtime/parse.rs | 43 +++- .../feature_gated_system_pallet.rs | 14 ++ .../feature_gated_system_pallet.stderr | 5 + .../invalid_meta_literal.rs | 15 ++ .../invalid_meta_literal.stderr | 6 + .../unsupported_meta_structure.rs | 15 ++ .../unsupported_meta_structure.stderr | 6 + .../unsupported_pallet_attr.rs | 15 ++ .../unsupported_pallet_attr.stderr | 5 + frame/support/test/tests/pallet.rs | 2 + 20 files changed, 507 insertions(+), 81 deletions(-) create mode 100644 frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.rs create mode 100644 frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.stderr create mode 100644 frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs create mode 100644 frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.stderr create mode 100644 frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs create mode 100644 frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.stderr create mode 100644 frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs create mode 100644 frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.stderr diff --git a/Cargo.lock b/Cargo.lock index d68330cfb15c2..f068b6f2f163e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -856,6 +856,15 @@ dependencies = [ "nom", ] +[[package]] +name = "cfg-expr" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aacacf4d96c24b2ad6eb8ee6df040e4f27b0d0b39a5710c30091baa830485db" +dependencies = [ + "smallvec", +] + [[package]] name = "cfg-if" version = "0.1.10" @@ -2294,7 +2303,9 @@ name = "frame-support-procedural" version = "4.0.0-dev" dependencies = [ "Inflector", + "cfg-expr", "frame-support-procedural-tools", + "itertools", "proc-macro2", "quote", "syn", diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index 7ddec39cad9fb..06b8056aff982 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -16,6 +16,8 @@ proc-macro = true [dependencies] Inflector = "0.11.4" +cfg-expr = "0.10.3" +itertools = "0.10.3" proc-macro2 = "1.0.37" quote = "1.0.10" syn = { version = "1.0.98", features = ["full"] } diff --git a/frame/support/procedural/src/construct_runtime/expand/call.rs b/frame/support/procedural/src/construct_runtime/expand/call.rs index c8c5d5ff0ee43..91b7b38de4707 100644 --- a/frame/support/procedural/src/construct_runtime/expand/call.rs +++ b/frame/support/procedural/src/construct_runtime/expand/call.rs @@ -18,6 +18,7 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream; use quote::quote; +use std::str::FromStr; use syn::Ident; pub fn expand_outer_dispatch( @@ -30,6 +31,7 @@ pub fn expand_outer_dispatch( let mut variant_patterns = Vec::new(); let mut query_call_part_macros = Vec::new(); let mut pallet_names = Vec::new(); + let mut pallet_attrs = Vec::new(); let system_path = &system_pallet.path; let pallets_with_call = pallet_decls.iter().filter(|decl| decl.exists_part("Call")); @@ -38,12 +40,28 @@ pub fn expand_outer_dispatch( let name = &pallet_declaration.name; let path = &pallet_declaration.path; let index = pallet_declaration.index; + let attr = pallet_declaration + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); variant_defs.extend( - quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),), + quote! { + #attr + #[codec(index = #index)] + #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ), + } ); variant_patterns.push(quote!(Call::#name(call))); pallet_names.push(name); + pallet_attrs.push(attr); query_call_part_macros.push(quote! { #path::__substrate_call_check::is_call_part_defined!(#name); }); @@ -69,6 +87,7 @@ pub fn expand_outer_dispatch( use #scrate::dispatch::Callable; use core::mem::size_of; &[#( + #pallet_attrs ( stringify!(#pallet_names), size_of::< <#pallet_names as Callable<#runtime>>::Call >(), @@ -101,7 +120,10 @@ pub fn expand_outer_dispatch( impl #scrate::dispatch::GetDispatchInfo for Call { fn get_dispatch_info(&self) -> #scrate::dispatch::DispatchInfo { match self { - #( #variant_patterns => call.get_dispatch_info(), )* + #( + #pallet_attrs + #variant_patterns => call.get_dispatch_info(), + )* } } } @@ -110,6 +132,7 @@ pub fn expand_outer_dispatch( use #scrate::dispatch::GetCallName; match self { #( + #pallet_attrs #variant_patterns => { let function_name = call.get_call_name(); let pallet_name = stringify!(#pallet_names); @@ -121,6 +144,7 @@ pub fn expand_outer_dispatch( fn get_module_names() -> &'static [&'static str] { &[#( + #pallet_attrs stringify!(#pallet_names), )*] } @@ -129,6 +153,7 @@ pub fn expand_outer_dispatch( use #scrate::dispatch::{Callable, GetCallName}; match module { #( + #pallet_attrs stringify!(#pallet_names) => <<#pallet_names as Callable<#runtime>>::Call as GetCallName>::get_call_names(), @@ -157,6 +182,7 @@ pub fn expand_outer_dispatch( fn dispatch_bypass_filter(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo { match self { #( + #pallet_attrs #variant_patterns => #scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(call, origin), )* @@ -178,6 +204,7 @@ pub fn expand_outer_dispatch( } #( + #pallet_attrs impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call { #[allow(unreachable_patterns)] fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> { @@ -189,6 +216,7 @@ pub fn expand_outer_dispatch( } } + #pallet_attrs impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call { fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self { #variant_patterns diff --git a/frame/support/procedural/src/construct_runtime/expand/config.rs b/frame/support/procedural/src/construct_runtime/expand/config.rs index a3d70f18529c7..d1e385f316b95 100644 --- a/frame/support/procedural/src/construct_runtime/expand/config.rs +++ b/frame/support/procedural/src/construct_runtime/expand/config.rs @@ -19,6 +19,7 @@ use crate::construct_runtime::Pallet; use inflector::Inflector; use proc_macro2::TokenStream; use quote::{format_ident, quote, ToTokens}; +use std::str::FromStr; use syn::Ident; pub fn expand_outer_config( @@ -40,11 +41,22 @@ pub fn expand_outer_config( let field_name = &Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span()); let part_is_generic = !pallet_entry.generics.params.is_empty(); + let attr = &decl + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); - types.extend(expand_config_types(runtime, decl, &config, part_is_generic)); - fields.extend(quote!(pub #field_name: #config,)); + types.extend(expand_config_types(attr, runtime, decl, &config, part_is_generic)); + fields.extend(quote!(#attr pub #field_name: #config,)); build_storage_calls - .extend(expand_config_build_storage_call(scrate, runtime, decl, field_name)); + .extend(expand_config_build_storage_call(scrate, attr, runtime, decl, field_name)); query_genesis_config_part_macros.push(quote! { #path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name); #[cfg(feature = "std")] @@ -88,6 +100,7 @@ pub fn expand_outer_config( } fn expand_config_types( + attr: &TokenStream, runtime: &Ident, decl: &Pallet, config: &Ident, @@ -97,14 +110,17 @@ fn expand_config_types( match (decl.instance.as_ref(), part_is_generic) { (Some(inst), true) => quote! { + #attr #[cfg(any(feature = "std", test))] pub type #config = #path::GenesisConfig<#runtime, #path::#inst>; }, (None, true) => quote! { + #attr #[cfg(any(feature = "std", test))] pub type #config = #path::GenesisConfig<#runtime>; }, (_, false) => quote! { + #attr #[cfg(any(feature = "std", test))] pub type #config = #path::GenesisConfig; }, @@ -113,6 +129,7 @@ fn expand_config_types( fn expand_config_build_storage_call( scrate: &TokenStream, + attr: &TokenStream, runtime: &Ident, decl: &Pallet, field_name: &Ident, @@ -125,6 +142,7 @@ fn expand_config_build_storage_call( }; quote! { + #attr #scrate::sp_runtime::BuildModuleGenesisStorage:: <#runtime, #instance>::build_module_genesis_storage(&self.#field_name, storage)?; } diff --git a/frame/support/procedural/src/construct_runtime/expand/event.rs b/frame/support/procedural/src/construct_runtime/expand/event.rs index b242f9641562c..39e31b61a9656 100644 --- a/frame/support/procedural/src/construct_runtime/expand/event.rs +++ b/frame/support/procedural/src/construct_runtime/expand/event.rs @@ -18,6 +18,7 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream; use quote::quote; +use std::str::FromStr; use syn::{Generics, Ident}; pub fn expand_outer_event( @@ -97,19 +98,38 @@ fn expand_event_variant( let path = &pallet.path; let variant_name = &pallet.name; let part_is_generic = !generics.params.is_empty(); + let attr = pallet + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); match instance { - Some(inst) if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),) + Some(inst) if part_is_generic => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Event<#runtime, #path::#inst>), }, - Some(inst) => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),) + Some(inst) => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Event<#path::#inst>), }, - None if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),) + None if part_is_generic => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Event<#runtime>), }, - None => { - quote!(#[codec(index = #index)] #variant_name(#path::Event),) + None => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Event), }, } } @@ -120,13 +140,26 @@ fn expand_event_conversion( pallet_event: &TokenStream, ) -> TokenStream { let variant_name = &pallet.name; + let attr = pallet + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); quote! { + #attr impl From<#pallet_event> for Event { fn from(x: #pallet_event) -> Self { Event::#variant_name(x) } } + #attr impl TryInto<#pallet_event> for Event { type Error = (); diff --git a/frame/support/procedural/src/construct_runtime/expand/inherent.rs b/frame/support/procedural/src/construct_runtime/expand/inherent.rs index 0f0d538643240..c8407ced3c39e 100644 --- a/frame/support/procedural/src/construct_runtime/expand/inherent.rs +++ b/frame/support/procedural/src/construct_runtime/expand/inherent.rs @@ -18,6 +18,7 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream; use quote::quote; +use std::str::FromStr; use syn::{Ident, TypePath}; pub fn expand_outer_inherent( @@ -28,14 +29,27 @@ pub fn expand_outer_inherent( scrate: &TokenStream, ) -> TokenStream { let mut pallet_names = Vec::new(); + let mut pallet_attrs = Vec::new(); let mut query_inherent_part_macros = Vec::new(); for pallet_decl in pallet_decls { if pallet_decl.exists_part("Inherent") { let name = &pallet_decl.name; let path = &pallet_decl.path; + let attr = pallet_decl + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); pallet_names.push(name); + pallet_attrs.push(attr); query_inherent_part_macros.push(quote! { #path::__substrate_inherent_check::is_inherent_part_defined!(#name); }); @@ -60,6 +74,7 @@ pub fn expand_outer_inherent( let mut inherents = Vec::new(); #( + #pallet_attrs if let Some(inherent) = #pallet_names::create_inherent(self) { let inherent = <#unchecked_extrinsic as #scrate::inherent::Extrinsic>::new( inherent.into(), @@ -90,22 +105,25 @@ pub fn expand_outer_inherent( let mut is_inherent = false; - #({ - let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt); - if let Some(call) = IsSubType::<_>::is_sub_type(call) { - if #pallet_names::is_inherent(call) { - is_inherent = true; - if let Err(e) = #pallet_names::check_inherent(call, self) { - result.put_error( - #pallet_names::INHERENT_IDENTIFIER, &e - ).expect("There is only one fatal error; qed"); - if e.is_fatal_error() { - return result; + #( + #pallet_attrs + { + let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt); + if let Some(call) = IsSubType::<_>::is_sub_type(call) { + if #pallet_names::is_inherent(call) { + is_inherent = true; + if let Err(e) = #pallet_names::check_inherent(call, self) { + result.put_error( + #pallet_names::INHERENT_IDENTIFIER, &e + ).expect("There is only one fatal error; qed"); + if e.is_fatal_error() { + return result; + } } } } } - })* + )* // Inherents are before any other extrinsics. // No module marked it as inherent thus it is not. @@ -115,6 +133,7 @@ pub fn expand_outer_inherent( } #( + #pallet_attrs match #pallet_names::is_inherent_required(self) { Ok(Some(e)) => { let found = block.extrinsics().iter().any(|xt| { @@ -177,14 +196,17 @@ pub fn expand_outer_inherent( false } else { let mut is_inherent = false; - #({ - let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt); - if let Some(call) = IsSubType::<_>::is_sub_type(call) { - if #pallet_names::is_inherent(&call) { - is_inherent = true; + #( + #pallet_attrs + { + let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt); + if let Some(call) = IsSubType::<_>::is_sub_type(call) { + if #pallet_names::is_inherent(&call) { + is_inherent = true; + } } } - })* + )* is_inherent }; diff --git a/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 6e2dd5fc002c6..5e248fcd0ba22 100644 --- a/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -18,6 +18,7 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream; use quote::quote; +use std::str::FromStr; use syn::{Ident, TypePath}; pub fn expand_runtime_metadata( @@ -47,8 +48,20 @@ pub fn expand_runtime_metadata( let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl); let constants = expand_pallet_metadata_constants(runtime, decl); let errors = expand_pallet_metadata_errors(runtime, decl); + let attr = decl + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); quote! { + #attr #scrate::metadata::PalletMetadata { name: stringify!(#name), index: #index, diff --git a/frame/support/procedural/src/construct_runtime/expand/origin.rs b/frame/support/procedural/src/construct_runtime/expand/origin.rs index 46f08832f0bb4..8b2747616494c 100644 --- a/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -18,6 +18,7 @@ use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME}; use proc_macro2::TokenStream; use quote::quote; +use std::str::FromStr; use syn::{Generics, Ident}; pub fn expand_outer_origin( @@ -303,19 +304,38 @@ fn expand_origin_caller_variant( let part_is_generic = !generics.params.is_empty(); let variant_name = &pallet.name; let path = &pallet.path; + let attr = pallet + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); match instance { - Some(inst) if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime, #path::#inst>),) + Some(inst) if part_is_generic => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Origin<#runtime, #path::#inst>), }, - Some(inst) => { - quote!(#[codec(index = #index)] #variant_name(#path::Origin<#path::#inst>),) + Some(inst) => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Origin<#path::#inst>), }, - None if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime>),) + None if part_is_generic => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Origin<#runtime>), }, - None => { - quote!(#[codec(index = #index)] #variant_name(#path::Origin),) + None => quote! { + #attr + #[codec(index = #index)] + #variant_name(#path::Origin), }, } } @@ -339,14 +359,27 @@ fn expand_origin_pallet_conversions( }; let doc_string = get_intra_doc_string(" Convert to runtime origin using", &path.module_name()); + let attr = pallet + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); quote! { + #attr impl From<#pallet_origin> for OriginCaller { fn from(x: #pallet_origin) -> Self { OriginCaller::#variant_name(x) } } + #attr impl From<#pallet_origin> for Origin { #[doc = #doc_string] fn from(x: #pallet_origin) -> Self { @@ -355,6 +388,7 @@ fn expand_origin_pallet_conversions( } } + #attr impl From for #scrate::sp_std::result::Result<#pallet_origin, Origin> { /// NOTE: converting to pallet origin loses the origin filter information. fn from(val: Origin) -> Self { @@ -366,6 +400,7 @@ fn expand_origin_pallet_conversions( } } + #attr impl TryFrom for #pallet_origin { type Error = OriginCaller; fn try_from( diff --git a/frame/support/procedural/src/construct_runtime/expand/unsigned.rs b/frame/support/procedural/src/construct_runtime/expand/unsigned.rs index c030676802093..cb7960f56e6bc 100644 --- a/frame/support/procedural/src/construct_runtime/expand/unsigned.rs +++ b/frame/support/procedural/src/construct_runtime/expand/unsigned.rs @@ -18,6 +18,7 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream; use quote::quote; +use std::str::FromStr; use syn::Ident; pub fn expand_outer_validate_unsigned( @@ -26,14 +27,27 @@ pub fn expand_outer_validate_unsigned( scrate: &TokenStream, ) -> TokenStream { let mut pallet_names = Vec::new(); + let mut pallet_attrs = Vec::new(); let mut query_validate_unsigned_part_macros = Vec::new(); for pallet_decl in pallet_decls { if pallet_decl.exists_part("ValidateUnsigned") { let name = &pallet_decl.name; let path = &pallet_decl.path; + let attr = pallet_decl + .cfg_pattern + .iter() + .fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); pallet_names.push(name); + pallet_attrs.push(attr); query_validate_unsigned_part_macros.push(quote! { #path::__substrate_validate_unsigned_check::is_validate_unsigned_part_defined!(#name); }); @@ -49,7 +63,10 @@ pub fn expand_outer_validate_unsigned( fn pre_dispatch(call: &Self::Call) -> Result<(), #scrate::unsigned::TransactionValidityError> { #[allow(unreachable_patterns)] match call { - #( Call::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call), )* + #( + #pallet_attrs + Call::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call), + )* // pre-dispatch should not stop inherent extrinsics, validation should prevent // including arbitrary (non-inherent) extrinsics to blocks. _ => Ok(()), @@ -63,7 +80,10 @@ pub fn expand_outer_validate_unsigned( ) -> #scrate::unsigned::TransactionValidity { #[allow(unreachable_patterns)] match call { - #( Call::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call), )* + #( + #pallet_attrs + Call::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call), + )* _ => #scrate::unsigned::UnknownTransaction::NoUnsignedValidator.into(), } } diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 7b4156a94db58..01f6bfefb0c15 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -144,9 +144,11 @@ mod expand; mod parse; +use cfg_expr::Predicate; use frame_support_procedural_tools::{ generate_crate_access, generate_crate_access_2018, generate_hidden_includes, }; +use itertools::Itertools; use parse::{ ExplicitRuntimeDeclaration, ImplicitRuntimeDeclaration, Pallet, RuntimeDeclaration, WhereSection, @@ -154,6 +156,10 @@ use parse::{ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; +use std::{ + collections::{HashMap, HashSet}, + str::FromStr, +}; use syn::{Ident, Result}; /// The fixed name of the system pallet. @@ -223,6 +229,28 @@ fn construct_runtime_final_expansion( Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},`", ) })?; + if !system_pallet.cfg_pattern.is_empty() { + return Err(syn::Error::new( + system_pallet.name.span(), + "`System` pallet declaration is feature gated, please remove any `#[cfg]` attributes", + )) + } + + let features = pallets + .iter() + .filter_map(|decl| { + (!decl.cfg_pattern.is_empty()).then(|| { + decl.cfg_pattern.iter().flat_map(|attr| { + attr.predicates().filter_map(|pred| match pred { + Predicate::Feature(feat) => Some(feat), + Predicate::Test => Some("test"), + _ => None, + }) + }) + }) + }) + .flatten() + .collect::>(); let hidden_crate_name = "construct_runtime"; let scrate = generate_crate_access(hidden_crate_name, "frame-support"); @@ -231,7 +259,7 @@ fn construct_runtime_final_expansion( let outer_event = expand::expand_outer_event(&name, &pallets, &scrate)?; let outer_origin = expand::expand_outer_origin(&name, system_pallet, &pallets, &scrate)?; - let all_pallets = decl_all_pallets(&name, pallets.iter()); + let all_pallets = decl_all_pallets(&name, pallets.iter(), &features); let pallet_to_index = decl_pallet_runtime_setup(&name, &pallets, &scrate); let dispatch = expand::expand_outer_dispatch(&name, system_pallet, &pallets, &scrate); @@ -293,61 +321,141 @@ fn construct_runtime_final_expansion( fn decl_all_pallets<'a>( runtime: &'a Ident, pallet_declarations: impl Iterator, + features: &HashSet<&str>, ) -> TokenStream2 { let mut types = TokenStream2::new(); - let mut names = Vec::new(); + let mut names_by_feature = features + .iter() + .powerset() + .map(|feat| (feat, Vec::new())) + .collect::>(); for pallet_declaration in pallet_declarations { let type_name = &pallet_declaration.name; let pallet = &pallet_declaration.path; let mut generics = vec![quote!(#runtime)]; generics.extend(pallet_declaration.instance.iter().map(|name| quote!(#pallet::#name))); + let mut attrs = Vec::new(); + for cfg in &pallet_declaration.cfg_pattern { + let feat = format!("#[cfg({})]\n", cfg.original()); + attrs.extend(TokenStream2::from_str(&feat).expect("was parsed successfully; qed")); + } let type_decl = quote!( + #(#attrs)* pub type #type_name = #pallet::Pallet <#(#generics),*>; ); types.extend(type_decl); - names.push(&pallet_declaration.name); + + if pallet_declaration.cfg_pattern.is_empty() { + for names in names_by_feature.values_mut() { + names.push(&pallet_declaration.name); + } + } else { + for (feature_set, names) in &mut names_by_feature { + // Rust tidbit: if we have multiple `#[cfg]` feature on the same item, then the + // predicates listed in all `#[cfg]` attributes are effectively joined by `and()`, + // meaning that all of them must match in order to activate the item + let is_feature_active = pallet_declaration.cfg_pattern.iter().all(|expr| { + expr.eval(|pred| match pred { + Predicate::Feature(f) => feature_set.contains(&f), + Predicate::Test => feature_set.contains(&&"test"), + _ => false, + }) + }); + if is_feature_active { + names.push(&pallet_declaration.name); + } + } + } } // Make nested tuple structure like: // `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))` // But ignore the system pallet. - let all_pallets_without_system = names - .iter() - .filter(|n| **n != SYSTEM_PALLET_NAME) - .rev() - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + let all_pallets_without_system = names_by_feature.iter().map(|(feature_set, names)| { + let mut feature_set = feature_set.iter().collect::>(); + let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); + let feature_set = feature_set.into_iter(); + let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let pallets_tuple = names + .iter() + .filter(|n| **n != SYSTEM_PALLET_NAME) + .rev() + .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + quote! { + #attr + /// All pallets included in the runtime as a nested tuple of types. + /// Excludes the System pallet. + pub type AllPalletsWithoutSystem = ( #pallets_tuple ); + } + }); // Make nested tuple structure like: // `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))` - let all_pallets_with_system = names - .iter() - .rev() - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + let all_pallets_with_system = names_by_feature.iter().map(|(feature_set, names)| { + let mut feature_set = feature_set.iter().collect::>(); + let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); + let feature_set = feature_set.into_iter(); + let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let pallets_tuple = names + .iter() + .rev() + .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + quote! { + #attr + /// All pallets included in the runtime as a nested tuple of types. + pub type AllPalletsWithSystem = ( #pallets_tuple ); + } + }); // Make nested tuple structure like: // `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))` // But ignore the system pallet. - let all_pallets_without_system_reversed = names - .iter() - .filter(|n| **n != SYSTEM_PALLET_NAME) - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + let all_pallets_without_system_reversed = + names_by_feature.iter().map(|(feature_set, names)| { + let mut feature_set = feature_set.iter().collect::>(); + let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); + let feature_set = feature_set.into_iter(); + let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let pallets_tuple = names + .iter() + .filter(|n| **n != SYSTEM_PALLET_NAME) + .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + quote! { + #attr + /// All pallets included in the runtime as a nested tuple of types in reversed order. + /// Excludes the System pallet. + pub type AllPalletsWithoutSystemReversed = ( #pallets_tuple ); + } + }); // Make nested tuple structure like: // `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))` - let all_pallets_with_system_reversed = names - .iter() - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + let all_pallets_with_system_reversed = names_by_feature.iter().map(|(feature_set, names)| { + let mut feature_set = feature_set.iter().collect::>(); + let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); + let feature_set = feature_set.into_iter(); + let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let pallets_tuple = names + .iter() + .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); + quote! { + #attr + /// All pallets included in the runtime as a nested tuple of types in reversed order. + pub type AllPalletsWithSystemReversed = ( #pallets_tuple ); + } + }); - let system_pallet = match names.iter().find(|n| **n == SYSTEM_PALLET_NAME) { - Some(name) => name, - None => - return syn::Error::new( - proc_macro2::Span::call_site(), - "`System` pallet declaration is missing. \ + let system_pallet = + match names_by_feature[&Vec::new()].iter().find(|n| **n == SYSTEM_PALLET_NAME) { + Some(name) => name, + None => + return syn::Error::new( + proc_macro2::Span::call_site(), + "`System` pallet declaration is missing. \ Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},`", - ) - .into_compile_error(), - }; + ) + .into_compile_error(), + }; quote!( #types @@ -363,19 +471,13 @@ fn decl_all_pallets<'a>( https://github.com/paritytech/substrate/pull/10043")] pub type AllPallets = AllPalletsWithSystem; - /// All pallets included in the runtime as a nested tuple of types. - pub type AllPalletsWithSystem = ( #all_pallets_with_system ); + #( #all_pallets_with_system )* - /// All pallets included in the runtime as a nested tuple of types. - /// Excludes the System pallet. - pub type AllPalletsWithoutSystem = ( #all_pallets_without_system ); + #( #all_pallets_without_system )* - /// All pallets included in the runtime as a nested tuple of types in reversed order. - /// Excludes the System pallet. - pub type AllPalletsWithoutSystemReversed = ( #all_pallets_without_system_reversed ); + #( #all_pallets_without_system_reversed )* - /// All pallets included in the runtime as a nested tuple of types in reversed order. - pub type AllPalletsWithSystemReversed = ( #all_pallets_with_system_reversed ); + #( #all_pallets_with_system_reversed )* /// All pallets included in the runtime as a nested tuple of types in reversed order. /// With the system pallet first. @@ -405,6 +507,22 @@ fn decl_pallet_runtime_setup( } }) .collect::>(); + let pallet_attrs = pallet_declarations + .iter() + .map(|pallet| { + pallet + .cfg_pattern + .iter() + .fold(TokenStream2::new(), |acc, pattern| { + let attr = TokenStream2::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }) + }) + .collect::>(); quote!( /// Provides an implementation of `PalletInfo` to provide information @@ -415,6 +533,7 @@ fn decl_pallet_runtime_setup( fn index() -> Option { let type_id = #scrate::sp_std::any::TypeId::of::

(); #( + #pallet_attrs if type_id == #scrate::sp_std::any::TypeId::of::<#names>() { return Some(#indices) } @@ -426,6 +545,7 @@ fn decl_pallet_runtime_setup( fn name() -> Option<&'static str> { let type_id = #scrate::sp_std::any::TypeId::of::

(); #( + #pallet_attrs if type_id == #scrate::sp_std::any::TypeId::of::<#names>() { return Some(#name_strings) } @@ -437,6 +557,7 @@ fn decl_pallet_runtime_setup( fn module_name() -> Option<&'static str> { let type_id = #scrate::sp_std::any::TypeId::of::

(); #( + #pallet_attrs if type_id == #scrate::sp_std::any::TypeId::of::<#names>() { return Some(#module_names) } @@ -448,6 +569,7 @@ fn decl_pallet_runtime_setup( fn crate_version() -> Option<#scrate::traits::CrateVersion> { let type_id = #scrate::sp_std::any::TypeId::of::

(); #( + #pallet_attrs if type_id == #scrate::sp_std::any::TypeId::of::<#names>() { return Some( <#pallet_structs as #scrate::traits::PalletInfoAccess>::crate_version() diff --git a/frame/support/procedural/src/construct_runtime/parse.rs b/frame/support/procedural/src/construct_runtime/parse.rs index a2cda6a0777b8..d9ff4a95a9f56 100644 --- a/frame/support/procedural/src/construct_runtime/parse.rs +++ b/frame/support/procedural/src/construct_runtime/parse.rs @@ -23,7 +23,7 @@ use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, spanned::Spanned, - token, Error, Ident, Path, Result, Token, + token, Attribute, Error, Ident, Path, Result, Token, }; mod keyword { @@ -178,6 +178,8 @@ impl Parse for WhereDefinition { pub struct PalletDeclaration { /// The name of the pallet, e.g.`System` in `System: frame_system`. pub name: Ident, + /// Optional attributes tagged right above a pallet declaration. + pub attrs: Vec, /// Optional fixed index, e.g. `MyPallet ... = 3,`. pub index: Option, /// The path of the pallet, e.g. `frame_system` in `System: frame_system`. @@ -205,6 +207,8 @@ pub enum SpecifiedParts { impl Parse for PalletDeclaration { fn parse(input: ParseStream) -> Result { + let attrs = input.call(Attribute::parse_outer)?; + let name = input.parse()?; let _: Token![:] = input.parse()?; let path = input.parse()?; @@ -272,7 +276,7 @@ impl Parse for PalletDeclaration { None }; - Ok(Self { name, path, instance, pallet_parts, specified_parts, index }) + Ok(Self { attrs, name, path, instance, pallet_parts, specified_parts, index }) } } @@ -528,6 +532,8 @@ pub struct Pallet { pub instance: Option, /// The pallet parts to use for the pallet. pub pallet_parts: Vec, + /// Expressions specified inside of a #[cfg] attribute. + pub cfg_pattern: Vec, } impl Pallet { @@ -640,11 +646,44 @@ fn convert_pallets(pallets: Vec) -> syn::Result (), } + // let meta = attr.parse_meta()?; + // match meta { + // Meta::List(MetaList { path: Path { segments, .. }, nested, .. }) if segments.len() == + // 1 && segments[0].ident == "cfg" => { let predicates = + // cfg_expr::expr::Expression::parse(&nested.into_token_stream().to_string()) + // .map_err(|e| syn::Error::new(attr.span(), &e.to_string()))?; + // }, + // _ => { + // let msg = "Unsupported attribute, only #[cfg] is supported on pallet declarations in + // `construct_runtime`"; return Err(syn::Error::new(attr.span(), msg)) + // } + // } + let cfg_pattern = pallet + .attrs + .iter() + .map(|attr| { + if attr.path.segments.len() != 1 || attr.path.segments[0].ident != "cfg" { + let msg = "Unsupported attribute, only #[cfg] is supported on pallet \ + declarations in `construct_runtime`"; + return Err(syn::Error::new(attr.span(), msg)) + } + + attr.parse_args_with(|input: syn::parse::ParseStream| { + // Required, otherwise the parse stream doesn't advance and will result in + // an error. + let input = input.parse::()?; + cfg_expr::Expression::parse(&input.to_string()) + .map_err(|e| syn::Error::new(attr.span(), e.to_string())) + }) + }) + .collect::>>()?; + Ok(Pallet { name: pallet.name, index: final_index, path: pallet.path, instance: pallet.instance, + cfg_pattern, pallet_parts, }) }) diff --git a/frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.rs b/frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.rs new file mode 100644 index 0000000000000..79b5632babd95 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.rs @@ -0,0 +1,14 @@ +use frame_support::construct_runtime; + +construct_runtime! { + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + #[cfg(test)] + System: frame_system::{Pallet, Call, Storage, Config, Event}, + } +} + +fn main() {} diff --git a/frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.stderr b/frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.stderr new file mode 100644 index 0000000000000..a86a839615aa0 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/feature_gated_system_pallet.stderr @@ -0,0 +1,5 @@ +error: `System` pallet declaration is feature gated, please remove any `#[cfg]` attributes + --> tests/construct_runtime_ui/feature_gated_system_pallet.rs:10:3 + | +10 | System: frame_system::{Pallet, Call, Storage, Config, Event}, + | ^^^^^^ diff --git a/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs b/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs new file mode 100644 index 0000000000000..f4cc643c25a39 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs @@ -0,0 +1,15 @@ +use frame_support::construct_runtime; + +construct_runtime! { + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: system::{Pallet}, + #[cfg(feature = 1)] + Balance: balances::{Config, Call}, + } +} + +fn main() {} \ No newline at end of file diff --git a/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.stderr b/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.stderr new file mode 100644 index 0000000000000..68366a3410bf1 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.stderr @@ -0,0 +1,6 @@ +error: feature = 1 + ^ expected one of ``, `all`, `any`, `not` here + --> tests/construct_runtime_ui/invalid_meta_literal.rs:10:3 + | +10 | #[cfg(feature = 1)] + | ^ diff --git a/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs b/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs new file mode 100644 index 0000000000000..f50fe758f085b --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs @@ -0,0 +1,15 @@ +use frame_support::construct_runtime; + +construct_runtime! { + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: system::{Pallet}, + #[cfg(feature(test))] + Balance: balances::{Config, Call}, + } +} + +fn main() {} \ No newline at end of file diff --git a/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.stderr b/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.stderr new file mode 100644 index 0000000000000..98d99a0d34997 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.stderr @@ -0,0 +1,6 @@ +error: feature(test) + ^ expected one of `=`, `,`, `)` here + --> tests/construct_runtime_ui/unsupported_meta_structure.rs:10:3 + | +10 | #[cfg(feature(test))] + | ^ diff --git a/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs b/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs new file mode 100644 index 0000000000000..798f5e42c7f8d --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs @@ -0,0 +1,15 @@ +use frame_support::construct_runtime; + +construct_runtime! { + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: system::{Pallet}, + #[attr] + Balance: balances::{Config, Call}, + } +} + +fn main() {} \ No newline at end of file diff --git a/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.stderr b/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.stderr new file mode 100644 index 0000000000000..fceb2b8a99db8 --- /dev/null +++ b/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.stderr @@ -0,0 +1,5 @@ +error: Unsupported attribute, only #[cfg] is supported on pallet declarations in `construct_runtime` + --> tests/construct_runtime_ui/unsupported_pallet_attr.rs:10:3 + | +10 | #[attr] + | ^ diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 6b72327eb4989..084f483ec71fa 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -601,6 +601,8 @@ frame_support::construct_runtime!( System: frame_system exclude_parts { Pallet, Storage }, Example: pallet, Example2: pallet2 exclude_parts { Call }, + #[cfg(feature = "example3")] + Example3: pallet3, Example4: pallet4 use_parts { Call }, } ); From 4588084787ac58f7ae4bfc9613a7208a71024dd4 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 12 Jul 2022 14:40:42 +0800 Subject: [PATCH 02/11] cargo fmt --- .../src/construct_runtime/expand/call.rs | 18 ++++----- .../src/construct_runtime/expand/config.rs | 19 ++++------ .../src/construct_runtime/expand/event.rs | 38 ++++++++----------- .../src/construct_runtime/expand/inherent.rs | 19 ++++------ .../src/construct_runtime/expand/metadata.rs | 19 ++++------ .../src/construct_runtime/expand/origin.rs | 38 ++++++++----------- .../src/construct_runtime/expand/unsigned.rs | 19 ++++------ .../procedural/src/construct_runtime/mod.rs | 19 ++++------ 8 files changed, 79 insertions(+), 110 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/expand/call.rs b/frame/support/procedural/src/construct_runtime/expand/call.rs index 91b7b38de4707..b75f6c7a6ba1a 100644 --- a/frame/support/procedural/src/construct_runtime/expand/call.rs +++ b/frame/support/procedural/src/construct_runtime/expand/call.rs @@ -40,10 +40,8 @@ pub fn expand_outer_dispatch( let name = &pallet_declaration.name; let path = &pallet_declaration.path; let index = pallet_declaration.index; - let attr = pallet_declaration - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { + let attr = + pallet_declaration.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) .expect("was successfully parsed before; qed"); quote! { @@ -52,13 +50,11 @@ pub fn expand_outer_dispatch( } }); - variant_defs.extend( - quote! { - #attr - #[codec(index = #index)] - #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ), - } - ); + variant_defs.extend(quote! { + #attr + #[codec(index = #index)] + #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ), + }); variant_patterns.push(quote!(Call::#name(call))); pallet_names.push(name); pallet_attrs.push(attr); diff --git a/frame/support/procedural/src/construct_runtime/expand/config.rs b/frame/support/procedural/src/construct_runtime/expand/config.rs index d1e385f316b95..9b731a5825a3c 100644 --- a/frame/support/procedural/src/construct_runtime/expand/config.rs +++ b/frame/support/procedural/src/construct_runtime/expand/config.rs @@ -41,17 +41,14 @@ pub fn expand_outer_config( let field_name = &Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span()); let part_is_generic = !pallet_entry.generics.params.is_empty(); - let attr = &decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = &decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); types.extend(expand_config_types(attr, runtime, decl, &config, part_is_generic)); fields.extend(quote!(#attr pub #field_name: #config,)); diff --git a/frame/support/procedural/src/construct_runtime/expand/event.rs b/frame/support/procedural/src/construct_runtime/expand/event.rs index 39e31b61a9656..f145327d37af5 100644 --- a/frame/support/procedural/src/construct_runtime/expand/event.rs +++ b/frame/support/procedural/src/construct_runtime/expand/event.rs @@ -98,17 +98,14 @@ fn expand_event_variant( let path = &pallet.path; let variant_name = &pallet.name; let part_is_generic = !generics.params.is_empty(); - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = pallet.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); match instance { Some(inst) if part_is_generic => quote! { @@ -140,17 +137,14 @@ fn expand_event_conversion( pallet_event: &TokenStream, ) -> TokenStream { let variant_name = &pallet.name; - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = pallet.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); quote! { #attr diff --git a/frame/support/procedural/src/construct_runtime/expand/inherent.rs b/frame/support/procedural/src/construct_runtime/expand/inherent.rs index c8407ced3c39e..599b34ba87241 100644 --- a/frame/support/procedural/src/construct_runtime/expand/inherent.rs +++ b/frame/support/procedural/src/construct_runtime/expand/inherent.rs @@ -36,17 +36,14 @@ pub fn expand_outer_inherent( if pallet_decl.exists_part("Inherent") { let name = &pallet_decl.name; let path = &pallet_decl.path; - let attr = pallet_decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = pallet_decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); pallet_names.push(name); pallet_attrs.push(attr); diff --git a/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 5e248fcd0ba22..ec90a0d30f98b 100644 --- a/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -48,17 +48,14 @@ pub fn expand_runtime_metadata( let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl); let constants = expand_pallet_metadata_constants(runtime, decl); let errors = expand_pallet_metadata_errors(runtime, decl); - let attr = decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); quote! { #attr diff --git a/frame/support/procedural/src/construct_runtime/expand/origin.rs b/frame/support/procedural/src/construct_runtime/expand/origin.rs index 8b2747616494c..a4bb0d9cbaa02 100644 --- a/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -304,17 +304,14 @@ fn expand_origin_caller_variant( let part_is_generic = !generics.params.is_empty(); let variant_name = &pallet.name; let path = &pallet.path; - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = pallet.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); match instance { Some(inst) if part_is_generic => quote! { @@ -359,17 +356,14 @@ fn expand_origin_pallet_conversions( }; let doc_string = get_intra_doc_string(" Convert to runtime origin using", &path.module_name()); - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = pallet.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); quote! { #attr diff --git a/frame/support/procedural/src/construct_runtime/expand/unsigned.rs b/frame/support/procedural/src/construct_runtime/expand/unsigned.rs index cb7960f56e6bc..310516793472f 100644 --- a/frame/support/procedural/src/construct_runtime/expand/unsigned.rs +++ b/frame/support/procedural/src/construct_runtime/expand/unsigned.rs @@ -34,17 +34,14 @@ pub fn expand_outer_validate_unsigned( if pallet_decl.exists_part("ValidateUnsigned") { let name = &pallet_decl.name; let path = &pallet_decl.path; - let attr = pallet_decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); + let attr = pallet_decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { + let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }); pallet_names.push(name); pallet_attrs.push(attr); diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 01f6bfefb0c15..91a638c99ca38 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -510,17 +510,14 @@ fn decl_pallet_runtime_setup( let pallet_attrs = pallet_declarations .iter() .map(|pallet| { - pallet - .cfg_pattern - .iter() - .fold(TokenStream2::new(), |acc, pattern| { - let attr = TokenStream2::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }) + pallet.cfg_pattern.iter().fold(TokenStream2::new(), |acc, pattern| { + let attr = TokenStream2::from_str(&format!("#[cfg({})]", pattern.original())) + .expect("was successfully parsed before; qed"); + quote! { + #acc + #attr + } + }) }) .collect::>(); From 5a305f10a46d431ea644635d80d6e84313829d55 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 15 Aug 2022 18:39:55 +0800 Subject: [PATCH 03/11] Remove commented out code --- .../procedural/src/construct_runtime/parse.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/parse.rs b/frame/support/procedural/src/construct_runtime/parse.rs index d9ff4a95a9f56..77f725945d760 100644 --- a/frame/support/procedural/src/construct_runtime/parse.rs +++ b/frame/support/procedural/src/construct_runtime/parse.rs @@ -646,18 +646,6 @@ fn convert_pallets(pallets: Vec) -> syn::Result (), } - // let meta = attr.parse_meta()?; - // match meta { - // Meta::List(MetaList { path: Path { segments, .. }, nested, .. }) if segments.len() == - // 1 && segments[0].ident == "cfg" => { let predicates = - // cfg_expr::expr::Expression::parse(&nested.into_token_stream().to_string()) - // .map_err(|e| syn::Error::new(attr.span(), &e.to_string()))?; - // }, - // _ => { - // let msg = "Unsupported attribute, only #[cfg] is supported on pallet declarations in - // `construct_runtime`"; return Err(syn::Error::new(attr.span(), msg)) - // } - // } let cfg_pattern = pallet .attrs .iter() From e4f34e421107668498ae6357247e3515f6fad19d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 15 Aug 2022 19:12:50 +0800 Subject: [PATCH 04/11] Fixes --- .../procedural/src/construct_runtime/mod.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 0ad0f5214938a..b5ccebabce5e1 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -448,6 +448,23 @@ fn decl_all_pallets<'a>( .into_compile_error(), }; + let all_pallets_reversed_with_system_first = names_by_feature.iter().map(|(feature_set, names)| { + let mut feature_set = feature_set.iter().collect::>(); + let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); + let feature_set = feature_set.into_iter(); + let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let names = + std::iter::once(system_pallet).chain(names.iter().filter(|n| **n != SYSTEM_PALLET_NAME)); + quote! { + #attr + /// All pallets included in the runtime as a nested tuple of types in reversed order. + /// With the system pallet first. + #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ + `AllPalletWithSystem or AllPalletsWithoutSystem`")] + pub type AllPalletsWithSystemReversed = ( #(#names),* ); + } + }); + quote!( #types @@ -470,11 +487,7 @@ fn decl_all_pallets<'a>( #( #all_pallets_with_system_reversed )* - /// All pallets included in the runtime as a nested tuple of types in reversed order. - /// With the system pallet first. - #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ - `AllPalletWithSystem or AllPalletsWithoutSystem`")] - pub type AllPalletsReversedWithSystemFirst = ( #(#names_reversed_with_system_first),* ); + #( #all_pallets_reversed_with_system_first )* ) } From db60599c31d016be0ad9dcff3431fc8fa15951e5 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 17 Aug 2022 00:36:52 +0800 Subject: [PATCH 05/11] cargo fmt --- .../procedural/src/construct_runtime/mod.rs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index b5ccebabce5e1..88a1c6066f664 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -448,22 +448,23 @@ fn decl_all_pallets<'a>( .into_compile_error(), }; - let all_pallets_reversed_with_system_first = names_by_feature.iter().map(|(feature_set, names)| { - let mut feature_set = feature_set.iter().collect::>(); - let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); - let feature_set = feature_set.into_iter(); - let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); - let names = - std::iter::once(system_pallet).chain(names.iter().filter(|n| **n != SYSTEM_PALLET_NAME)); - quote! { - #attr - /// All pallets included in the runtime as a nested tuple of types in reversed order. - /// With the system pallet first. - #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ - `AllPalletWithSystem or AllPalletsWithoutSystem`")] - pub type AllPalletsWithSystemReversed = ( #(#names),* ); - } - }); + let all_pallets_reversed_with_system_first = + names_by_feature.iter().map(|(feature_set, names)| { + let mut feature_set = feature_set.iter().collect::>(); + let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); + let feature_set = feature_set.into_iter(); + let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let names = std::iter::once(system_pallet) + .chain(names.iter().filter(|n| **n != SYSTEM_PALLET_NAME)); + quote! { + #attr + /// All pallets included in the runtime as a nested tuple of types in reversed order. + /// With the system pallet first. + #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ + `AllPalletWithSystem or AllPalletsWithoutSystem`")] + pub type AllPalletsWithSystemReversed = ( #(#names),* ); + } + }); quote!( #types From c3a1f23c213077d97744aa4d63841b590c7e53b3 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 17 Aug 2022 00:53:46 +0800 Subject: [PATCH 06/11] Remove inaccurate comments --- .../procedural/src/construct_runtime/mod.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 88a1c6066f664..83ed4e93e2e45 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -368,9 +368,6 @@ fn decl_all_pallets<'a>( } } - // Make nested tuple structure like: - // `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))` - // But ignore the system pallet. let all_pallets_without_system = names_by_feature.iter().map(|(feature_set, names)| { let mut feature_set = feature_set.iter().collect::>(); let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); @@ -385,8 +382,6 @@ fn decl_all_pallets<'a>( } }); - // Make nested tuple structure like: - // `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))` let all_pallets_with_system = names_by_feature.iter().map(|(feature_set, names)| { let mut feature_set = feature_set.iter().collect::>(); let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); @@ -400,9 +395,6 @@ fn decl_all_pallets<'a>( } }); - // Make nested tuple structure like: - // `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))` - // But ignore the system pallet. let all_pallets_without_system_reversed = names_by_feature.iter().map(|(feature_set, names)| { let mut feature_set = feature_set.iter().collect::>(); @@ -420,8 +412,6 @@ fn decl_all_pallets<'a>( } }); - // Make nested tuple structure like: - // `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))` let all_pallets_with_system_reversed = names_by_feature.iter().map(|(feature_set, names)| { let mut feature_set = feature_set.iter().collect::>(); let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); @@ -484,10 +474,10 @@ fn decl_all_pallets<'a>( #( #all_pallets_without_system )* - #( #all_pallets_without_system_reversed )* - #( #all_pallets_with_system_reversed )* + #( #all_pallets_without_system_reversed )* + #( #all_pallets_reversed_with_system_first )* ) } From 402cbb1c221b8974c76eca76a127268e94ae0ffa Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 17 Aug 2022 01:19:58 +0800 Subject: [PATCH 07/11] Fix typo --- frame/support/procedural/src/construct_runtime/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 83ed4e93e2e45..3b4368455c36a 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -378,7 +378,7 @@ fn decl_all_pallets<'a>( #attr /// All pallets included in the runtime as a nested tuple of types. /// Excludes the System pallet. - pub type AllPalletsWithoutSystem = ( #(#names),* ); + pub type AllPalletsWithoutSystem = ( #(#names,)* ); } }); @@ -391,7 +391,7 @@ fn decl_all_pallets<'a>( quote! { #attr /// All pallets included in the runtime as a nested tuple of types. - pub type AllPalletsWithSystem = ( #(#names),* ); + pub type AllPalletsWithSystem = ( #(#names,)* ); } }); @@ -408,7 +408,7 @@ fn decl_all_pallets<'a>( /// Excludes the System pallet. #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ `AllPalletWithSystem or AllPalletsWithoutSystem`")] - pub type AllPalletsWithoutSystemReversed = ( #(#names),* ); + pub type AllPalletsWithoutSystemReversed = ( #(#names,)* ); } }); @@ -422,7 +422,7 @@ fn decl_all_pallets<'a>( /// All pallets included in the runtime as a nested tuple of types in reversed order. #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ `AllPalletWithSystem or AllPalletsWithoutSystem`")] - pub type AllPalletsWithSystemReversed = ( #(#names),* ); + pub type AllPalletsWithSystemReversed = ( #(#names,)* ); } }); @@ -452,7 +452,7 @@ fn decl_all_pallets<'a>( /// With the system pallet first. #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ `AllPalletWithSystem or AllPalletsWithoutSystem`")] - pub type AllPalletsWithSystemReversed = ( #(#names),* ); + pub type AllPalletsReversedWithSystemFirst = ( #(#names,)* ); } }); From 0709ed8759e56db1da26561a939264fdb2397166 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 17 Aug 2022 01:26:27 +0800 Subject: [PATCH 08/11] Properly reverse pallets --- frame/support/procedural/src/construct_runtime/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 3b4368455c36a..793f2c2f1eeee 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -387,7 +387,6 @@ fn decl_all_pallets<'a>( let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); - let names = names.iter().rev(); quote! { #attr /// All pallets included in the runtime as a nested tuple of types. @@ -401,7 +400,7 @@ fn decl_all_pallets<'a>( let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); - let names = names.iter().filter(|n| **n != SYSTEM_PALLET_NAME); + let names = names.iter().rev().filter(|n| **n != SYSTEM_PALLET_NAME); quote! { #attr /// All pallets included in the runtime as a nested tuple of types in reversed order. @@ -417,6 +416,7 @@ fn decl_all_pallets<'a>( let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); + let names = names.iter().rev(); quote! { #attr /// All pallets included in the runtime as a nested tuple of types in reversed order. @@ -445,7 +445,7 @@ fn decl_all_pallets<'a>( let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); let names = std::iter::once(system_pallet) - .chain(names.iter().filter(|n| **n != SYSTEM_PALLET_NAME)); + .chain(names.iter().rev(). filter(|n| **n != SYSTEM_PALLET_NAME)); quote! { #attr /// All pallets included in the runtime as a nested tuple of types in reversed order. From ad2a4db19b1ff42d6582c97431789d28a6dc96bd Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 17 Aug 2022 01:29:09 +0800 Subject: [PATCH 09/11] Fixes --- frame/support/procedural/src/construct_runtime/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 793f2c2f1eeee..d46f8c9eedd36 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -373,7 +373,7 @@ fn decl_all_pallets<'a>( let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); - let names = names.iter().filter(|n| **n != SYSTEM_PALLET_NAME).rev(); + let names = names.iter().filter(|n| **n != SYSTEM_PALLET_NAME); quote! { #attr /// All pallets included in the runtime as a nested tuple of types. @@ -400,7 +400,7 @@ fn decl_all_pallets<'a>( let test_cfg = feature_set.remove(&&&"test").then_some(quote!(test)).into_iter(); let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); - let names = names.iter().rev().filter(|n| **n != SYSTEM_PALLET_NAME); + let names = names.iter().filter(|n| **n != SYSTEM_PALLET_NAME).rev(); quote! { #attr /// All pallets included in the runtime as a nested tuple of types in reversed order. From bbc82a26e2b2f58a6e1c4b3069e6966eaa54123c Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 17 Aug 2022 11:45:59 +0800 Subject: [PATCH 10/11] cargo fmt --- frame/support/procedural/src/construct_runtime/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index d46f8c9eedd36..cfd582d0e4472 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -445,7 +445,7 @@ fn decl_all_pallets<'a>( let feature_set = feature_set.into_iter(); let attr = quote!(#[cfg(all( #(#test_cfg),* #(feature = #feature_set),* ))]); let names = std::iter::once(system_pallet) - .chain(names.iter().rev(). filter(|n| **n != SYSTEM_PALLET_NAME)); + .chain(names.iter().rev().filter(|n| **n != SYSTEM_PALLET_NAME)); quote! { #attr /// All pallets included in the runtime as a nested tuple of types in reversed order. From a380a18c7eee2ccfd350b63b2e66404ddef5a12c Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 22 Aug 2022 01:46:18 +0800 Subject: [PATCH 11/11] Add missing newlines --- .../test/tests/construct_runtime_ui/invalid_meta_literal.rs | 2 +- .../tests/construct_runtime_ui/unsupported_meta_structure.rs | 2 +- .../test/tests/construct_runtime_ui/unsupported_pallet_attr.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs b/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs index f4cc643c25a39..a1d39fa76ea85 100644 --- a/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs +++ b/frame/support/test/tests/construct_runtime_ui/invalid_meta_literal.rs @@ -12,4 +12,4 @@ construct_runtime! { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs b/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs index f50fe758f085b..b93adf9a780a7 100644 --- a/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs +++ b/frame/support/test/tests/construct_runtime_ui/unsupported_meta_structure.rs @@ -12,4 +12,4 @@ construct_runtime! { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs b/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs index 798f5e42c7f8d..3ec8b9db1d435 100644 --- a/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs +++ b/frame/support/test/tests/construct_runtime_ui/unsupported_pallet_attr.rs @@ -12,4 +12,4 @@ construct_runtime! { } } -fn main() {} \ No newline at end of file +fn main() {}