This repository was 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.7k
Allow additional trait bounds for #[pallet::constant]
#9050
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8d606de
Allow additional trait bounds for constants
ascjones ec05773
Add ui test for constants with additional trait bounds
ascjones cec1de6
Merge branch 'master' into aj-constant-parsing
ascjones 0715e71
Update trait constant ui test
ascjones dd974ee
Import syn::Error
ascjones dd129c9
Use reference instead of cloning
ascjones dfb8b1b
Add extra invalid bound ui test
ascjones 110ab91
Out or order valid bounds
ascjones 1ef9ce0
Fix ui test
ascjones 8d46ec7
Fix ui test
ascjones b1536e1
Apply review suggestion about error message
ascjones 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 hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
frame/support/test/tests/pallet_ui/pass/trait_constant_valid_bounds.rs
This file contains hidden or 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,29 @@ | ||
| #[frame_support::pallet] | ||
| mod pallet { | ||
| use frame_support::pallet_prelude::*; | ||
| use frame_system::pallet_prelude::BlockNumberFor; | ||
|
|
||
| #[pallet::config] | ||
| pub trait Config: frame_system::Config { | ||
| #[pallet::constant] | ||
| type U: Get<u32>; | ||
|
|
||
| #[pallet::constant] | ||
| type V: Get<u32> + From<u16>; | ||
|
|
||
| #[pallet::constant] | ||
| type W: From<u16> + 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() { | ||
| } |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
frame/support/test/tests/pallet_ui/trait_constant_invalid_bound_lifetime.rs
This file contains hidden or 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::Hooks; | ||
| use frame_system::pallet_prelude::BlockNumberFor; | ||
|
|
||
| #[pallet::config] | ||
| pub trait Config: frame_system::Config { | ||
| #[pallet::constant] | ||
| type U: Get<'static>; | ||
| } | ||
|
|
||
| #[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() { | ||
| } |
11 changes: 11 additions & 0 deletions
11
frame/support/test/tests/pallet_ui/trait_constant_invalid_bound_lifetime.stderr
This file contains hidden or 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,11 @@ | ||
| error: Invalid usage of `#[pallet::constant]`, syntax must be `type $SomeIdent: Get<$SomeType>;` | ||
| --> $DIR/trait_constant_invalid_bound_lifetime.rs:9:3 | ||
| | | ||
| 9 | type U: Get<'static>; | ||
| | ^^^^ | ||
|
|
||
| error: Expected a type argument | ||
| --> $DIR/trait_constant_invalid_bound_lifetime.rs:9:15 | ||
| | | ||
| 9 | type U: Get<'static>; | ||
| | ^^^^^^^ |
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.
Uh oh!
There was an error while loading. Please reload this page.