Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix where clause on rust stable
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed May 16, 2022
1 parent 4448e20 commit 608e985
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
21 changes: 15 additions & 6 deletions frame/support/procedural/src/storage_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ struct Input {
_type: Token![type],
storage_name: Ident,
storage_generics: Option<SimpleGenerics>,
where_clause: Option<WhereClause>,
_equal: Token![=],
storage_type: StorageType,
where_clause: Option<WhereClause>,
_semicolon: Token![;],
}

Expand All @@ -426,17 +426,26 @@ impl Parse for Input {
let storage_name = input.parse()?;

let lookahead = input.lookahead1();
let (storage_generics, _equal) = if lookahead.peek(Token![<]) {
(Some(input.parse()?), input.parse()?)
let storage_generics = if lookahead.peek(Token![<]) {
Some(input.parse()?)
} else if lookahead.peek(Token![=]) {
(None, input.parse()?)
None
} else {
return Err(lookahead.error())
};

let storage_type = input.parse()?;
let lookahead = input.lookahead1();
let where_clause = if lookahead.peek(Token![where]) {
Some(input.parse()?)
} else if lookahead.peek(Token![=]) {
None
} else {
return Err(lookahead.error())
};

let _equal = input.parse()?;

let where_clause = input.parse()?;
let storage_type = input.parse()?;

let _semicolon = input.parse()?;

Expand Down
7 changes: 4 additions & 3 deletions frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,9 +1640,10 @@ fn assert_type_all_pallets_without_system_reversed_is_correct() {
#[test]
fn test_storage_alias() {
#[frame_support::storage_alias]
type Value<T: pallet::Config> =
StorageValue<pallet::Pallet<T>, u32, ValueQuery>
where <T as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1;
type Value<T: pallet::Config>
where
<T as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1,
= StorageValue<pallet::Pallet<T>, u32, ValueQuery>;

TestExternalities::default().execute_with(|| {
pallet::Value::<Runtime>::put(10);
Expand Down

0 comments on commit 608e985

Please sign in to comment.