mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
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:
committed by
Bastian Köcher
parent
062b734571
commit
57f306a3c1
Generated
+1
@@ -3699,6 +3699,7 @@ dependencies = [
|
||||
"srml-support 2.0.0",
|
||||
"substrate-inherents 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
"trybuild 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -381,7 +381,7 @@ mod tests {
|
||||
let key2 = 18u32;
|
||||
|
||||
DoubleMap::insert(key1, key2, vec![1]);
|
||||
DoubleMap::append(key1, key2, &[2, 3]);
|
||||
DoubleMap::append(key1, key2, &[2, 3]).unwrap();
|
||||
assert_eq!(DoubleMap::get(key1, key2), vec![1, 2, 3]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ mod test_empty_call {
|
||||
pub enum Call {
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub struct Runtime;
|
||||
|
||||
impl_outer_validate_unsigned! {
|
||||
|
||||
@@ -4,13 +4,14 @@ version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dev-dependencies]
|
||||
[dependencies]
|
||||
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
||||
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
|
||||
runtime_io = { package = "sr-io", path = "../../../core/sr-io", default-features = false }
|
||||
srml-support = { path = "../", default-features = false }
|
||||
srml-support = { version = "2", path = "../", default-features = false }
|
||||
inherents = { package = "substrate-inherents", path = "../../../core/inherents", default-features = false }
|
||||
primitives = { package = "substrate-primitives", path = "../../../core/primitives", default-features = false }
|
||||
trybuild = "1"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
|
||||
@@ -16,3 +16,9 @@
|
||||
|
||||
//! Test crate for srml_support. Allow to make use of `srml_support::decl_storage`.
|
||||
//! See tests directory.
|
||||
|
||||
#[test]
|
||||
fn reserved_keyword() {
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/reserved_keyword/*.rs");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
macro_rules! reserved {
|
||||
($($reserved:ident)*) => {
|
||||
$(
|
||||
mod $reserved {
|
||||
pub use srml_support::dispatch::Result;
|
||||
|
||||
pub trait Trait {
|
||||
type Origin;
|
||||
type BlockNumber: Into<u32>;
|
||||
}
|
||||
|
||||
pub mod system {
|
||||
use srml_support::dispatch::Result;
|
||||
|
||||
pub fn ensure_root<R>(_: R) -> Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
srml_support::decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn $reserved() -> Result { unreachable!() }
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
error: Invalid call fn name: `on_finalize`, 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.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= 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_initialize`, 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.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= 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.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= 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.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= 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: `offchain_worker`, 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.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= 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: `deposit_event`, 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.
|
||||
--> $DIR/on_initialize.rs:30:1
|
||||
|
|
||||
30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
Reference in New Issue
Block a user