Implement #[pallet::composite_enum] (#13722)

* Implement #[pallet::hold_reason]

* Appease clippy

* cargo fmt

* Update test expectations

* Update test expectations

* Support composite_enum attribute instead

* Update test expectations

* Change hold_reason to composite_enum

* Add UI test for unsupported identifier when using composite_enum

* Fix comment

* Add documentation for pallet::composable_enum

* More docs

* cargo fmt
This commit is contained in:
Keith Yeung
2023-04-04 20:28:46 +08:00
committed by GitHub
parent c268f3d3c8
commit 1a55f961c6
26 changed files with 682 additions and 11 deletions
@@ -0,0 +1,13 @@
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::composite_enum]
pub enum HoldReasons {}
}
fn main() {}
@@ -0,0 +1,5 @@
error: expected one of: `FreezeReason`, `HoldReason`, `LockId`, `SlashReason`
--> tests/pallet_ui/composite_enum_unsupported_identifier.rs:10:11
|
10 | pub enum HoldReasons {}
| ^^^^^^^^^^^
@@ -1,4 +1,4 @@
error: Invalid pallet::event, expected item enum
error: Invalid pallet::event, expected enum item
--> $DIR/event_wrong_item.rs:19:2
|
19 | pub struct Foo;
@@ -0,0 +1,14 @@
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::composite_enum]
pub struct HoldReason;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::composite_enum, expected enum item
--> tests/pallet_ui/hold_reason_non_enum.rs:10:2
|
10 | pub struct HoldReason;
| ^^^
@@ -0,0 +1,14 @@
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::composite_enum]
enum HoldReason {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::composite_enum, `HoldReason` must be public
--> tests/pallet_ui/hold_reason_not_pub.rs:10:5
|
10 | enum HoldReason {}
| ^^^^
@@ -0,0 +1,17 @@
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::composite_enum]
pub enum LockId {}
#[pallet::composite_enum]
pub enum LockId {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid duplicated `LockId` definition
--> tests/pallet_ui/lock_id_duplicate.rs:13:14
|
13 | pub enum LockId {}
| ^^^^^^