Skip to content
Snippets Groups Projects
Unverified Commit f81751e0 authored by gupnik's avatar gupnik Committed by GitHub
Browse files

Better error for missing index in CRV2 (#4643)


Fixes https://github.com/paritytech/polkadot-sdk/issues/4552

---------

Co-authored-by: command-bot <>
Co-authored-by: default avatarBastian Köcher <info@kchr.de>
parent fc6c3182
No related merge requests found
Pipeline #479833 waiting for manual action with stages
in 1 hour, 20 minutes, and 20 seconds
......@@ -152,8 +152,7 @@ impl Def {
let mut pallets = vec![];
for item in items.iter_mut() {
let mut pallet_item = None;
let mut pallet_index = 0;
let mut pallet_index_and_item = None;
let mut disable_call = false;
let mut disable_unsigned = false;
......@@ -170,9 +169,8 @@ impl Def {
runtime_types = Some(types);
},
RuntimeAttr::PalletIndex(span, index) => {
pallet_index = index;
pallet_item = if let syn::Item::Type(item) = item {
Some(item.clone())
pallet_index_and_item = if let syn::Item::Type(item) = item {
Some((index, item.clone()))
} else {
let msg = "Invalid runtime::pallet_index, expected type definition";
return Err(syn::Error::new(span, msg))
......@@ -187,7 +185,7 @@ impl Def {
}
}
if let Some(pallet_item) = pallet_item {
if let Some((pallet_index, pallet_item)) = pallet_index_and_item {
match *pallet_item.ty.clone() {
syn::Type::Path(ref path) => {
let pallet_decl =
......@@ -230,6 +228,11 @@ impl Def {
},
_ => continue,
}
} else {
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))
}
}
}
......
// 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() {}
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;
| ^^^
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment