-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl_runtime_apis! {}
: prevent the use of Self
#1890
Comments
hey @kianenigma, I want to work on this. I looked at the source of |
That sounds about correct to me, but I don't know the exact answer either without actually solving the issue, so you should try for yourself :) |
Great, could you please assign this to me :) |
…ment (#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]>
Assuming some type like
type HeaderFor<T>
is in scope, you would expectHeaderFor<Runtime>
andHeaderFor<Self>
would be equivalent, but it is not. I am not sure of the exact reason, but this can be confusing.A simple patch to
impl_runtime_apis
should simply prevent the use ofSelf
in this block of code.The text was updated successfully, but these errors were encountered: