diff --git a/Cargo.lock b/Cargo.lock index a1610fa57bc28..2567d56d331da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2054,6 +2054,7 @@ dependencies = [ "sp-state-machine", "sp-std", "sp-tracing", + "tt-call", ] [[package]] @@ -10804,6 +10805,12 @@ dependencies = [ "toml", ] +[[package]] +name = "tt-call" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e66dcbec4290c69dd03c57e76c2469ea5c7ce109c6dd4351c13055cf71ea055" + [[package]] name = "twox-hash" version = "1.6.1" diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 5f1b24d90a499..6b963fe5c232e 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -25,6 +25,7 @@ sp-core = { version = "4.0.0-dev", default-features = false, path = "../../primi sp-arithmetic = { version = "4.0.0-dev", default-features = false, path = "../../primitives/arithmetic" } sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../primitives/inherents" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +tt-call = "1.0.8" frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "./procedural" } paste = "1.0" once_cell = { version = "1", default-features = false, optional = true } diff --git a/frame/support/procedural/src/construct_runtime/expand/config.rs b/frame/support/procedural/src/construct_runtime/expand/config.rs index 5e1b9d94700e6..8bcd4c950429f 100644 --- a/frame/support/procedural/src/construct_runtime/expand/config.rs +++ b/frame/support/procedural/src/construct_runtime/expand/config.rs @@ -32,16 +32,21 @@ pub fn expand_outer_config( let mut query_genesis_config_part_macros = Vec::new(); for decl in pallet_decls { - if let Some(pallet_entry) = decl.find_part("Config") { + if decl.exists_part("Config") { let path = &decl.path; let pallet_name = &decl.name; let path_str = path.into_token_stream().to_string(); - let config = format_ident!("{}Config", pallet_name); + let config = &format_ident!("{}Config", pallet_name); 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 instance = decl.instance.as_ref().into_iter(); - types.extend(expand_config_types(runtime, decl, &config, part_is_generic)); + types.extend(quote! { + #[cfg(any(feature = "std", test))] + pub type #config = < + #path::Pallet<#runtime #(, #path::#instance)*> as #path::SubstratePalletConfig + >::GenesisConfig; + }); fields.extend(quote!(pub #field_name: #config,)); build_storage_calls.extend(expand_config_build_storage_call( scrate, @@ -91,30 +96,6 @@ pub fn expand_outer_config( } } -fn expand_config_types( - runtime: &Ident, - decl: &Pallet, - config: &Ident, - part_is_generic: bool, -) -> TokenStream { - let path = &decl.path; - - match (decl.instance.as_ref(), part_is_generic) { - (Some(inst), true) => quote! { - #[cfg(any(feature = "std", test))] - pub type #config = #path::GenesisConfig<#runtime, #path::#inst>; - }, - (None, true) => quote! { - #[cfg(any(feature = "std", test))] - pub type #config = #path::GenesisConfig<#runtime>; - }, - (_, false) => quote! { - #[cfg(any(feature = "std", test))] - pub type #config = #path::GenesisConfig; - }, - } -} - fn expand_config_build_storage_call( scrate: &TokenStream, runtime: &Ident, diff --git a/frame/support/procedural/src/construct_runtime/expand/event.rs b/frame/support/procedural/src/construct_runtime/expand/event.rs index 798646bf27334..f03cd349d48f4 100644 --- a/frame/support/procedural/src/construct_runtime/expand/event.rs +++ b/frame/support/procedural/src/construct_runtime/expand/event.rs @@ -15,10 +15,10 @@ // See the License for the specific language governing permissions and // limitations under the License -use crate::construct_runtime::Pallet; +use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME}; use proc_macro2::TokenStream; use quote::quote; -use syn::{Generics, Ident}; +use syn::Ident; pub fn expand_outer_event( runtime: &Ident, @@ -30,37 +30,24 @@ pub fn expand_outer_event( let mut query_event_part_macros = Vec::new(); for pallet_decl in pallet_decls { - if let Some(pallet_entry) = pallet_decl.find_part("Event") { + if pallet_decl.exists_part("Event") { let path = &pallet_decl.path; let pallet_name = &pallet_decl.name; let index = pallet_decl.index; - let instance = pallet_decl.instance.as_ref(); - let generics = &pallet_entry.generics; - if instance.is_some() && generics.params.is_empty() { - let msg = format!( - "Instantiable pallet with no generic `Event` cannot \ - be constructed: pallet `{}` must have generic `Event`", - pallet_name, - ); - return Err(syn::Error::new(pallet_name.span(), msg)) - } - - let part_is_generic = !generics.params.is_empty(); - let pallet_event = match (instance, part_is_generic) { - (Some(inst), true) => quote!(#path::Event::<#runtime, #path::#inst>), - (Some(inst), false) => quote!(#path::Event::<#path::#inst>), - (None, true) => quote!(#path::Event::<#runtime>), - (None, false) => quote!(#path::Event), + let pallet_event = if pallet_decl.name == SYSTEM_PALLET_NAME { + // Note: for some reason, the compiler recognizes + // ` as frame_system::SubstratePalletEvent>::Event` as + // essentially the same as the outer/runtime Event type, which then causes an error + // about conflicting implementations of the From trait for the Event type, + // and thereby necessitating a special case for the system pallet. + quote!(#path::Event<#runtime>) + } else { + let instance = pallet_decl.instance.as_ref().into_iter(); + quote!(<#path::Pallet<#runtime #(, #path::#instance)*> as #path::SubstratePalletEvent>::Event) }; - event_variants.extend(expand_event_variant( - runtime, - pallet_decl, - index, - instance, - generics, - )); + event_variants.extend(quote!(#[codec(index = #index)] #pallet_name(#pallet_event),)); event_conversions.extend(expand_event_conversion(scrate, pallet_decl, &pallet_event)); query_event_part_macros.push(quote! { #path::__substrate_event_check::is_event_part_defined!(#pallet_name); @@ -87,33 +74,6 @@ pub fn expand_outer_event( }) } -fn expand_event_variant( - runtime: &Ident, - pallet: &Pallet, - index: u8, - instance: Option<&Ident>, - generics: &Generics, -) -> TokenStream { - let path = &pallet.path; - let variant_name = &pallet.name; - let part_is_generic = !generics.params.is_empty(); - - match instance { - Some(inst) if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),) - }, - Some(inst) => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),) - }, - None if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),) - }, - None => { - quote!(#[codec(index = #index)] #variant_name(#path::Event),) - }, - } -} - fn expand_event_conversion( scrate: &TokenStream, pallet: &Pallet, diff --git a/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/frame/support/procedural/src/construct_runtime/expand/metadata.rs index c8445e0bbc255..fc291c4718dab 100644 --- a/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License -use crate::construct_runtime::Pallet; +use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME}; use proc_macro2::TokenStream; use quote::quote; use syn::{Ident, TypePath}; @@ -132,17 +132,16 @@ fn expand_pallet_metadata_events( ) -> TokenStream { if filtered_names.contains(&"Event") { let path = &decl.path; - let part_is_generic = !decl - .find_part("Event") - .expect("Event part exists; qed") - .generics - .params - .is_empty(); - let pallet_event = match (decl.instance.as_ref(), part_is_generic) { - (Some(inst), true) => quote!(#path::Event::<#runtime, #path::#inst>), - (Some(inst), false) => quote!(#path::Event::<#path::#inst>), - (None, true) => quote!(#path::Event::<#runtime>), - (None, false) => quote!(#path::Event), + let pallet_event = if decl.name == SYSTEM_PALLET_NAME { + // Note: for some reason, the compiler recognizes + // ` as frame_system::SubstratePalletEvent>::Event` as + // essentially the same as the outer/runtime Event type, which then causes an error + // about conflicting implementations of the From trait for the Event type, and + // thereby necessitating a special case for the system pallet. + quote!(#path::Event<#runtime>) + } else { + let instance = decl.instance.as_ref().into_iter(); + quote!(<#path::Pallet<#runtime #(, #path::#instance)*> as #path::SubstratePalletEvent>::Event) }; quote! { diff --git a/frame/support/procedural/src/construct_runtime/expand/origin.rs b/frame/support/procedural/src/construct_runtime/expand/origin.rs index 57adf86a9fe18..6601dac924d1a 100644 --- a/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -31,7 +31,7 @@ pub fn expand_outer_origin( syn::Error::new( pallets_token.span, "`System` pallet declaration is missing. \ - Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},`", + Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},`", ) })?; diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index 6987fc49b9a8c..9d9bde431e51a 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -30,6 +30,7 @@ mod pallet; mod partial_eq_no_bound; mod storage; mod transactional; +mod tt_macro; use proc_macro::TokenStream; use std::{cell::RefCell, str::FromStr}; @@ -229,7 +230,7 @@ fn get_cargo_env_var(version_env: &str) -> std::result::Result}, +/// Example: example::{Pallet, Storage, ..., Config}, /// ..., /// } /// ); @@ -304,13 +305,13 @@ pub fn decl_storage(input: TokenStream) -> TokenStream { /// NodeBlock = node::Block, /// UncheckedExtrinsic = UncheckedExtrinsic /// { -/// System: system::{Pallet, Call, Event, Config} = 0, +/// System: system::{Pallet, Call, Event, Config} = 0, /// Test: test::{Pallet, Call} = 1, -/// Test2: test_with_long_module::{Pallet, Event}, +/// Test2: test_with_long_module::{Pallet, Event}, /// /// // Pallets with instances /// Test3_Instance1: test3::::{Pallet, Call, Storage, Event, Config, Origin}, -/// Test3_DefaultInstance: test3::{Pallet, Call, Storage, Event, Config, Origin} = 4, +/// Test3_DefaultInstance: test3::{Pallet, Call, Storage, Event, Config, Origin} = 4, /// } /// ) /// ``` @@ -325,10 +326,9 @@ pub fn decl_storage(input: TokenStream) -> TokenStream { /// - `Pallet` - Required for all pallets /// - `Call` - If the pallet has callable functions /// - `Storage` - If the pallet uses storage -/// - `Event` or `Event` (if the event is generic) - If the pallet emits events +/// - `Event` - If the pallet emits events /// - `Origin` or `Origin` (if the origin is generic) - If the pallet has instanciable origins -/// - `Config` or `Config` (if the config is generic) - If the pallet builds the genesis storage -/// with `GenesisConfig` +/// - `Config` - If the pallet builds the genesis storage with `GenesisConfig` /// - `Inherent` - If the pallet provides/can check inherents. /// - `ValidateUnsigned` - If the pallet validates unsigned extrinsics. /// @@ -498,3 +498,9 @@ pub fn impl_key_prefix_for_tuples(input: TokenStream) -> TokenStream { pub fn __generate_dummy_part_checker(input: TokenStream) -> TokenStream { dummy_part_checker::generate_dummy_part_checker(input) } + +/// Internal macro used by frame_support to create tt-call-compliant macros +#[proc_macro] +pub fn __create_tt_macro(input: TokenStream) -> TokenStream { + tt_macro::create_tt_return_macro(input) +} diff --git a/frame/support/procedural/src/pallet/expand/event.rs b/frame/support/procedural/src/pallet/expand/event.rs index ebd2d7aeabaff..441c09a32cb89 100644 --- a/frame/support/procedural/src/pallet/expand/event.rs +++ b/frame/support/procedural/src/pallet/expand/event.rs @@ -122,11 +122,12 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream { #[scale_info(skip_type_params(#event_use_gen), capture_docs = "always")] )); + let type_impl_gen = &def.type_impl_generics(event.attr_span); + let type_use_gen = &def.type_use_generics(event.attr_span); + let deposit_event = if let Some(deposit_event) = &event.deposit_event { let event_use_gen = &event.gen_kind.type_use_gen(event.attr_span); let trait_use_gen = &def.trait_use_generics(event.attr_span); - let type_impl_gen = &def.type_impl_generics(event.attr_span); - let type_use_gen = &def.type_use_generics(event.attr_span); let PalletEventDepositAttr { fn_vis, fn_span, .. } = deposit_event; @@ -164,6 +165,14 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream { pub use #macro_ident as is_event_part_defined; } + pub trait SubstratePalletEvent { + type Event; + } + + impl<#type_impl_gen> SubstratePalletEvent for Pallet<#type_use_gen> #completed_where_clause { + type Event = #event_ident<#event_use_gen>; + } + #deposit_event impl<#event_impl_gen> From<#event_ident<#event_use_gen>> for () #event_where_clause { diff --git a/frame/support/procedural/src/pallet/expand/genesis_config.rs b/frame/support/procedural/src/pallet/expand/genesis_config.rs index 4bbba2c05908e..7e699114407be 100644 --- a/frame/support/procedural/src/pallet/expand/genesis_config.rs +++ b/frame/support/procedural/src/pallet/expand/genesis_config.rs @@ -107,7 +107,22 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream { _ => unreachable!("Checked by genesis_config parser"), } + let config_ident = &genesis_config.genesis_config; + let config_use_gen = &genesis_config.gen_kind.type_use_gen(config_ident.span()); + let config_where_clause = def.config.where_clause.iter(); + let type_impl_gen = &def.type_impl_generics(config_ident.span()); + let type_use_gen = &def.type_use_generics(config_ident.span()); + quote::quote! { + pub trait SubstratePalletConfig { + type GenesisConfig; + } + + #[cfg(feature = "std")] + impl<#type_impl_gen> SubstratePalletConfig for Pallet<#type_use_gen> #(#config_where_clause)* { + type GenesisConfig = #config_ident<#config_use_gen>; + } + #[doc(hidden)] pub mod __substrate_genesis_config_check { #[macro_export] diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 96d4776e805bc..117a526171328 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -336,7 +336,7 @@ impl GenericKind { /// Return the generic to be used when using the type. /// - /// Depending on its definition it can be: ``, `T` or `T, I` + /// Depending on its definition it can be: ` `, `T` or `T, I` pub fn type_use_gen(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { match self { GenericKind::None => quote::quote!(), diff --git a/frame/support/procedural/src/storage/genesis_config/mod.rs b/frame/support/procedural/src/storage/genesis_config/mod.rs index d2d1afb017736..43566a2dc7003 100644 --- a/frame/support/procedural/src/storage/genesis_config/mod.rs +++ b/frame/support/procedural/src/storage/genesis_config/mod.rs @@ -87,6 +87,31 @@ fn decl_genesis_config_and_impl_default( } } } + + macro_rules! impl_substrate_pallet_config { + { + pallet = [{ $pallet_type:ident <$config_instance:ident : $config_name:ident $(, $instance:ident : $instantiable:path)?> }] + where_bounds = [{ $( $other_where_bounds:tt )* }] + } => { + pub trait SubstratePalletConfig { + type GenesisConfig; + } + + #[cfg(feature = "std")] + impl<$config_instance: $config_name $(, $instance: $instantiable)?> SubstratePalletConfig + for $pallet_type<$config_instance $(, $instance)?> + where + $( $other_where_bounds )* + { + type GenesisConfig = GenesisConfig#genesis_struct; + } + }; + } + + #scrate::tt_call! { + macro = [{ tt_get_pallet_type }] + ~~> impl_substrate_pallet_config + } ) } diff --git a/frame/support/procedural/src/tt_macro.rs b/frame/support/procedural/src/tt_macro.rs new file mode 100644 index 0000000000000..057886df7eab2 --- /dev/null +++ b/frame/support/procedural/src/tt_macro.rs @@ -0,0 +1,74 @@ +// This file is part of Substrate. + +// Copyright (C) 2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Implementation of the `create_tt_return_macro` macro +use frame_support_procedural_tools::generate_crate_access_2018; +use proc_macro2::{Ident, TokenStream}; + +struct CreateTtReturnMacroDef { + name: Ident, + args: Vec<(Ident, TokenStream)>, +} + +impl syn::parse::Parse for CreateTtReturnMacroDef { + fn parse(input: syn::parse::ParseStream) -> syn::Result { + let name = input.parse()?; + let _ = input.parse::()?; + + let mut args = Vec::new(); + while !input.is_empty() { + let mut value; + let key: Ident = input.parse()?; + let _ = input.parse::()?; + let _: syn::token::Bracket = syn::bracketed!(value in input); + let _: syn::token::Brace = syn::braced!(value in value); + let value: TokenStream = value.parse()?; + + args.push((key, value)) + } + + Ok(Self { name, args }) + } +} + +pub fn create_tt_return_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let CreateTtReturnMacroDef { name, args } = + syn::parse_macro_input!(input as CreateTtReturnMacroDef); + + let frame_support = match generate_crate_access_2018("frame-support") { + Ok(i) => i, + Err(e) => return e.into_compile_error().into(), + }; + let (keys, values): (Vec<_>, Vec<_>) = args.into_iter().unzip(); + + let decl_macro = quote::quote! { + macro_rules! #name { + { + $caller:tt + } => { + #frame_support::tt_return! { + $caller + #( + #keys = [{ #values }] + )* + } + } + } + }; + + decl_macro.into() +} diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index b4e9071e361aa..7c1d2479901f2 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -1980,6 +1980,12 @@ macro_rules! decl_module { pub type Pallet<$trait_instance $(, $instance $( = $module_default_instance)?)?> = $mod_type<$trait_instance $(, $instance)?>; + $crate::__create_tt_macro! { + tt_get_pallet_type, + pallet = [{ $mod_type<$trait_instance: $trait_name $(, $instance: $instantiable)?> }] + where_bounds = [{ $( $other_where_bounds )* }] + } + $crate::decl_module! { @impl_on_initialize { $system } diff --git a/frame/support/src/event.rs b/frame/support/src/event.rs index 3d042a3122db8..a3cb8dd39baf4 100644 --- a/frame/support/src/event.rs +++ b/frame/support/src/event.rs @@ -142,6 +142,12 @@ macro_rules! decl_event { impl From for () { fn from(_: Event) -> () { () } } + $crate::tt_call! { + macro = [{ tt_get_pallet_type }] + ~~> $crate::impl_substrate_pallet_event! { + event = [{ Event }] + } + } } } @@ -285,8 +291,35 @@ macro_rules! __decl_generic_event { impl<$( $generic_param ),* $(, $instance)? > From> for () { fn from(_: RawEvent<$( $generic_param ),* $(, $instance)?>) -> () { () } } + $crate::tt_call! { + macro = [{ tt_get_pallet_type }] + ~~> $crate::impl_substrate_pallet_event! { + event = [{ Event<$event_generic_param $(, $instance)?> }] + } + } }; (@cannot_parse $ty:ty) => { compile_error!(concat!("The type `", stringify!($ty), "` can't be parsed as an unnamed one, please name it `Name = ", stringify!($ty), "`")); } } + +#[macro_export] +macro_rules! impl_substrate_pallet_event { + { + event = [{ Event $( <$event_generic_param:ident $(, $event_instance:ident)?> )? }] + pallet = [{ $pallet_type:ident <$config_instance:ident : $config_name:ident $(, $instance:ident : $instantiable:path)?> }] + where_bounds = [{ $( $other_where_bounds:tt )* }] + } => { + pub trait SubstratePalletEvent { + type Event; + } + + impl<$config_instance: $config_name $(, $instance: $instantiable)?> SubstratePalletEvent + for $pallet_type<$config_instance $(, $instance)?> + where + $( $other_where_bounds )* + { + type Event = Event $( <$event_generic_param $(, $event_instance)?> )?; + } + }; +} diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index f3b00c764bb35..41d6d60bba255 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -50,6 +50,8 @@ pub use sp_runtime::RuntimeDebug; pub use sp_state_machine::BasicExternalities; #[doc(hidden)] pub use sp_std; +#[doc(hidden)] +pub use tt_call::*; #[macro_use] pub mod dispatch; @@ -577,7 +579,7 @@ pub use frame_support_procedural::{ }; #[doc(hidden)] -pub use frame_support_procedural::__generate_dummy_part_checker; +pub use frame_support_procedural::{__create_tt_macro, __generate_dummy_part_checker}; /// Derive [`Clone`] but do not bound any generic. /// diff --git a/frame/support/test/tests/construct_runtime.rs b/frame/support/test/tests/construct_runtime.rs index 2d14da04f64b7..bc20b9464ab57 100644 --- a/frame/support/test/tests/construct_runtime.rs +++ b/frame/support/test/tests/construct_runtime.rs @@ -247,19 +247,19 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Event, Origin} = 30, - Module1_1: module1::::{Pallet, Call, Storage, Event, Origin}, + System: system::{Pallet, Call, Event, Origin} = 30, + Module1_1: module1::::{Pallet, Call, Storage, Event, Origin}, Module2: module2::{Pallet, Call, Storage, Event, Origin}, - Module1_2: module1::::{Pallet, Call, Storage, Event, Origin}, + Module1_2: module1::::{Pallet, Call, Storage, Event, Origin}, NestedModule3: nested::module3::{Pallet, Call, Config, Storage, Event, Origin}, Module3: self::module3::{Pallet, Call, Config, Storage, Event, Origin}, Module1_3: module1::::{Pallet, Storage} = 6, Module1_4: module1::::{Pallet, Call} = 3, - Module1_5: module1::::{Pallet, Event}, - Module1_6: module1::::{Pallet, Call, Storage, Event, Origin} = 1, - Module1_7: module1::::{Pallet, Call, Storage, Event, Origin}, - Module1_8: module1::::{Pallet, Call, Storage, Event, Origin} = 12, - Module1_9: module1::::{Pallet, Call, Storage, Event, Origin}, + Module1_5: module1::::{Pallet, Event}, + Module1_6: module1::::{Pallet, Call, Storage, Event, Origin} = 1, + Module1_7: module1::::{Pallet, Call, Storage, Event, Origin}, + Module1_8: module1::::{Pallet, Call, Storage, Event, Origin} = 12, + Module1_9: module1::::{Pallet, Call, Storage, Event, Origin}, } ); @@ -302,7 +302,7 @@ mod origin_test { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Event, Origin}, + System: system::{Pallet, Event, Origin}, NestedModule3: nested::module3::{Pallet, Origin, Call}, Module3: module3::{Pallet, Origin, Call}, } diff --git a/frame/support/test/tests/construct_runtime_ui/double_module_parts.stderr b/frame/support/test/tests/construct_runtime_ui/double_module_parts.stderr index 9d10474ce85ab..c7b992b45e426 100644 --- a/frame/support/test/tests/construct_runtime_ui/double_module_parts.stderr +++ b/frame/support/test/tests/construct_runtime_ui/double_module_parts.stderr @@ -1,5 +1,5 @@ error: `Config` was already declared before. Please remove the duplicate declaration --> $DIR/double_module_parts.rs:10:37 | -10 | Balance: balances::{Config, Call, Config, Origin}, +10 | Balance: balances::{Config, Call, Config, Origin}, | ^^^^^^ diff --git a/frame/support/test/tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.rs b/frame/support/test/tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.rs deleted file mode 100644 index f748e643aa18a..0000000000000 --- a/frame/support/test/tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.rs +++ /dev/null @@ -1,14 +0,0 @@ -use frame_support::construct_runtime; - -construct_runtime! { - pub enum Runtime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic - { - System: system::{Pallet}, - Balance: balances::::{Event}, - } -} - -fn main() {} diff --git a/frame/support/test/tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.stderr b/frame/support/test/tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.stderr deleted file mode 100644 index b1aa9b86cd0d6..0000000000000 --- a/frame/support/test/tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: Instantiable pallet with no generic `Event` cannot be constructed: pallet `Balance` must have generic `Event` - --> $DIR/missing_event_generic_on_module_with_instance.rs:10:3 - | -10 | Balance: balances::::{Event}, - | ^^^^^^^ diff --git a/frame/support/test/tests/construct_runtime_ui/missing_system_module.stderr b/frame/support/test/tests/construct_runtime_ui/missing_system_module.stderr index 7648f5c1bfb33..3199abb30baf2 100644 --- a/frame/support/test/tests/construct_runtime_ui/missing_system_module.stderr +++ b/frame/support/test/tests/construct_runtime_ui/missing_system_module.stderr @@ -1,4 +1,4 @@ -error: `System` pallet declaration is missing. Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},` +error: `System` pallet declaration is missing. Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},` --> $DIR/missing_system_module.rs:8:2 | 8 | / { diff --git a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.rs b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.rs index 89774eb8a7702..336c3a6170bc6 100644 --- a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.rs +++ b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.rs @@ -16,7 +16,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: test_pallet::{Pallet, Config}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr index 3dc7fcda9f18a..11efd224d8e9e 100644 --- a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr +++ b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr @@ -15,7 +15,7 @@ error: `Pallet` does not have the std feature enabled, this will cause the `test error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/no_std_genesis_config.rs:19:11 | -19 | System: system::{Pallet, Call, Storage, Config, Event}, +19 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0433]: failed to resolve: use of undeclared crate or module `system` diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs b/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs index c5b9fcca1f318..f9d47e73dab84 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs +++ b/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs @@ -25,7 +25,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: pallet::{Pallet, Call}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr index 2629cf4101923..653cf7b3fd388 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr @@ -18,7 +18,7 @@ error: `Pallet` does not have #[pallet::call] defined, perhaps you should remove error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/undefined_call_part.rs:28:11 | -28 | System: system::{Pallet, Call, Storage, Config, Event}, +28 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0433]: failed to resolve: use of undeclared crate or module `system` diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs b/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs index 6aec45f240c90..9998261aa3b26 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs +++ b/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs @@ -25,7 +25,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: pallet::{Pallet, Event}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr index af69b79ed1a64..311b8be182c28 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr @@ -18,7 +18,7 @@ error: `Pallet` does not have #[pallet::event] defined, perhaps you should remov error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/undefined_event_part.rs:28:11 | -28 | System: system::{Pallet, Call, Storage, Config, Event}, +28 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0412]: cannot find type `Event` in module `pallet` diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs index 5e08fd96fa1ad..4e4d05cfaa047 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs +++ b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs @@ -25,7 +25,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: pallet::{Pallet, Config}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr index bfedb921bca44..d25a35cc1e1d2 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr @@ -18,7 +18,7 @@ error: `Pallet` does not have #[pallet::genesis_config] defined, perhaps you sho error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/undefined_genesis_config_part.rs:28:17 | -28 | System: system::{Pallet, Call, Storage, Config, Event}, +28 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0433]: failed to resolve: use of undeclared crate or module `system` diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs b/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs index 06c36a30f5506..d3fa3dbbd26bb 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs +++ b/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs @@ -25,7 +25,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: pallet::{Pallet, Inherent}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr index 50dde1108263b..e2af4b35920e1 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr @@ -18,7 +18,7 @@ error: `Pallet` does not have #[pallet::inherent] defined, perhaps you should re error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/undefined_inherent_part.rs:28:11 | -28 | System: system::{Pallet, Call, Storage, Config, Event}, +28 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0433]: failed to resolve: use of undeclared crate or module `system` diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs b/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs index bec5c27ec0346..518f60bac611e 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs +++ b/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs @@ -25,7 +25,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: pallet::{Pallet, Origin}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr index b5f3ec4d381bc..a434079f76d96 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr @@ -18,7 +18,7 @@ error: `Pallet` does not have #[pallet::origin] defined, perhaps you should remo error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/undefined_origin_part.rs:28:11 | -28 | System: system::{Pallet, Call, Storage, Config, Event}, +28 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0433]: failed to resolve: use of undeclared crate or module `system` diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs b/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs index 816f52b91cccb..3d51c69453dee 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs +++ b/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs @@ -25,7 +25,7 @@ construct_runtime! { NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Storage, Config, Event}, + System: system::{Pallet, Call, Storage, Config, Event}, Pallet: pallet::{Pallet, ValidateUnsigned}, } } diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr index 12bdce67cf038..408d3a4d5ddb2 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr @@ -18,7 +18,7 @@ error: `Pallet` does not have #[pallet::validate_unsigned] defined, perhaps you error[E0433]: failed to resolve: use of undeclared crate or module `system` --> $DIR/undefined_validate_unsigned_part.rs:28:11 | -28 | System: system::{Pallet, Call, Storage, Config, Event}, +28 | System: system::{Pallet, Call, Storage, Config, Event}, | ^^^^^^ use of undeclared crate or module `system` error[E0433]: failed to resolve: use of undeclared crate or module `system` diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index 809edae14f80c..342eab614c122 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -61,7 +61,8 @@ mod module1 { pub struct Module, I: Instance> for enum Call where origin: ::Origin, system = system, - T::BlockNumber: From + T::BlockNumber: From, + T::BlockNumber: std::fmt::Display { fn offchain_worker() {} @@ -95,6 +96,7 @@ mod module1 { pub enum Error for Module, I: Instance> where T::BlockNumber: From, T::BlockNumber: Add, + T::BlockNumber: std::fmt::Display, T::AccountId: AsRef<[u8]>, { /// Test @@ -122,7 +124,7 @@ mod module1 { impl, I: Instance> ProvideInherent for Module where - T::BlockNumber: From, + T::BlockNumber: From + std::fmt::Display, { type Call = Call; type Error = MakeFatalError<()>; @@ -293,22 +295,22 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Event}, + System: system::{Pallet, Call, Event}, Module1_1: module1::::{ - Pallet, Call, Storage, Event, Config, Origin, Inherent + Pallet, Call, Storage, Event, Config, Origin, Inherent }, Module1_2: module1::::{ - Pallet, Call, Storage, Event, Config, Origin, Inherent + Pallet, Call, Storage, Event, Config, Origin, Inherent }, - Module2: module2::{Pallet, Call, Storage, Event, Config, Origin, Inherent}, + Module2: module2::{Pallet, Call, Storage, Event, Config, Origin, Inherent}, Module2_1: module2::::{ - Pallet, Call, Storage, Event, Config, Origin, Inherent + Pallet, Call, Storage, Event, Config, Origin, Inherent }, Module2_2: module2::::{ - Pallet, Call, Storage, Event, Config, Origin, Inherent + Pallet, Call, Storage, Event, Config, Origin, Inherent }, Module2_3: module2::::{ - Pallet, Call, Storage, Event, Config, Origin, Inherent + Pallet, Call, Storage, Event, Config, Origin, Inherent }, Module3: module3::{Pallet, Call}, } diff --git a/frame/support/test/tests/issue2219.rs b/frame/support/test/tests/issue2219.rs index 68ad2a50a21bc..b0cc17dde4777 100644 --- a/frame/support/test/tests/issue2219.rs +++ b/frame/support/test/tests/issue2219.rs @@ -177,7 +177,7 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Pallet, Call, Event}, + System: system::{Pallet, Call, Event}, Module: module::{Pallet, Call, Storage, Config}, } ); diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index dc72be3ebdd49..9661d160f5297 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -563,9 +563,9 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: frame_system::{Call, Event}, - Example: pallet::{Pallet, Call, Event, Config, Storage, Inherent, Origin, ValidateUnsigned}, - Example2: pallet2::{Pallet, Call, Event, Config, Storage}, + System: frame_system::{Call, Event}, + Example: pallet::{Pallet, Call, Event, Config, Storage, Inherent, Origin, ValidateUnsigned}, + Example2: pallet2::{Pallet, Call, Event, Config, Storage}, } ); diff --git a/frame/support/test/tests/pallet_compatibility.rs b/frame/support/test/tests/pallet_compatibility.rs index 4523063252ab9..44c25c05ae8e4 100644 --- a/frame/support/test/tests/pallet_compatibility.rs +++ b/frame/support/test/tests/pallet_compatibility.rs @@ -268,10 +268,10 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: frame_system::{Pallet, Call, Event}, + System: frame_system::{Pallet, Call, Event}, // NOTE: name Example here is needed in order to have same module prefix - Example: pallet::{Pallet, Call, Event, Config, Storage}, - PalletOld: pallet_old::{Pallet, Call, Event, Config, Storage}, + Example: pallet::{Pallet, Call, Event, Config, Storage}, + PalletOld: pallet_old::{Pallet, Call, Event, Config, Storage}, } ); diff --git a/frame/support/test/tests/pallet_compatibility_instance.rs b/frame/support/test/tests/pallet_compatibility_instance.rs index 768b9f28d35f3..c5f89c11aee05 100644 --- a/frame/support/test/tests/pallet_compatibility_instance.rs +++ b/frame/support/test/tests/pallet_compatibility_instance.rs @@ -268,13 +268,13 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: frame_system::{Pallet, Call, Event}, - Example: pallet::{Pallet, Call, Event, Config, Storage}, - PalletOld: pallet_old::{Pallet, Call, Event, Config, Storage}, - Instance2Example: pallet::::{Pallet, Call, Event, Config, Storage}, - PalletOld2: pallet_old::::{Pallet, Call, Event, Config, Storage}, - Instance3Example: pallet::::{Pallet, Call, Event, Config, Storage}, - PalletOld3: pallet_old::::{Pallet, Call, Event, Config, Storage}, + System: frame_system::{Pallet, Call, Event}, + Example: pallet::{Pallet, Call, Event, Config, Storage}, + PalletOld: pallet_old::{Pallet, Call, Event, Config, Storage}, + Instance2Example: pallet::::{Pallet, Call, Event, Config, Storage}, + PalletOld2: pallet_old::::{Pallet, Call, Event, Config, Storage}, + Instance3Example: pallet::::{Pallet, Call, Event, Config, Storage}, + PalletOld3: pallet_old::::{Pallet, Call, Event, Config, Storage}, } ); diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 34586e8414216..1dd3d751f5967 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -302,13 +302,13 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: frame_system::{Pallet, Call, Event}, - Example: pallet::{Pallet, Call, Event, Config, Storage, Inherent, Origin, ValidateUnsigned}, + System: frame_system::{Pallet, Call, Event}, + Example: pallet::{Pallet, Call, Event, Config, Storage, Inherent, Origin, ValidateUnsigned}, Instance1Example: pallet::::{ - Pallet, Call, Event, Config, Storage, Inherent, Origin, ValidateUnsigned + Pallet, Call, Event, Config, Storage, Inherent, Origin, ValidateUnsigned }, - Example2: pallet2::{Pallet, Event, Config, Storage}, - Instance1Example2: pallet2::::{Pallet, Event, Config, Storage}, + Example2: pallet2::{Pallet, Event, Config, Storage}, + Instance1Example2: pallet2::::{Pallet, Event, Config, Storage}, } ); diff --git a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs index 1c47d13a619f2..87e50d9488ad1 100644 --- a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs +++ b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs @@ -119,8 +119,8 @@ mod tests { NodeBlock = TestBlock, UncheckedExtrinsic = TestUncheckedExtrinsic { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - PalletTest: pallet_test::{Pallet, Call, Storage, Event, Config, ValidateUnsigned, Inherent}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, + PalletTest: pallet_test::{Pallet, Call, Storage, Event, Config, ValidateUnsigned, Inherent}, } );