sp-api: `impl_runtime_apis!` replace the use of `Self` as a type argument (#4012)
closes #1890 ### Overview Introduces similar checker struct to `CheckTraitDecls` in `decl_runtime_apis!` - `CheckTraitImpls`. Overrides `visit::visit_type_path` to detect usage of `Self` as a type argument within the scope of `impl_runtime_apis!`. **Note**: only prevents the usage of `Self` as a type argument in an angle bracket `<>`, as it is the only use case that fails to compile. For example, the code [below](https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs#L1002) compiles fine: ```rs impl BridgeMessagesConfig<WithBridgeHubRococoMessagesInstance> for Runtime { fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool { let bench_lane_id = <Self as BridgeMessagesConfig<WithBridgeHubRococoMessagesInstance>>::bench_lane_id(); // ... ``` ### Result Given a block of code like this: ```rs impl_runtime_apis! { impl apis::Core<Block> for Runtime { fn initialize_block(header: &HeaderFor<Self>) -> ExtrinsicInclusionMode { let _: HeaderFor<Self> = header.clone(); RuntimeExecutive::initialize_block(header) } // ... } // ... ``` <details open> <summary>Output:</summary> ```bash $ cargo build --release -p minimal-template-node error: `Self` can not be used as type argument in the scope of `impl_runtime_apis!`. Use `Runtime` instead. --> /polkadot-sdk/templates/minimal/runtime/src/lib.rs:133:11 | 133 | let _: HeaderFor<Self> = header.clone(); | ^^^^^^^^^^^^^^^ error: `Self` can not be used as type argument in the scope of `impl_runtime_apis!`. Use `Runtime` instead. --> /polkadot-sdk/templates/minimal/runtime/src/lib.rs:132:32 | 132 | fn initialize_block(header: &HeaderFor<Self>) -> ExtrinsicInclusionMode { ``` </details> --------- Co-authored-by: Pavlo Khrystenko <[email protected]> Co-authored-by: Pavlo Khrystenko <[email protected]> Co-authored-by: Alexandru Vasile <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>