Make hooks and call attributes optional in pallet macro (#8853)

* Make #[pallet::hooks] optional

* Make #[pallet::call] optional

* Remove unused imports

* Update UI test expectations

* Update UI test expectations

* Remove unnecessary HooksDef::empty method

* Remove unnecessary CallDef::empty method

* Clarify what would happen when no call or hooks are specified in a pallet
This commit is contained in:
Keith Yeung
2021-05-20 12:31:56 -07:00
committed by GitHub
parent 029b8a1d07
commit e5954cf863
9 changed files with 90 additions and 57 deletions
@@ -406,20 +406,11 @@ pub mod pallet2 {
/// Test that the supertrait check works when we pass some parameter to the `frame_system::Config`.
#[frame_support::pallet]
pub mod pallet3 {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config<Origin = ()> {}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
frame_support::parameter_types!(
@@ -209,7 +209,6 @@ pub mod pallet {
#[frame_support::pallet]
pub mod pallet2 {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
@@ -220,12 +219,6 @@ pub mod pallet2 {
#[pallet::generate_store(pub(crate) trait Store)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {}
#[pallet::event]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// Something
@@ -1,3 +1,9 @@
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:10:20
|
10 | pub struct Pallet<T>(core::marker::PhantomData<T>);
| ^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:16:7
|
@@ -10,12 +16,6 @@ error: Invalid generic declaration, trait is defined with instance but generic u
16 | impl<T: Config> Pallet<T> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:10:20
|
10 | pub struct Pallet<T>(core::marker::PhantomData<T>);
| ^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:13:47
|
@@ -1,3 +1,9 @@
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:10:20
|
10 | pub struct Pallet<T, I = ()>(core::marker::PhantomData<(T, I)>);
| ^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:16:7
|
@@ -10,12 +16,6 @@ error: Invalid generic declaration, trait is defined without instance but generi
16 | impl<T: Config<I>, I: 'static> Pallet<T, I> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:10:20
|
10 | pub struct Pallet<T, I = ()>(core::marker::PhantomData<(T, I)>);
| ^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:13:62
|