From b715efe8a55ca0f723700bb1904a13f14a1943f6 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov <39522748+dmitrylavrenov@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:01:06 +0300 Subject: [PATCH] Fix casting `usize` to `u8` at `pallet::error` macro (#91) (#95) (#99) (#102) (#103) Fix casting `usize` to `u8` at `pallet::error` macro (reapplying `3f6bdf2`) (#74) (#80) * Fix casting usize to u8 at pallet::error macro * Edit error message Co-authored-by: MOZGIII --- frame/support/procedural/src/pallet/expand/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/error.rs b/frame/support/procedural/src/pallet/expand/error.rs index 376a6a9f51c6d..1f501b4159ea4 100644 --- a/frame/support/procedural/src/pallet/expand/error.rs +++ b/frame/support/procedural/src/pallet/expand/error.rs @@ -149,11 +149,11 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream { { fn from(err: #error_ident<#type_use_gen>) -> Self { use #frame_support::codec::Encode; - let index = < + let index: u8 = < ::PalletInfo as #frame_support::traits::PalletInfo >::index::>() - .expect("Every active module has an index in the runtime; qed") as u8; + .expect("Every active module has an index in the runtime; qed").try_into().expect("Index should fit into u8"); let mut encoded = err.encode(); encoded.resize(#frame_support::MAX_MODULE_ERROR_ENCODED_SIZE, 0);