-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Better error for missing index in CRV2 #4643
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,7 +153,7 @@ impl Def { | |
|
|
||
| for item in items.iter_mut() { | ||
| let mut pallet_item = None; | ||
| let mut pallet_index = 0; | ||
| let mut pallet_index = None; | ||
|
|
||
| let mut disable_call = false; | ||
| let mut disable_unsigned = false; | ||
|
|
@@ -170,7 +170,7 @@ impl Def { | |
| runtime_types = Some(types); | ||
| }, | ||
| RuntimeAttr::PalletIndex(span, index) => { | ||
| pallet_index = index; | ||
| pallet_index = Some(index); | ||
| pallet_item = if let syn::Item::Type(item) = item { | ||
| Some(item.clone()) | ||
| } else { | ||
|
|
@@ -187,6 +187,13 @@ impl Def { | |
| } | ||
| } | ||
|
|
||
| if pallet_index.is_none() { | ||
| if let syn::Item::Type(item) = item { | ||
|
||
| let msg = "Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]`"; | ||
| return Err(syn::Error::new(item.span(), &msg)) | ||
| } | ||
| } | ||
|
|
||
| if let Some(pallet_item) = pallet_item { | ||
| match *pallet_item.ty.clone() { | ||
| syn::Type::Path(ref path) => { | ||
|
|
@@ -209,7 +216,9 @@ impl Def { | |
| let pallet = Pallet::try_from( | ||
| item.span(), | ||
| &pallet_item, | ||
| pallet_index, | ||
| pallet_index | ||
| .expect("Pallet item is present only for valid pallet index") | ||
| .into(), | ||
| disable_call, | ||
| disable_unsigned, | ||
| &bounds, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #[frame_support::runtime] | ||
| mod runtime { | ||
| #[runtime::runtime] | ||
| #[runtime::derive(RuntimeCall)] | ||
| pub struct Runtime; | ||
|
|
||
| pub type System = frame_system; | ||
| } | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| error: Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]` | ||
| --> tests/runtime_ui/missing_pallet_index.rs:24:5 | ||
| | | ||
| 24 | pub type System = frame_system; | ||
| | ^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pallet_indexcan be None for all items other than type aliases.