This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Adds ability to provide defaults for types provided by construct_runtime
#14682
Merged
paritytech-processbot
merged 46 commits into
master
from
gupnik/derive-impl-improvements
Aug 25, 2023
Merged
Changes from 15 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
bfc3ff7
Adds ability to use defaults for verbatim types
gupnik 18dc0ac
Adds RuntimeOrigin and PalletInfo in DefaultConfig
gupnik 7fb9749
Adds RuntimeEvent in DefaultConfig
gupnik 43fff80
Adds RuntimeEvent in DefaultConfig
gupnik 8e45209
Minor fix
gupnik 9af59d6
Minor fix
gupnik 44f2845
Everything in frame_system can now have a default
gupnik eed9dc8
Adds docs
gupnik d2a3546
Adds UI Test for no_bounds
gupnik 821424a
Updates docs
gupnik 5e54173
Adds UI tests for verbatim
gupnik cd3e530
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik 641cc9b
Minor update
gupnik 90af58e
Minor updates
gupnik c3f5134
Minor updates
gupnik 7f80e65
Addresses review comments
gupnik 38c0601
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik 846f296
Fixes test
gupnik 6dfb929
Update frame/support/procedural/src/derive_impl.rs
gupnik 0ddf452
Minor fix
gupnik 3e90665
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik de6e5b6
Minor
gupnik ce1ad29
Optionally keep verbatim to be replaced later
gupnik 821758b
Fixes build
gupnik d33f51f
Uses runtime_type
gupnik 96fc62c
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik e051985
Fixes comment
gupnik 16028ff
Fixes comment
gupnik 34f66f6
Fixes test
gupnik 97e470c
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik 92ddd1e
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik 3524c14
Uses no_aggregated_types as an option in derive_impl
gupnik 1218faf
Uses specific imports
gupnik 01071a9
Fmt
gupnik a3db9f4
Updates doc
gupnik 28f7cec
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik 9d31723
Update frame/support/procedural/src/derive_impl.rs
gupnik 3f1fcc6
Update frame/support/procedural/src/derive_impl.rs
gupnik 58762cf
Addresses review comment
gupnik cb2a8e0
Addresses review comment
gupnik 32f33ae
fmt
gupnik 88f6253
Renames test files
gupnik bb30704
Adds docs using docify
gupnik 8f3191f
Fixes test
gupnik 718c1ce
Fixes UI tests
gupnik 969bf0e
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
frame/support/test/tests/derive_impl_ui/pass/verbatim_working.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use frame_support::{*, pallet_macros::verbatim}; | ||
use static_assertions::assert_type_eq_all; | ||
|
||
pub trait Shape { | ||
type Area; | ||
} | ||
|
||
type Area = f32; | ||
|
||
struct DefaultShape; | ||
|
||
#[register_default_impl(DefaultShape)] | ||
impl Shape for DefaultShape { | ||
#[verbatim] | ||
type Area = (); | ||
gupnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
struct Circle; | ||
|
||
#[derive_impl(DefaultShape)] // Injects type Area = Area; | ||
impl Shape for Circle {} | ||
|
||
assert_type_eq_all!(<Circle as Shape>::Area, Area); | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
frame/support/test/tests/derive_impl_ui/verbatim_fails_when_type_not_in_scope.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use frame_support::{*, pallet_macros::verbatim}; | ||
use static_assertions::assert_type_eq_all; | ||
|
||
pub trait Shape { | ||
type Area; | ||
} | ||
|
||
struct DefaultShape; | ||
|
||
#[register_default_impl(DefaultShape)] | ||
impl Shape for DefaultShape { | ||
#[verbatim] | ||
type Area = (); | ||
} | ||
|
||
struct Circle; | ||
|
||
#[derive_impl(DefaultShape)] // Injects type Area = Area; | ||
impl Shape for Circle {} | ||
|
||
assert_type_eq_all!(<Circle as Shape>::Area, Area); | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
frame/support/test/tests/derive_impl_ui/verbatim_fails_when_type_not_in_scope.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0412]: cannot find type `Area` in this scope | ||
--> tests/derive_impl_ui/verbatim_fails_when_type_not_in_scope.rs:13:10 | ||
| | ||
13 | type Area = (); | ||
| ^^^^ help: you might have meant to use the associated type: `Self::Area` | ||
... | ||
18 | #[derive_impl(DefaultShape)] // Injects type Area = Area; | ||
| ---------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `__export_tokens_tt_default_shape` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0412]: cannot find type `Area` in this scope | ||
--> tests/derive_impl_ui/verbatim_fails_when_type_not_in_scope.rs:21:46 | ||
| | ||
21 | assert_type_eq_all!(<Circle as Shape>::Area, Area); | ||
| ^^^^ not found in this scope |
23 changes: 23 additions & 0 deletions
23
frame/support/test/tests/pallet_ui/no_bounds_but_missing_with_default.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
#[pallet::constant] | ||
#[pallet::no_bounds] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually we could think about grouping those. |
||
type MyGetParam2: Get<u32>; | ||
} | ||
|
||
#[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() {} |
5 changes: 5 additions & 0 deletions
5
frame/support/test/tests/pallet_ui/no_bounds_but_missing_with_default.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[pallet:no_bounds]` can only be used if `#[pallet::config(with_default)]` has been specified | ||
--> tests/pallet_ui/no_bounds_but_missing_with_default.rs:9:4 | ||
| | ||
9 | #[pallet::no_bounds] | ||
| ^^^^^^^^^^^^^^^^^^^ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice making this extendible 💯