decl_runtime_apis! - check that a method without changed_in exists (#5635)

* `decl_runtime_apis!` - check that a method without `changed_in` exists

This adds another check to the macro that ensures that not only methods
with `changed_in` exists, but there are also the default methods exist.

* Update primitives/api/proc-macro/src/decl_runtime_apis.rs

Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>

* Fix test

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
Bastian Köcher
2020-04-15 00:02:14 +02:00
committed by GitHub
parent 51f9bb3c0e
commit b267b1728f
4 changed files with 76 additions and 2 deletions
@@ -0,0 +1,19 @@
use sp_runtime::traits::GetNodeBlockType;
use substrate_test_runtime_client::runtime::Block;
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
struct Runtime {}
impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
sp_api::decl_runtime_apis! {
#[api_version(2)]
pub trait Api {
#[changed_in(2)]
fn test(data: u64);
}
}
fn main() {}
@@ -0,0 +1,6 @@
error: There is no 'default' method with this name (without `changed_in` attribute).
The 'default' method is used to call into the latest implementation.
--> $DIR/changed_in_no_default_method.rs:15:6
|
15 | fn test(data: u64);
| ^^^^