break sp-api dependency cycle (#4352)

* move benches into tests, ignore non-passing doctests

* Rename sr-api folder

* Move test-primitives to primitives, use that for sp-api doctests
This commit is contained in:
Benjamin Kampmann
2019-12-10 20:18:01 +01:00
committed by Bastian Köcher
parent f6f0f1cc16
commit 8721d98dd6
71 changed files with 62 additions and 60 deletions
@@ -0,0 +1,7 @@
sp_api::decl_runtime_apis! {
pub trait Api {
fn test(&self);
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `self` as argument not supported.
--> $DIR/adding_self_parameter.rs:3:11
|
3 | fn test(&self);
| ^
@@ -0,0 +1,19 @@
use sp_runtime::traits::GetNodeBlockType;
use test_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! {
pub trait Api {
#[changed_in(2)]
fn test(data: u64);
fn test(data: u64);
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `changed_in` version can not be greater than the `api_version`
--> $DIR/changed_in_unknown_version.rs:14:3
|
14 | fn test(data: u64);
| ^^
@@ -0,0 +1,9 @@
use sp_runtime::traits::Block as BlockT;
sp_api::decl_runtime_apis! {
pub trait Api<Block: BlockT> {
fn test();
}
}
fn main() {}
@@ -0,0 +1,19 @@
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro!
--> $DIR/declaring_old_block.rs:4:16
|
4 | pub trait Api<Block: BlockT> {
| ^^^^^
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
--> $DIR/declaring_old_block.rs:4:23
|
4 | pub trait Api<Block: BlockT> {
| ^^^^^^
warning: unused import: `sp_runtime::traits::Block as BlockT`
--> $DIR/declaring_old_block.rs:1:5
|
1 | use sp_runtime::traits::Block as BlockT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
@@ -0,0 +1,9 @@
use sp_runtime::traits::Block as BlockT;
sp_api::decl_runtime_apis! {
pub trait Api<B: BlockT> {
fn test();
}
}
fn main() {}
@@ -0,0 +1,13 @@
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
--> $DIR/declaring_own_block_with_different_name.rs:4:19
|
4 | pub trait Api<B: BlockT> {
| ^^^^^^
warning: unused import: `sp_runtime::traits::Block as BlockT`
--> $DIR/declaring_own_block_with_different_name.rs:1:5
|
1 | use sp_runtime::traits::Block as BlockT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
@@ -0,0 +1,19 @@
use sp_runtime::traits::GetNodeBlockType;
use test_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! {
pub trait Api {
fn test(data: u64);
}
}
sp_api::impl_runtime_apis! {}
fn main() {}
@@ -0,0 +1,5 @@
error: No api implementation given!
--> $DIR/empty_impl_runtime_apis_call.rs:17:1
|
17 | sp_api::impl_runtime_apis! {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
@@ -0,0 +1,35 @@
use sp_runtime::traits::{GetNodeBlockType, Block as BlockT};
use test_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! {
pub trait Api {
fn test(data: u64);
}
}
sp_api::impl_runtime_apis! {
impl self::Api<Block> for Runtime {
fn test(data: String) {}
}
impl sp_api::Core<Block> for Runtime {
fn version() -> runtime_api::RuntimeVersion {
unimplemented!()
}
fn execute_block(_: Block) {
unimplemented!()
}
fn initialize_block(_: &<Block as BlockT>::Header) {
unimplemented!()
}
}
}
fn main() {}
@@ -0,0 +1,70 @@
error[E0433]: failed to resolve: use of undeclared type or module `runtime_api`
--> $DIR/impl_incorrect_method_signature.rs:23:19
|
23 | fn version() -> runtime_api::RuntimeVersion {
| ^^^^^^^^^^^ use of undeclared type or module `runtime_api`
error[E0053]: method `test` has an incompatible type for trait
--> $DIR/impl_incorrect_method_signature.rs:19:17
|
13 | fn test(data: u64);
| --- type in trait
...
19 | fn test(data: String) {}
| ^^^^^^ expected u64, found struct `std::string::String`
|
= note: expected type `fn(u64)`
found type `fn(std::string::String)`
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
--> $DIR/impl_incorrect_method_signature.rs:17:1
|
11 | / sp_api::decl_runtime_apis! {
12 | | pub trait Api {
13 | | fn test(data: u64);
14 | | }
15 | | }
| |_- type in trait
16 |
17 | sp_api::impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| _expected u64, found struct `std::string::String`
| |
18 | | impl self::Api<Block> for Runtime {
19 | | fn test(data: String) {}
20 | | }
... |
32 | | }
33 | | }
| |_- in this macro invocation
|
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<std::string::String>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:17:1
|
17 | / sp_api::impl_runtime_apis! {
18 | | impl self::Api<Block> for Runtime {
19 | | fn test(data: String) {}
20 | | }
... |
32 | | }
33 | | }
| | ^
| | |
| |_expected u64, found struct `std::string::String`
| in this macro invocation
|
= note: expected type `u64`
found type `std::string::String`
error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:19:11
|
19 | fn test(data: String) {}
| ^^^^ expected u64, found struct `std::string::String`
|
= note: expected type `u64`
found type `std::string::String`
@@ -0,0 +1,37 @@
use sp_runtime::traits::GetNodeBlockType;
use test_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! {
pub trait Api {
fn test(data: u64);
}
}
mod second {
use super::*;
decl_runtime_apis! {
pub trait Api {
fn test2(data: u64);
}
}
}
sp_api::impl_runtime_apis! {
impl self::Api<Block> for Runtime {
fn test(data: u64) {}
}
impl second::Api<Block> for Runtime {
fn test2(data: u64) {}
}
}
fn main() {}
@@ -0,0 +1,77 @@
error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration!
--> $DIR/impl_two_traits_with_same_name.rs:32:15
|
32 | impl second::Api<Block> for Runtime {
| ^^^
error: cannot find macro `decl_runtime_apis` in this scope
--> $DIR/impl_two_traits_with_same_name.rs:20:2
|
20 | decl_runtime_apis! {
| ^^^^^^^^^^^^^^^^^
error[E0425]: cannot find function `test2_call_api_at` in `second::runtime_decl_for_Api`
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
27 | / sp_api::impl_runtime_apis! {
28 | | impl self::Api<Block> for Runtime {
29 | | fn test(data: u64) {}
30 | | }
... |
34 | | }
35 | | }
| | ^
| | |
| |_not found in `second::runtime_decl_for_Api`
| in this macro invocation
error[E0425]: cannot find function `test2_native_call_generator` in `second::runtime_decl_for_Api`
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
27 | / sp_api::impl_runtime_apis! {
28 | | impl self::Api<Block> for Runtime {
29 | | fn test(data: u64) {}
30 | | }
... |
34 | | }
35 | | }
| | ^
| | |
| |_not found in `second::runtime_decl_for_Api`
| in this macro invocation
error[E0576]: cannot find method or associated constant `test2` in `second::runtime_decl_for_Api::Api`
--> $DIR/impl_two_traits_with_same_name.rs:33:6
|
33 | fn test2(data: u64) {}
| ^^^^^ not found in `second::runtime_decl_for_Api::Api`
error[E0603]: module `runtime_decl_for_Api` is private
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
27 | / sp_api::impl_runtime_apis! {
28 | | impl self::Api<Block> for Runtime {
29 | | fn test(data: u64) {}
30 | | }
... |
34 | | }
35 | | }
| |_^
error[E0119]: conflicting implementations of trait `runtime_decl_for_Api::Api<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` for type `Runtime`:
--> $DIR/impl_two_traits_with_same_name.rs:32:2
|
28 | impl self::Api<Block> for Runtime {
| --------------------------------- first implementation here
...
32 | impl second::Api<Block> for Runtime {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Runtime`
error[E0119]: conflicting implementations of trait `Api<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` for type `RuntimeApiImpl<_>`:
--> $DIR/impl_two_traits_with_same_name.rs:32:2
|
28 | impl self::Api<Block> for Runtime {
| --------------------------------- first implementation here
...
32 | impl second::Api<Block> for Runtime {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `RuntimeApiImpl<_>`
@@ -0,0 +1,8 @@
sp_api::decl_runtime_apis! {
#[api_version]
pub trait Api {
fn test(data: u64);
}
}
fn main() {}
@@ -0,0 +1,33 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version.rs:1:1
|
1 | / sp_api::decl_runtime_apis! {
2 | | #[api_version]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version.rs:1:1
|
1 | / sp_api::decl_runtime_apis! {
2 | | #[api_version]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version.rs:2:4
|
2 | #[api_version]
| ^^^^^^^^^^^
@@ -0,0 +1,8 @@
sp_api::decl_runtime_apis! {
#[api_version("1")]
pub trait Api {
fn test(data: u64);
}
}
fn main() {}
@@ -0,0 +1,33 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version_2.rs:1:1
|
1 | / sp_api::decl_runtime_apis! {
2 | | #[api_version("1")]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_2.rs:1:1
|
1 | / sp_api::decl_runtime_apis! {
2 | | #[api_version("1")]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_2.rs:2:4
|
2 | #[api_version("1")]
| ^^^^^^^^^^^
@@ -0,0 +1,8 @@
sp_api::decl_runtime_apis! {
#[api_version()]
pub trait Api {
fn test(data: u64);
}
}
fn main() {}
@@ -0,0 +1,33 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version_3.rs:1:1
|
1 | / sp_api::decl_runtime_apis! {
2 | | #[api_version()]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_3.rs:1:1
|
1 | / sp_api::decl_runtime_apis! {
2 | | #[api_version()]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_3.rs:2:4
|
2 | #[api_version()]
| ^^^^^^^^^^^
@@ -0,0 +1,25 @@
use sp_runtime::traits::GetNodeBlockType;
use test_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! {
pub trait Api {
fn test(data: u64);
}
}
sp_api::impl_runtime_apis! {
impl self::Api for Runtime {
fn test(data: u64) {
unimplemented!()
}
}
}
fn main() {}
@@ -0,0 +1,11 @@
error: Missing `Block` generic parameter.
--> $DIR/missing_block_generic_parameter.rs:18:13
|
18 | impl self::Api for Runtime {
| ^^^
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/missing_block_generic_parameter.rs:18:7
|
18 | impl self::Api for Runtime {
| ^^^^^^^^^ expected 1 type argument
@@ -0,0 +1,25 @@
use sp_runtime::traits::GetNodeBlockType;
use test_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! {
pub trait Api {
fn test(data: u64);
}
}
sp_api::impl_runtime_apis! {
impl Api<Block> for Runtime {
fn test(data: u64) {
unimplemented!()
}
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: The implemented trait has to be referenced with a path, e.g. `impl client::Core for Runtime`.
--> $DIR/missing_path_for_trait.rs:18:7
|
18 | impl Api<Block> for Runtime {
| ^^^
@@ -0,0 +1,37 @@
use sp_runtime::traits::{GetNodeBlockType, Block as BlockT};
use test_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! {
pub trait Api {
fn test(data: u64);
}
}
sp_api::impl_runtime_apis! {
impl self::Api<Block> for Runtime {
fn test(data: &u64) {
unimplemented!()
}
}
impl sp_api::Core<Block> for Runtime {
fn version() -> runtime_api::RuntimeVersion {
unimplemented!()
}
fn execute_block(_: Block) {
unimplemented!()
}
fn initialize_block(_: &<Block as BlockT>::Header) {
unimplemented!()
}
}
}
fn main() {}
@@ -0,0 +1,73 @@
error[E0433]: failed to resolve: use of undeclared type or module `runtime_api`
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:25:19
|
25 | fn version() -> runtime_api::RuntimeVersion {
| ^^^^^^^^^^^ use of undeclared type or module `runtime_api`
error[E0053]: method `test` has an incompatible type for trait
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:17
|
13 | fn test(data: u64);
| --- type in trait
...
19 | fn test(data: &u64) {
| ^^^^ expected u64, found &u64
|
= note: expected type `fn(u64)`
found type `fn(&u64)`
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1
|
11 | / sp_api::decl_runtime_apis! {
12 | | pub trait Api {
13 | | fn test(data: u64);
14 | | }
15 | | }
| |_- type in trait
16 |
17 | sp_api::impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| _expected u64, found &u64
| |
18 | | impl self::Api<Block> for Runtime {
19 | | fn test(data: &u64) {
20 | | unimplemented!()
... |
34 | | }
35 | | }
| |_- in this macro invocation
|
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
error[E0308]: mismatched types
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1
|
17 | / sp_api::impl_runtime_apis! {
18 | | impl self::Api<Block> for Runtime {
19 | | fn test(data: &u64) {
20 | | unimplemented!()
... |
34 | | }
35 | | }
| | ^
| | |
| |_expected u64, found &u64
| in this macro invocation
|
= note: expected type `u64`
found type `&u64`
error[E0308]: mismatched types
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:11
|
19 | fn test(data: &u64) {
| ^^^^^^^
| |
| expected u64, found &u64
| help: consider removing the borrow: `data`
|
= note: expected type `u64`
found type `&u64`