Reserve function name (#2609)

* reserve function name

* bumpd impl version

* Revert "bumpd impl version"

This reverts commit 03a23e308312d857bdfd3c90ff564b4b11347530.

* add test

* update test

* update lock

* Fix test on stable
This commit is contained in:
thiolliere
2019-05-21 17:07:30 +02:00
committed by Bastian Köcher
parent 062b734571
commit 57f306a3c1
8 changed files with 128 additions and 3 deletions
+36
View File
@@ -874,6 +874,10 @@ macro_rules! decl_module {
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
) => {
$crate::__check_reserved_fn_name! {
$($fn_name)*
}
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
@@ -1201,6 +1205,38 @@ macro_rules! __function_to_metadata {
}
}
#[macro_export]
#[doc(hidden)]
macro_rules! __check_reserved_fn_name {
(deposit_event $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error deposit_event);
};
(on_initialize $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error on_initialize);
};
(on_initialise $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error on_initialise);
};
(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);
};
(offchain_worker $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!(@compile_error offchain_worker);
};
($t:ident $( $rest:ident )*) => {
$crate::__check_reserved_fn_name!($( $rest )*);
};
() => {};
(@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."));
};
}
#[cfg(test)]
// Do not complain about unused `dispatch` and `dispatch_aux`.
#[allow(dead_code)]