mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 01:57:56 +00:00
BREAKING: Rename Call & Event (#11981)
* rename Event to RuntimeEvent * rename Call * rename in runtimes * small fix * rename Event * small fix & rename RuntimeCall back to Call for now * small fixes * more renaming * a bit more renaming * fmt * small fix * commit * prep for renaming associated types * fix * rename associated Event type * rename to RuntimeEvent * commit * merge conflict fixes & fmt * additional renaming * fix. * fix decl_event * rename in tests * remove warnings * remove accidental rename * . * commit * update .stderr * fix in test * update .stderr * TRYBUILD=overwrite * docs * fmt * small change in docs * rename PalletEvent to Event * rename Call to RuntimeCall * renamed at wrong places :P * rename Call * rename * rename associated type * fix * fix & fmt * commit * frame-support-test * passing tests * update docs * rustdoc fix * update .stderr * wrong code in docs * merge fix * fix in error message * update .stderr * docs & error message * . * merge fix * merge fix * fmt * fmt * merge fix * more fixing * fmt * remove unused * fmt * fix Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ mod keyword {
|
||||
syn::custom_keyword!(I);
|
||||
syn::custom_keyword!(config);
|
||||
syn::custom_keyword!(IsType);
|
||||
syn::custom_keyword!(RuntimeEvent);
|
||||
syn::custom_keyword!(Event);
|
||||
syn::custom_keyword!(constant);
|
||||
syn::custom_keyword!(frame_system);
|
||||
@@ -42,8 +43,9 @@ pub struct ConfigDef {
|
||||
pub has_instance: bool,
|
||||
/// Const associated type.
|
||||
pub consts_metadata: Vec<ConstMetadataDef>,
|
||||
/// Whether the trait has the associated type `Event`, note that those bounds are checked:
|
||||
/// * `IsType<Self as frame_system::Config>::Event`
|
||||
/// Whether the trait has the associated type `Event`, note that those bounds are
|
||||
/// checked:
|
||||
/// * `IsType<Self as frame_system::Config>::RuntimeEvent`
|
||||
/// * `From<Event>` or `From<Event<T>>` or `From<Event<T, I>>`
|
||||
pub has_event_type: bool,
|
||||
/// The where clause on trait definition but modified so `Self` is `T`.
|
||||
@@ -159,7 +161,7 @@ impl syn::parse::Parse for ConfigBoundParse {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse for `IsType<<Sef as $ident::Config>::Event>` and retrieve `$ident`
|
||||
/// Parse for `IsType<<Sef as $ident::Config>::RuntimeEvent>` and retrieve `$ident`
|
||||
pub struct IsTypeBoundEventParse(syn::Ident);
|
||||
|
||||
impl syn::parse::Parse for IsTypeBoundEventParse {
|
||||
@@ -174,7 +176,7 @@ impl syn::parse::Parse for IsTypeBoundEventParse {
|
||||
input.parse::<keyword::Config>()?;
|
||||
input.parse::<syn::Token![>]>()?;
|
||||
input.parse::<syn::Token![::]>()?;
|
||||
input.parse::<keyword::Event>()?;
|
||||
input.parse::<keyword::RuntimeEvent>()?;
|
||||
input.parse::<syn::Token![>]>()?;
|
||||
|
||||
Ok(Self(ident))
|
||||
@@ -212,7 +214,7 @@ impl syn::parse::Parse for FromEventParse {
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if trait_item is `type Event`, if so checks its bounds are those expected.
|
||||
/// Check if trait_item is `type RuntimeEvent`, if so checks its bounds are those expected.
|
||||
/// (Event type is reserved type)
|
||||
fn check_event_type(
|
||||
frame_system: &syn::Ident,
|
||||
@@ -220,10 +222,10 @@ fn check_event_type(
|
||||
trait_has_instance: bool,
|
||||
) -> syn::Result<bool> {
|
||||
if let syn::TraitItem::Type(type_) = trait_item {
|
||||
if type_.ident == "Event" {
|
||||
if type_.ident == "RuntimeEvent" {
|
||||
// Check event has no generics
|
||||
if !type_.generics.params.is_empty() || type_.generics.where_clause.is_some() {
|
||||
let msg = "Invalid `type Event`, associated type `Event` is reserved and must have\
|
||||
let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must have\
|
||||
no generics nor where_clause";
|
||||
return Err(syn::Error::new(trait_item.span(), msg))
|
||||
}
|
||||
@@ -236,8 +238,8 @@ fn check_event_type(
|
||||
|
||||
if !has_is_type_bound {
|
||||
let msg = format!(
|
||||
"Invalid `type Event`, associated type `Event` is reserved and must \
|
||||
bound: `IsType<<Self as {}::Config>::Event>`",
|
||||
"Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \
|
||||
bound: `IsType<<Self as {}::Config>::RuntimeEvent>`",
|
||||
frame_system,
|
||||
);
|
||||
return Err(syn::Error::new(type_.span(), msg))
|
||||
@@ -251,14 +253,14 @@ fn check_event_type(
|
||||
let from_event_bound = if let Some(b) = from_event_bound {
|
||||
b
|
||||
} else {
|
||||
let msg = "Invalid `type Event`, associated type `Event` is reserved and must \
|
||||
let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \
|
||||
bound: `From<Event>` or `From<Event<Self>>` or `From<Event<Self, I>>`";
|
||||
return Err(syn::Error::new(type_.span(), msg))
|
||||
};
|
||||
|
||||
if from_event_bound.is_generic && (from_event_bound.has_instance != trait_has_instance)
|
||||
{
|
||||
let msg = "Invalid `type Event`, associated type `Event` bounds inconsistent \
|
||||
let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` bounds inconsistent \
|
||||
`From<Event..>`. Config and generic Event must be both with instance or \
|
||||
without instance";
|
||||
return Err(syn::Error::new(type_.span(), msg))
|
||||
|
||||
@@ -105,11 +105,11 @@ impl Def {
|
||||
let m = hooks::HooksDef::try_from(span, index, item)?;
|
||||
hooks = Some(m);
|
||||
},
|
||||
Some(PalletAttr::Call(span)) if call.is_none() =>
|
||||
Some(PalletAttr::RuntimeCall(span)) if call.is_none() =>
|
||||
call = Some(call::CallDef::try_from(span, index, item)?),
|
||||
Some(PalletAttr::Error(span)) if error.is_none() =>
|
||||
error = Some(error::ErrorDef::try_from(span, index, item)?),
|
||||
Some(PalletAttr::Event(span)) if event.is_none() =>
|
||||
Some(PalletAttr::RuntimeEvent(span)) if event.is_none() =>
|
||||
event = Some(event::EventDef::try_from(span, index, item)?),
|
||||
Some(PalletAttr::GenesisConfig(_)) if genesis_config.is_none() => {
|
||||
let g = genesis_config::GenesisConfigDef::try_from(index, item)?;
|
||||
@@ -182,19 +182,19 @@ impl Def {
|
||||
}
|
||||
|
||||
/// Check that usage of trait `Event` is consistent with the definition, i.e. it is declared
|
||||
/// and trait defines type Event, or not declared and no trait associated type.
|
||||
/// and trait defines type RuntimeEvent, or not declared and no trait associated type.
|
||||
fn check_event_usage(&self) -> syn::Result<()> {
|
||||
match (self.config.has_event_type, self.event.is_some()) {
|
||||
(true, false) => {
|
||||
let msg = "Invalid usage of Event, `Config` contains associated type `Event`, \
|
||||
let msg = "Invalid usage of RuntimeEvent, `Config` contains associated type `RuntimeEvent`, \
|
||||
but enum `Event` is not declared (i.e. no use of `#[pallet::event]`). \
|
||||
Note that type `Event` in trait is reserved to work alongside pallet event.";
|
||||
Note that type `RuntimeEvent` in trait is reserved to work alongside pallet event.";
|
||||
Err(syn::Error::new(proc_macro2::Span::call_site(), msg))
|
||||
},
|
||||
(false, true) => {
|
||||
let msg = "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`.";
|
||||
let msg = "Invalid usage of RuntimeEvent, `Config` contains no associated type \
|
||||
`RuntimeEvent`, but enum `Event` is declared (in use of `#[pallet::event]`). \
|
||||
An RuntimeEvent associated type must be declare on trait `Config`.";
|
||||
Err(syn::Error::new(proc_macro2::Span::call_site(), msg))
|
||||
},
|
||||
_ => Ok(()),
|
||||
@@ -391,9 +391,9 @@ enum PalletAttr {
|
||||
Config(proc_macro2::Span),
|
||||
Pallet(proc_macro2::Span),
|
||||
Hooks(proc_macro2::Span),
|
||||
Call(proc_macro2::Span),
|
||||
RuntimeCall(proc_macro2::Span),
|
||||
Error(proc_macro2::Span),
|
||||
Event(proc_macro2::Span),
|
||||
RuntimeEvent(proc_macro2::Span),
|
||||
Origin(proc_macro2::Span),
|
||||
Inherent(proc_macro2::Span),
|
||||
Storage(proc_macro2::Span),
|
||||
@@ -410,9 +410,9 @@ impl PalletAttr {
|
||||
Self::Config(span) => *span,
|
||||
Self::Pallet(span) => *span,
|
||||
Self::Hooks(span) => *span,
|
||||
Self::Call(span) => *span,
|
||||
Self::RuntimeCall(span) => *span,
|
||||
Self::Error(span) => *span,
|
||||
Self::Event(span) => *span,
|
||||
Self::RuntimeEvent(span) => *span,
|
||||
Self::Origin(span) => *span,
|
||||
Self::Inherent(span) => *span,
|
||||
Self::Storage(span) => *span,
|
||||
@@ -441,11 +441,11 @@ impl syn::parse::Parse for PalletAttr {
|
||||
} else if lookahead.peek(keyword::hooks) {
|
||||
Ok(PalletAttr::Hooks(content.parse::<keyword::hooks>()?.span()))
|
||||
} else if lookahead.peek(keyword::call) {
|
||||
Ok(PalletAttr::Call(content.parse::<keyword::call>()?.span()))
|
||||
Ok(PalletAttr::RuntimeCall(content.parse::<keyword::call>()?.span()))
|
||||
} else if lookahead.peek(keyword::error) {
|
||||
Ok(PalletAttr::Error(content.parse::<keyword::error>()?.span()))
|
||||
} else if lookahead.peek(keyword::event) {
|
||||
Ok(PalletAttr::Event(content.parse::<keyword::event>()?.span()))
|
||||
Ok(PalletAttr::RuntimeEvent(content.parse::<keyword::event>()?.span()))
|
||||
} else if lookahead.peek(keyword::origin) {
|
||||
Ok(PalletAttr::Origin(content.parse::<keyword::origin>()?.span()))
|
||||
} else if lookahead.peek(keyword::inherent) {
|
||||
|
||||
Reference in New Issue
Block a user