From a0f2e9b3963853e17475617af4b175c6e8d15d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <bkchr@users.noreply.github.com> Date: Sat, 17 Aug 2019 01:14:21 +0200 Subject: [PATCH] Move checks for renamed functions to `__check_reserved_function_names` (#3425) * Move checks for renamed functions to `__check_reserved_function_names` * Fix trybuild test --- substrate/srml/support/src/dispatch.rs | 65 +++++++------------ .../tests/reserved_keyword/on_initialize.rs | 3 +- .../reserved_keyword/on_initialize.stderr | 4 +- 3 files changed, 25 insertions(+), 47 deletions(-) diff --git a/substrate/srml/support/src/dispatch.rs b/substrate/srml/support/src/dispatch.rs index 31237431c0e..d987e5431bb 100644 --- a/substrate/srml/support/src/dispatch.rs +++ b/substrate/srml/support/src/dispatch.rs @@ -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.", + ), + ); }; } diff --git a/substrate/srml/support/test/tests/reserved_keyword/on_initialize.rs b/substrate/srml/support/test/tests/reserved_keyword/on_initialize.rs index f9c2f5f7f0e..1934ae5ea1e 100644 --- a/substrate/srml/support/test/tests/reserved_keyword/on_initialize.rs +++ b/substrate/srml/support/test/tests/reserved_keyword/on_initialize.rs @@ -29,5 +29,4 @@ macro_rules! reserved { reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); -fn main() { -} +fn main() {} diff --git a/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr b/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr index 7a37eb66c32..04adefab3a7 100644 --- a/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr +++ b/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr @@ -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); -- GitLab