Add pallet attribute macro to declare pallets (#6877)

* rename system Config to system Trait.

command used:
```
find frame/ bin/ test-utils/ utils/ -name *.rs -exec sed -i 's/system::Trait>::/system::Config>::/g' {} \;
find frame/ bin/ test-utils/ utils/ -name *.rs -exec sed -i 's/impl frame_system::Trait for /impl frame_system::Config for /g' {} \;
find frame/ bin/ test-utils/ utils/ -name *.rs -exec sed -i 's/impl system::Trait for /impl system::Config for /g' {} \;
```
plus some manual ones especially for frame-support tests and frame-system

* make construct_runtime handle Pallet and Module

pallets can now be implemented on struct named Pallet or Module, both
definition are valid.
This is because next macro will generate only Pallet placeholder.

* introduce pallet attribute macro

currently just with tests, frame_system and other example hasn't been
upgraded

* allow to print some upgrade helper from decl_storage

* Improved error msg, typo.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Improved error msg, typo.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Improved error message on unexpected attributes + ui test

* add test for transactional

* various typo

* some tips when spans are lost

* allow pallet to depend on other pallet instances

* make event type metadata consistent with call and constant

* error messages

* ignore doc example

* fix pallet upgrade template

* fixup

* fix doc

* fix indentation

* Apply suggestions code formatting

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* some renames + fix compilation

* remove unsupported genesis config type alias

* merge fixup

* fix ui tests

* additional doc

* implement StorageInstance with new syntax

* fix line width

* fix doc: because pallet doc goes below reexport doc

* Update frame/support/procedural/src/pallet/parse/event.rs

Co-authored-by: Andrew Jones <ascjones@gmail.com>

* Update frame/system/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/test/tests/pallet_ui.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* improve doc as suggested

* revert construct_runtime Pallet part.

This revert the changes on construct_runtime. Now construct_runtime is
unchanged and instead pallet macro create a type alias
`type Module<..> = Pallet<..>` to be used by construct_runtime

* refactor with less intricated code

* fix ui test with new image

* fix ui tests

* add minor tests

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Guillaume Thiolliere
2020-12-24 12:33:40 +01:00
committed by GitHub
parent 8e3d8a6a09
commit 6dfad0921b
131 changed files with 9610 additions and 31 deletions
@@ -0,0 +1,6 @@
#[frame_support::pallet [foo]]
mod foo {
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet macro call: expected no attributes, e.g. macro call must be just `#[frame_support::pallet]` or `#[pallet]`
--> $DIR/attr_non_empty.rs:1:26
|
1 | #[frame_support::pallet [foo]]
| ^^^
@@ -0,0 +1,27 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar: codec::Codec;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
}
fn main() {
}
@@ -0,0 +1,28 @@
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> $DIR/call_argument_invalid_bound.rs:20:37
|
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^
|
help: consider further restricting this bound
|
1 | #[frame_support::pallet] + std::cmp::PartialEq
| ^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> $DIR/call_argument_invalid_bound.rs:20:37
|
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
= note: required by `clone`
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
--> $DIR/call_argument_invalid_bound.rs:20:37
|
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
= note: required for the cast to the object type `dyn std::fmt::Debug`
@@ -0,0 +1,27 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
}
fn main() {
}
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `pallet::Call<T>: Decode` is not satisfied
--> $DIR/call_argument_invalid_bound_2.rs:17:12
|
17 | #[pallet::call]
| ^^^^ the trait `Decode` is not implemented for `pallet::Call<T>`
error[E0277]: the trait bound `pallet::Call<T>: pallet::_::_parity_scale_codec::Encode` is not satisfied
--> $DIR/call_argument_invalid_bound_2.rs:17:12
|
17 | #[pallet::call]
| ^^^^ the trait `pallet::_::_parity_scale_codec::Encode` is not implemented for `pallet::Call<T>`
@@ -0,0 +1,29 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
use codec::{Encode, Decode};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[derive(Encode, Decode)]
struct Bar;
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
}
fn main() {
}
@@ -0,0 +1,26 @@
error[E0369]: binary operation `==` cannot be applied to type `&Bar`
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `&Bar`
error[E0277]: the trait bound `Bar: Clone` is not satisfied
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `Clone` is not implemented for `Bar`
|
= note: required by `clone`
error[E0277]: `Bar` doesn't implement `std::fmt::Debug`
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^ `Bar` cannot be formatted using `{:?}`
|
= help: the trait `std::fmt::Debug` is not implemented for `Bar`
= note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&Bar`
= note: required for the cast to the object type `dyn std::fmt::Debug`
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
const Foo: u8 = 3u8;
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, only method accepted
--> $DIR/call_invalid_const.rs:17:3
|
17 | const Foo: u8 = 3u8;
| ^^^^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo(origin: u8) {}
}
}
fn main() {
}
@@ -0,0 +1,11 @@
error: Invalid type: expected `OriginFor<T>`
--> $DIR/call_invalid_origin_type.rs:17:18
|
17 | fn foo(origin: u8) {}
| ^^
error: expected `OriginFor`
--> $DIR/call_invalid_origin_type.rs:17:18
|
17 | fn foo(origin: u8) {}
| ^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, require weight attribute i.e. `#[pallet::weight = $expr]`
--> $DIR/call_missing_weight.rs:17:3
|
17 | fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
| ^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo() {}
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, must have at least origin arg
--> $DIR/call_no_origin.rs:17:3
|
17 | fn foo() {}
| ^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo(origin: OriginFor<T>) {}
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, require return type DispatchResultWithPostInfo
--> $DIR/call_no_return.rs:17:3
|
17 | fn foo(origin: OriginFor<T>) {}
| ^^
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid duplicated attribute
--> $DIR/duplicate_call_attr.rs:23:12
|
23 | #[pallet::call]
| ^^^^
@@ -0,0 +1,26 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(trait Store)]
#[pallet::generate_store(trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::pallet, multiple argument pallet::generate_store found
--> $DIR/duplicate_store_attr.rs:12:33
|
12 | #[pallet::generate_store(trait Store)]
| ^^^^^
@@ -0,0 +1,25 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::error]
pub enum Error<T> {
U8(u8),
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::error, unexpected fields, must be `Unit`
--> $DIR/error_no_fieldless.rs:20:5
|
20 | U8(u8),
| ^^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::error]
pub struct Foo;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::error, expected item enum
--> $DIR/error_wrong_item.rs:19:2
|
19 | pub struct Foo;
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::error]
pub enum Foo<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: expected `Error`
--> $DIR/error_wrong_item_name.rs:19:11
|
19 | pub enum Foo<T> {}
| ^^^
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, IsType};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,28 @@
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
--> $DIR/event_field_not_member.rs:23:7
|
23 | B { b: T::Bar },
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
= note: required for the cast to the object type `dyn std::fmt::Debug`
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> $DIR/event_field_not_member.rs:23:7
|
23 | B { b: T::Bar },
| ^
|
help: consider further restricting this bound
|
22 | pub enum Event<T: Config + std::cmp::PartialEq> {
| ^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> $DIR/event_field_not_member.rs:23:7
|
23 | B { b: T::Bar },
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
= note: required by `clone`
@@ -0,0 +1,27 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,7 @@
error: Invalid usage of Event, `Config` contains no associated type `Event`, but enum `Event` is declared (in use of `#[pallet::event]`). An Event associated type must be declare on trait `Config`.
--> $DIR/event_not_in_trait.rs:1:1
|
1 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
type Event;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid `type Event`, associated type `Event` is reserved and must bound: `IsType<<Self as frame_system::Config>::Event>`
--> $DIR/event_type_invalid_bound.rs:9:3
|
9 | type Event;
| ^^^^
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, IsType};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
type Event: IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid `type Event`, associated type `Event` is reserved and must bound: `From<Event>` or `From<Event<Self>>` or `From<Event<Self, I>>`
--> $DIR/event_type_invalid_bound_2.rs:9:3
|
9 | type Event: IsType<<Self as frame_system::Config>::Event>;
| ^^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub struct Foo;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::event, expected item enum
--> $DIR/event_wrong_item.rs:19:2
|
19 | pub struct Foo;
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: expected `Event`
--> $DIR/event_wrong_item_name.rs:19:11
|
19 | pub enum Foo {}
| ^^^
@@ -0,0 +1,26 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, GenesisBuild};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_config]
pub struct GenesisConfig;
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {}
}
fn main() {
}
@@ -0,0 +1,10 @@
error[E0277]: the trait bound `pallet::GenesisConfig: std::default::Default` is not satisfied
--> $DIR/genesis_default_not_satisfied.rs:22:18
|
22 | impl<T: Config> GenesisBuild<T> for GenesisConfig {}
| ^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `pallet::GenesisConfig`
|
::: $WORKSPACE/frame/support/src/traits.rs
|
| pub trait GenesisBuild<T, I=()>: Default + MaybeSerializeDeserialize {
| ------- required by this bound in `GenesisBuild`
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: `#[pallet::genesis_config]` and `#[pallet::genesis_build]` attributes must be either both used or both not used, instead genesis_config is unused and genesis_build is used
--> $DIR/genesis_inconsistent_build_config.rs:2:1
|
2 | mod pallet {
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_build]
impl GenesisBuild for GenesisConfig {}
}
fn main() {
}
@@ -0,0 +1,13 @@
error: Invalid genesis builder: expected `GenesisBuild<T>` or `GenesisBuild<T, I>`
--> $DIR/genesis_invalid_generic.rs:19:7
|
19 | impl GenesisBuild for GenesisConfig {}
| ^^^^^^^^^^^^
error: expected `<`
--> $DIR/genesis_invalid_generic.rs:1:1
|
1 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_build]
impl Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::genesis_build, expected impl<..> GenesisBuild<..> for GenesisConfig<..>
--> $DIR/genesis_wrong_name.rs:19:2
|
19 | impl Foo {}
| ^^^^
@@ -0,0 +1,19 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/hooks_invalid_item.rs:12:18
|
12 | impl<T: Config> Hooks for Pallet<T> {}
| ^^^^^ expected 1 type argument
@@ -0,0 +1,20 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,29 @@
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:16:7
|
16 | impl<T: Config> Pallet<T> {}
| ^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:16:18
|
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
|
13 | impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:13:7
|
13 | impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
| ^
@@ -0,0 +1,20 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T, I = ()>(core::marker::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> {}
}
fn main() {
}
@@ -0,0 +1,29 @@
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:16:7
|
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:16:33
|
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
|
13 | impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:13:7
|
13 | impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
| ^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, ProvideInherent};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::inherent]
impl<T: Config> ProvideInherent for Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,10 @@
error[E0046]: not all trait items implemented, missing: `Call`, `Error`, `INHERENT_IDENTIFIER`, `create_inherent`
--> $DIR/inherent_check_inner_span.rs:19:2
|
19 | impl<T: Config> ProvideInherent for Pallet<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Call`, `Error`, `INHERENT_IDENTIFIER`, `create_inherent` in implementation
|
= help: implement the missing item: `type Call = Type;`
= help: implement the missing item: `type Error = Type;`
= help: implement the missing item: `const INHERENT_IDENTIFIER: [u8; 8] = value;`
= help: implement the missing item: `fn create_inherent(_: &InherentData) -> std::option::Option<<Self as ProvideInherent>::Call> { todo!() }`
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::inherent]
impl Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::inherent, expected impl<..> ProvideInherent for Pallet<..>
--> $DIR/inherent_invalid_item.rs:19:2
|
19 | impl Foo {}
| ^^^^
@@ -0,0 +1,5 @@
#[frame_support::pallet]
mod foo;
fn main() {
}
@@ -0,0 +1,13 @@
error[E0658]: non-inline modules in proc macro input are unstable
--> $DIR/mod_not_inlined.rs:2:1
|
2 | mod foo;
| ^^^^^^^^
|
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
error: Invalid pallet definition, expected mod to be inlined.
--> $DIR/mod_not_inlined.rs:2:1
|
2 | mod foo;
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo;
}
fn main() {
}
@@ -0,0 +1,13 @@
error: free type alias without body
--> $DIR/storage_incomplete_item.rs:19:2
|
19 | type Foo;
| ^^^^^^^^-
| |
| help: provide a definition for the type: `= <type>;`
error[E0433]: failed to resolve: use of undeclared crate or module `pallet`
--> $DIR/storage_incomplete_item.rs:18:4
|
18 | #[pallet::storage]
| ^^^^^^ use of undeclared crate or module `pallet`
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<u8, u8>;
}
fn main() {
}
@@ -0,0 +1,11 @@
error: Invalid use of `#[pallet::storage]`, the type first generic argument must be `_`, the final argument is automatically set by macro.
--> $DIR/storage_invalid_first_generic.rs:19:29
|
19 | type Foo<T> = StorageValue<u8, u8>;
| ^^
error: expected `_`
--> $DIR/storage_invalid_first_generic.rs:19:29
|
19 | type Foo<T> = StorageValue<u8, u8>;
| ^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = u8;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, expected ident: `StorageValue` or `StorageMap` or `StorageDoubleMap` in order to expand metadata, found `u8`
--> $DIR/storage_not_storage_type.rs:19:16
|
19 | type Foo<T> = u8;
| ^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: pallet::storage unexpected number of generic argument, expected at least 2 args, found none
--> $DIR/storage_value_no_generic.rs:19:16
|
19 | type Foo<T> = StorageValue;
| ^^^^^^^^^^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
impl Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, expected item type
--> $DIR/storage_wrong_item.rs:19:2
|
19 | impl Foo {}
| ^^^^
@@ -0,0 +1,25 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
}
fn main() {
}
@@ -0,0 +1,8 @@
error[E0446]: private type `_GeneratedPrefixForStorageFoo<T>` in public interface
--> $DIR/store_trait_leak_private.rs:11:37
|
11 | #[pallet::generate_store(pub trait Store)]
| ^^^^^ can't leak private type
...
21 | type Foo<T> = StorageValue<_, u8>;
| - `_GeneratedPrefixForStorageFoo<T>` declared as private
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
#[pallet::constant]
type U;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,11 @@
error: Invalid usage of `#[pallet::constant]`, syntax must be `type $SomeIdent: Get<$SomeType>;`
--> $DIR/trait_constant_invalid_bound.rs:9:3
|
9 | type U;
| ^^^^
error: expected `:`
--> $DIR/trait_constant_invalid_bound.rs:9:9
|
9 | type U;
| ^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
#[pallet::constant]
const U: u8 = 3;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::constant in pallet::config, expected type trait item
--> $DIR/trait_invalid_item.rs:9:3
|
9 | const U: u8 = 3;
| ^^^^^
@@ -0,0 +1,21 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config {
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::trait, expected explicit `frame_system::Config` as supertrait, found none. (try `pub trait Config: frame_system::Config { ...` or `pub trait Config<I: 'static>: frame_system::Config { ...`). To disable this check, use `#[pallet::disable_frame_system_supertrait_check]`
--> $DIR/trait_no_supertrait.rs:7:2
|
7 | pub trait Config {
| ^^^
@@ -0,0 +1,25 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::type_value] fn Foo() -> u32 {
// Just wrong code to see span
u32::new()
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error[E0599]: no function or associated item named `new` found for type `u32` in the current scope
--> $DIR/type_value_error_in_block.rs:20:8
|
20 | u32::new()
| ^^^ function or associated item not found in `u32`
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::type_value] struct Foo;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::type_value, expected item fn
--> $DIR/type_value_invalid_item.rs:18:24
|
18 | #[pallet::type_value] struct Foo;
| ^^^^^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::type_value] fn Foo() {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::type_value, expected return type
--> $DIR/type_value_no_return.rs:18:24
|
18 | #[pallet::type_value] fn Foo() {}
| ^^