Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit fae5be6

Browse files
committed
add allow type alias bounds automatically
1 parent b3857a3 commit fae5be6

File tree

5 files changed

+16
-41
lines changed

5 files changed

+16
-41
lines changed

frame/support/procedural/src/pallet/expand/storage.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
3939
.collect::<Vec<_>>();
4040

4141
// Replace first arg `_` by the generated prefix structure.
42+
// Add `#[allow(type_alias_bounds)]`
4243
for (i, def_storage) in def.storages.iter_mut().enumerate() {
4344
let item = &mut def.item.content.as_mut().expect("Checked by def").1[def_storage.index];
4445

@@ -48,6 +49,8 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
4849
unreachable!("Checked by def");
4950
};
5051

52+
typ_item.attrs.push(syn::parse_quote!(#[allow(type_alias_bounds)]));
53+
5154
let typ_path = if let syn::Type::Path(p) = &mut *typ_item.ty {
5255
p
5356
} else {

frame/support/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ pub mod pallet_prelude {
12251225
/// //
12261226
/// // NOTE: for storage hasher, the type is not copied because storage hasher trait already
12271227
/// // implements metadata. Thus generic storage hasher is supported.
1228-
/// #[pallet::storage] #[allow(type_alias_bounds)]
1228+
/// #[pallet::storage]
12291229
/// type MyStorageValue<T: Trait> = StorageValueType<_, T::Balance, ValueQuery>;
12301230
///
12311231
/// // Another declaration
@@ -1351,7 +1351,7 @@ pub mod pallet_prelude {
13511351
/// Something(u32),
13521352
/// }
13531353
///
1354-
/// #[pallet::storage] #[allow(type_alias_bounds)]
1354+
/// #[pallet::storage]
13551355
/// type MyStorageValue<T: Trait<I>, I: Instance = DefaultInstance> =
13561356
/// StorageValueType<_, T::Balance, ValueQuery>;
13571357
///

frame/support/test/tests/pallet.rs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,52 +95,26 @@ pub mod pallet {
9595
Something(u32),
9696
}
9797

98-
// Declare a storage, any amount of storage can be declared.
99-
//
100-
// Is expected either `StorageValueType`, `StorageMapType` or `StorageDoubleMapType`.
101-
// The macro generates for struct `$identP` (for storage of name `$ident`) and implement
102-
// storage instance on it.
103-
// The macro macro expand the metadata for the storage with the type used:
104-
// * For storage value the type for value will be copied into metadata
105-
// * For storage map the type for value and the type for key will be copied into metadata
106-
// * For storage double map the type for value, key1, and key2 will be copied into
107-
// metadata.
108-
//
109-
// NOTE: for storage hasher, the type is not copied because storage hasher trait already
110-
// implements metadata. Thus generic storage hasher is supported.
111-
#[pallet::storage] #[allow(type_alias_bounds)]
112-
type MyStorageValue<T: Trait> = StorageValueType<MyStorageValueP, T::Balance, ValueQuery>;
98+
#[pallet::storage]
99+
type MyStorageValue<T: Trait> = StorageValueType<_, T::Balance, ValueQuery>;
113100

114-
// Another declaration
115101
#[pallet::storage]
116-
type MyStorage = StorageMapType<MyStorageP, Blake2_128Concat, u32, u32>;
102+
type MyStorage = StorageMapType<_, Blake2_128Concat, u32, u32>;
117103

118-
// Declare genesis config. (This is optional)
119-
//
120-
// The macro accept either type alias or struct or enum, it checks generics are consistent.
121-
//
122-
// Type must implement `Default` traits
123104
#[pallet::genesis_config]
124105
#[derive(Default)]
125106
pub struct GenesisConfig {
126107
_myfield: u32,
127108
}
128109

129-
// Declare genesis builder. (This is need only if GenesisConfig is declared)
130110
#[pallet::genesis_build]
131111
impl<T: Trait> GenesisBuilder<T> for GenesisConfig {
132112
fn build(&self) {}
133113
}
134114

135-
// Declare a pallet origin. (this is optional)
136-
//
137-
// The macro accept type alias or struct or enum, it checks generics are consistent.
138115
#[pallet::origin]
139116
pub struct Origin<T>(PhantomData<T>);
140117

141-
// Declare inherent provider for module. (this is optional)
142-
//
143-
// The macro checks module is `Module<T>` or `Module<T, I>` and trait is `ProvideInherent`
144118
#[pallet::inherent]
145119
impl<T: Trait> ProvideInherent for Module<T> {
146120
type Call = Call<T>;
@@ -153,8 +127,6 @@ pub mod pallet {
153127
}
154128
}
155129

156-
// Regular rust code needed for implementing ProvideInherent trait
157-
158130
#[derive(codec::Encode, sp_runtime::RuntimeDebug)]
159131
#[cfg_attr(feature = "std", derive(codec::Decode))]
160132
pub enum InherentError {

frame/support/test/tests/pallet_compatibility.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,22 @@ pub mod pallet {
120120
Dummy(T::Balance),
121121
}
122122

123-
#[pallet::storage] #[allow(type_alias_bounds)]
123+
#[pallet::storage]
124124
/// Some documentation
125125
type Dummy<T: Trait> = StorageValueType<_, T::Balance, OptionQuery>;
126126

127-
#[pallet::storage] #[allow(type_alias_bounds)]
127+
#[pallet::storage]
128128
type Bar<T: Trait> = StorageMapType<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;
129129

130-
#[pallet::storage] #[allow(type_alias_bounds)]
130+
#[pallet::storage]
131131
type Foo<T: Trait> = StorageValueType<_, T::Balance, ValueQuery, OnFooEmpty<T>>;
132132
pub struct OnFooEmpty<T: Trait>(PhantomData<T>); // TODO TODO: allow faster declaration with parameter_types
133133
impl<T: Trait> Get<T::Balance> for OnFooEmpty<T> { fn get() -> T::Balance { 3.into() } }
134134
// #[pallet::type_value] pub struct BalanceDefault: Balance = 0;
135135
// #[pallet::type_value] pub fn BalanceDefault<T: Trait>() -> T::Balance { 0.into() }
136136
// #[pallet::type_value] pub struct BalanceDefault<T: Trait>(fn() -> T::Balance { 0.into() })
137137

138-
#[pallet::storage] #[allow(type_alias_bounds)]
138+
#[pallet::storage]
139139
type Double = StorageDoubleMapType<
140140
_, Blake2_128Concat, u32, Twox64Concat, u64, u16, ValueQuery
141141
>;

frame/support/test/tests/pallet_compatibility_instance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,21 @@ pub mod pallet {
118118
Dummy(T::Balance),
119119
}
120120

121-
#[pallet::storage] #[allow(type_alias_bounds)]
121+
#[pallet::storage]
122122
/// Some documentation
123123
type Dummy<T: Trait<I>, I: Instance = DefaultInstance> = StorageValueType<_, T::Balance, OptionQuery>;
124124

125-
#[pallet::storage] #[allow(type_alias_bounds)]
125+
#[pallet::storage]
126126
type Bar<T: Trait<I>, I: Instance = DefaultInstance> =
127127
StorageMapType<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;
128128

129-
#[pallet::storage] #[allow(type_alias_bounds)]
129+
#[pallet::storage]
130130
type Foo<T: Trait<I>, I: Instance = DefaultInstance> =
131131
StorageValueType<_, T::Balance, ValueQuery, OnFooEmpty<T, I>>;
132132
pub struct OnFooEmpty<T: Trait<I>, I: Instance>(PhantomData<(T, I)>);
133133
impl<T: Trait<I>, I: Instance> Get<T::Balance> for OnFooEmpty<T, I> { fn get() -> T::Balance { 3.into() } }
134134

135-
#[pallet::storage] #[allow(type_alias_bounds)]
135+
#[pallet::storage]
136136
type Double<I: Instance = DefaultInstance> = StorageDoubleMapType<
137137
_, Blake2_128Concat, u32, Twox64Concat, u64, u16, ValueQuery
138138
>;

0 commit comments

Comments
 (0)