diff --git a/frame/support/procedural/src/pallet/expand/storage.rs b/frame/support/procedural/src/pallet/expand/storage.rs index c427d57e6d680..be38880d4c457 100644 --- a/frame/support/procedural/src/pallet/expand/storage.rs +++ b/frame/support/procedural/src/pallet/expand/storage.rs @@ -39,6 +39,7 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { .collect::>(); // Replace first arg `_` by the generated prefix structure. + // Add `#[allow(type_alias_bounds)]` for (i, def_storage) in def.storages.iter_mut().enumerate() { let item = &mut def.item.content.as_mut().expect("Checked by def").1[def_storage.index]; @@ -48,6 +49,8 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { unreachable!("Checked by def"); }; + typ_item.attrs.push(syn::parse_quote!(#[allow(type_alias_bounds)])); + let typ_path = if let syn::Type::Path(p) = &mut *typ_item.ty { p } else { diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 3f6e5b7773a8a..fd4908bdc7c2f 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1225,7 +1225,7 @@ pub mod pallet_prelude { /// // /// // NOTE: for storage hasher, the type is not copied because storage hasher trait already /// // implements metadata. Thus generic storage hasher is supported. -/// #[pallet::storage] #[allow(type_alias_bounds)] +/// #[pallet::storage] /// type MyStorageValue = StorageValueType<_, T::Balance, ValueQuery>; /// /// // Another declaration @@ -1351,7 +1351,7 @@ pub mod pallet_prelude { /// Something(u32), /// } /// -/// #[pallet::storage] #[allow(type_alias_bounds)] +/// #[pallet::storage] /// type MyStorageValue, I: Instance = DefaultInstance> = /// StorageValueType<_, T::Balance, ValueQuery>; /// diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 5eab83d2331fa..41a33f700634f 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -95,52 +95,26 @@ pub mod pallet { Something(u32), } - // Declare a storage, any amount of storage can be declared. - // - // Is expected either `StorageValueType`, `StorageMapType` or `StorageDoubleMapType`. - // The macro generates for struct `$identP` (for storage of name `$ident`) and implement - // storage instance on it. - // The macro macro expand the metadata for the storage with the type used: - // * For storage value the type for value will be copied into metadata - // * For storage map the type for value and the type for key will be copied into metadata - // * For storage double map the type for value, key1, and key2 will be copied into - // metadata. - // - // NOTE: for storage hasher, the type is not copied because storage hasher trait already - // implements metadata. Thus generic storage hasher is supported. - #[pallet::storage] #[allow(type_alias_bounds)] - type MyStorageValue = StorageValueType; + #[pallet::storage] + type MyStorageValue = StorageValueType<_, T::Balance, ValueQuery>; - // Another declaration #[pallet::storage] - type MyStorage = StorageMapType; + type MyStorage = StorageMapType<_, Blake2_128Concat, u32, u32>; - // Declare genesis config. (This is optional) - // - // The macro accept either type alias or struct or enum, it checks generics are consistent. - // - // Type must implement `Default` traits #[pallet::genesis_config] #[derive(Default)] pub struct GenesisConfig { _myfield: u32, } - // Declare genesis builder. (This is need only if GenesisConfig is declared) #[pallet::genesis_build] impl GenesisBuilder for GenesisConfig { fn build(&self) {} } - // Declare a pallet origin. (this is optional) - // - // The macro accept type alias or struct or enum, it checks generics are consistent. #[pallet::origin] pub struct Origin(PhantomData); - // Declare inherent provider for module. (this is optional) - // - // The macro checks module is `Module` or `Module` and trait is `ProvideInherent` #[pallet::inherent] impl ProvideInherent for Module { type Call = Call; @@ -153,8 +127,6 @@ pub mod pallet { } } - // Regular rust code needed for implementing ProvideInherent trait - #[derive(codec::Encode, sp_runtime::RuntimeDebug)] #[cfg_attr(feature = "std", derive(codec::Decode))] pub enum InherentError { diff --git a/frame/support/test/tests/pallet_compatibility.rs b/frame/support/test/tests/pallet_compatibility.rs index 252b478ba384c..0684fdfd44914 100644 --- a/frame/support/test/tests/pallet_compatibility.rs +++ b/frame/support/test/tests/pallet_compatibility.rs @@ -120,14 +120,14 @@ pub mod pallet { Dummy(T::Balance), } - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] /// Some documentation type Dummy = StorageValueType<_, T::Balance, OptionQuery>; - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] type Bar = StorageMapType<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>; - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] type Foo = StorageValueType<_, T::Balance, ValueQuery, OnFooEmpty>; pub struct OnFooEmpty(PhantomData); // TODO TODO: allow faster declaration with parameter_types impl Get for OnFooEmpty { fn get() -> T::Balance { 3.into() } } @@ -135,7 +135,7 @@ pub mod pallet { // #[pallet::type_value] pub fn BalanceDefault() -> T::Balance { 0.into() } // #[pallet::type_value] pub struct BalanceDefault(fn() -> T::Balance { 0.into() }) - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] type Double = StorageDoubleMapType< _, Blake2_128Concat, u32, Twox64Concat, u64, u16, ValueQuery >; diff --git a/frame/support/test/tests/pallet_compatibility_instance.rs b/frame/support/test/tests/pallet_compatibility_instance.rs index 8e082c7b84500..b19c2ba6030ce 100644 --- a/frame/support/test/tests/pallet_compatibility_instance.rs +++ b/frame/support/test/tests/pallet_compatibility_instance.rs @@ -118,21 +118,21 @@ pub mod pallet { Dummy(T::Balance), } - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] /// Some documentation type Dummy, I: Instance = DefaultInstance> = StorageValueType<_, T::Balance, OptionQuery>; - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] type Bar, I: Instance = DefaultInstance> = StorageMapType<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>; - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] type Foo, I: Instance = DefaultInstance> = StorageValueType<_, T::Balance, ValueQuery, OnFooEmpty>; pub struct OnFooEmpty, I: Instance>(PhantomData<(T, I)>); impl, I: Instance> Get for OnFooEmpty { fn get() -> T::Balance { 3.into() } } - #[pallet::storage] #[allow(type_alias_bounds)] + #[pallet::storage] type Double = StorageDoubleMapType< _, Blake2_128Concat, u32, Twox64Concat, u64, u16, ValueQuery >;