Move checks for renamed functions to __check_reserved_function_names (#3425)

* Move checks for renamed functions to `__check_reserved_function_names`

* Fix trybuild test
This commit is contained in:
Bastian Köcher
2019-08-17 01:14:21 +02:00
committed by GitHub
parent 6cc4495700
commit a0f2e9b396
3 changed files with 25 additions and 47 deletions
+22 -43
View File
@@ -362,25 +362,6 @@ macro_rules! decl_module {
$($rest)*
);
};
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{ $( $on_initialize:tt )* }
{}
{ $( $offchain:tt )* }
{ $( $constants:tt )* }
[ $( $dispatchables:tt )* ]
$(#[doc = $doc_attr:tt])*
fn on_finalise($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
$($rest:tt)*
) => {
compile_error!(
"`on_finalise` was renamed to `on_finalize`. Please rename your function accordingly."
);
};
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
@@ -410,25 +391,6 @@ macro_rules! decl_module {
$($rest)*
);
};
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $other_where_bounds:tt )* }
{ $( $deposit_event:tt )* }
{}
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
{ $( $constants:tt )* }
[ $( $dispatchables:tt )* ]
$(#[doc = $doc_attr:tt])*
fn on_initialize($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
$($rest:tt)*
) => {
compile_error!(
"`on_initialise` was renamed to `on_initialize`. Please rename your function accordingly."
);
};
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<
@@ -1576,13 +1538,13 @@ macro_rules! __check_reserved_fn_name {
$crate::__check_reserved_fn_name!(@compile_error on_initialize);
};
(on_initialise $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error on_initialise);
$crate::__check_reserved_fn_name!(@compile_error_renamed on_initialise on_initialize);
};
(on_finalize $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error on_finalize);
};
(on_finalise $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error on_finalise);
$crate::__check_reserved_fn_name!(@compile_error_renamed on_finalise on_finalize);
};
(offchain_worker $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error offchain_worker);
@@ -1592,9 +1554,26 @@ macro_rules! __check_reserved_fn_name {
};
() => {};
(@compile_error $ident:ident) => {
compile_error!(concat!("Invalid call fn name: `", stringify!($ident),
"`, name is reserved and doesn't match expected signature, please refer to `decl_module!`",
" documentation to see the appropriate usage, or rename it to an unreserved keyword."));
compile_error!(
concat!(
"Invalid call fn name: `",
stringify!($ident),
"`, name is reserved and doesn't match expected signature, please refer to ",
"`decl_module!` documentation to see the appropriate usage, or rename it to an ",
"unreserved keyword."
),
);
};
(@compile_error_renamed $ident:ident $new_ident:ident) => {
compile_error!(
concat!(
"`",
stringify!($ident),
"` was renamed to `",
stringify!($new_ident),
"`. Please rename your function accordingly.",
),
);
};
}
@@ -29,5 +29,4 @@ macro_rules! reserved {
reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
fn main() {
}
fn main() {}
@@ -14,7 +14,7 @@ error: Invalid call fn name: `on_initialize`, name is reserved and doesn't match
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Invalid call fn name: `on_finalise`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
error: `on_finalise` was renamed to `on_finalize`. Please rename your function accordingly.
--> $DIR/on_initialize.rs:30:1
|
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
@@ -22,7 +22,7 @@ error: Invalid call fn name: `on_finalise`, name is reserved and doesn't match e
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Invalid call fn name: `on_initialise`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
error: `on_initialise` was renamed to `on_initialize`. Please rename your function accordingly.
--> $DIR/on_initialize.rs:30:1
|
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);