From b1f8d153eb01a5c29691208eeb04cfffdbc85192 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 1 Apr 2023 21:14:29 +0200 Subject: [PATCH 1/7] Use proc-macro-warning crate Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 12 +++++ frame/support/procedural/Cargo.toml | 1 + .../procedural/src/pallet/expand/call.rs | 52 ++++++++++++------- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fd0122f3cc0f..ca55c2ac52668 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2468,6 +2468,7 @@ dependencies = [ "derive-syn-parse", "frame-support-procedural-tools", "itertools", + "proc-macro-warning", "proc-macro2", "quote", "syn", @@ -7511,6 +7512,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-warning" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "163ecdb21ae408b772089d644160051dcf8905eac97a129380c0998847b6853b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.51" diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index ee1ca4dff8873..cd019b4d4e98b 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -23,6 +23,7 @@ proc-macro2 = "1.0.37" quote = "1.0.10" syn = { version = "1.0.98", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } +proc-macro-warning = { version = "0.1.0", default-features = false } [features] default = ["std"] diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 0fdf4455ae7d0..0711d40f889b3 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -54,30 +54,45 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { .map(|fn_name| format!("Create a call with the variant `{}`.", fn_name)) .collect::>(); - let mut warning_structs = Vec::new(); - let mut warning_names = Vec::new(); + let mut call_index_warnings = Vec::new(); // Emit a warning for each call that is missing `call_index` when not in dev-mode. for method in &methods { if method.explicit_call_index || def.dev_mode { continue } - let name = syn::Ident::new(&format!("{}", method.name), method.name.span()); - let warning: syn::ItemStruct = syn::parse_quote!( - #[deprecated(note = r" - Implicit call indices are deprecated in favour of explicit ones. - Please ensure that all calls have the `pallet::call_index` attribute or that the - `dev-mode` of the pallet is enabled. For more info see: - and - .")] - #[allow(non_camel_case_types)] - struct #name; - ); - warning_names.push(name); - warning_structs.push(warning); + let warning = proc_macro_warning::Warning::new_deprecated("ImplicitCallIndex") + .old("use implicit call indices") + .alternative("ensure that all calls have the `pallet::call_index` attribute or that the `dev-mode` of the pallet is enabled") + .help_links(&[ + "https://github.com/paritytech/substrate/pull/12891", + "https://github.com/paritytech/substrate/pull/11381" + ]) + .span(method.name.span()) + .build(); + call_index_warnings.push(warning); } let fn_weight = methods.iter().map(|method| &method.weight); + let mut weight_warnings = Vec::new(); + for weight in fn_weight.clone() { + if def.dev_mode { + continue + } + + match weight { + syn::Expr::Lit(lit) => { + let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight") + .old("use hard-coded constant as call weight") + .alternative("benchmark all calls or put the pallet into `dev` mode") + .help_link("TODO") + .span(lit.span()) + .build(); + weight_warnings.push(warning); + }, + _ => {}, + } + } let fn_doc = methods.iter().map(|method| &method.docs).collect::>(); @@ -203,9 +218,10 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { quote::quote_spanned!(span => mod warnings { #( - #warning_structs - // This triggers each deprecated warning once. - const _: Option<#warning_names> = None; + #call_index_warnings + )* + #( + #weight_warnings )* } From dd334a4116bf03dc36256eb2145c84d2f6ed3f3a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 3 Apr 2023 15:17:05 +0200 Subject: [PATCH 2/7] Fixup Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 4 ++-- frame/support/procedural/Cargo.toml | 2 +- frame/support/procedural/src/pallet/expand/call.rs | 4 +++- frame/support/test/tests/pallet.rs | 8 ++++---- frame/support/test/tests/pallet_instance.rs | 2 +- frame/support/test/tests/storage_layers.rs | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca55c2ac52668..db53fda94fba8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7514,9 +7514,9 @@ dependencies = [ [[package]] name = "proc-macro-warning" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "163ecdb21ae408b772089d644160051dcf8905eac97a129380c0998847b6853b" +checksum = "02947afd04953718e1b5ac72bd4237ec7305aec959b68763f3fbce61e0113ec4" dependencies = [ "proc-macro2", "quote", diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index cd019b4d4e98b..2886440ea08b6 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -23,7 +23,7 @@ proc-macro2 = "1.0.37" quote = "1.0.10" syn = { version = "1.0.98", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } -proc-macro-warning = { version = "0.1.0", default-features = false } +proc-macro-warning = { version = "0.1.2", default-features = false } [features] default = ["std"] diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 0711d40f889b3..99bed2ee331ff 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -62,6 +62,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { } let warning = proc_macro_warning::Warning::new_deprecated("ImplicitCallIndex") + .index(call_index_warnings.len()) .old("use implicit call indices") .alternative("ensure that all calls have the `pallet::call_index` attribute or that the `dev-mode` of the pallet is enabled") .help_links(&[ @@ -83,9 +84,10 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { match weight { syn::Expr::Lit(lit) => { let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight") + .index(weight_warnings.len()) .old("use hard-coded constant as call weight") .alternative("benchmark all calls or put the pallet into `dev` mode") - .help_link("TODO") + .help_link("https://github.com/paritytech/substrate/pull/13798") .span(lit.span()) .build(); weight_warnings.push(warning); diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 52acdc5c26e03..1a367c8b379f0 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -218,7 +218,7 @@ pub mod pallet { /// Doc comment put in metadata #[pallet::call_index(1)] - #[pallet::weight(1)] + #[pallet::weight({1})] pub fn foo_storage_layer( _origin: OriginFor, #[pallet::compact] foo: u32, @@ -232,20 +232,20 @@ pub mod pallet { } #[pallet::call_index(4)] - #[pallet::weight(1)] + #[pallet::weight({1})] pub fn foo_index_out_of_order(_origin: OriginFor) -> DispatchResult { Ok(()) } // Test for DispatchResult return type #[pallet::call_index(2)] - #[pallet::weight(1)] + #[pallet::weight({1})] pub fn foo_no_post_info(_origin: OriginFor) -> DispatchResult { Ok(()) } #[pallet::call_index(3)] - #[pallet::weight(1)] + #[pallet::weight({1})] pub fn check_for_dispatch_context(_origin: OriginFor) -> DispatchResult { with_context::<(), _>(|_| ()).ok_or_else(|| DispatchError::Unavailable) } diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 517f920c5ce07..241492a596993 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -27,7 +27,7 @@ use sp_io::{ }; use sp_runtime::{DispatchError, ModuleError}; -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] pub mod pallet { use codec::MaxEncodedLen; use frame_support::{pallet_prelude::*, parameter_types, scale_info}; diff --git a/frame/support/test/tests/storage_layers.rs b/frame/support/test/tests/storage_layers.rs index f124aed9aa561..82174bf9d7141 100644 --- a/frame/support/test/tests/storage_layers.rs +++ b/frame/support/test/tests/storage_layers.rs @@ -22,7 +22,7 @@ use frame_support::{ use pallet::*; use sp_io::TestExternalities; -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] pub mod pallet { use frame_support::{ensure, pallet_prelude::*}; use frame_system::pallet_prelude::*; From f4611e2d94c5f4102417f1c1afbf3e1042d28f7b Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 3 Apr 2023 17:38:54 +0200 Subject: [PATCH 3/7] Fix pallet_ui tests Also renamed some of the odd-named ones. Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 2 - frame/support/procedural/Cargo.toml | 2 +- .../procedural/src/pallet/expand/call.rs | 4 +- .../call_argument_invalid_bound.stderr | 13 +++++ .../call_argument_invalid_bound_2.stderr | 13 +++++ .../call_argument_invalid_bound_3.stderr | 13 +++++ .../tests/pallet_ui/call_missing_index.rs | 5 ++ .../tests/pallet_ui/call_missing_index.stderr | 47 ++++++++++++++++--- ....rs => call_weight_argument_has_suffix.rs} | 4 +- .../call_weight_argument_has_suffix.stderr | 20 ++++++++ .../pallet_ui/call_weight_const_warning.rs | 21 +++++++++ .../call_weight_const_warning.stderr | 12 +++++ .../call_weight_const_warning_twice.rs | 25 ++++++++++ .../call_weight_const_warning_twice.stderr | 31 ++++++++++++ ...ev_mode_without_arg_max_encoded_len.stderr | 24 +++++++--- .../weight_argument_has_suffix.stderr | 7 --- 16 files changed, 217 insertions(+), 26 deletions(-) rename frame/support/test/tests/pallet_ui/{weight_argument_has_suffix.rs => call_weight_argument_has_suffix.rs} (70%) create mode 100644 frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.stderr create mode 100644 frame/support/test/tests/pallet_ui/call_weight_const_warning.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_const_warning.stderr create mode 100644 frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.stderr delete mode 100644 frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr diff --git a/Cargo.lock b/Cargo.lock index db53fda94fba8..dc0c355595140 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7515,8 +7515,6 @@ dependencies = [ [[package]] name = "proc-macro-warning" version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02947afd04953718e1b5ac72bd4237ec7305aec959b68763f3fbce61e0113ec4" dependencies = [ "proc-macro2", "quote", diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index 2886440ea08b6..58da1cc8dccd7 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -23,7 +23,7 @@ proc-macro2 = "1.0.37" quote = "1.0.10" syn = { version = "1.0.98", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } -proc-macro-warning = { version = "0.1.2", default-features = false } +proc-macro-warning = { version = "0.1.2", path = "../../../../proc-macro-warning", default-features = false } [features] default = ["std"] diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 99bed2ee331ff..74075848d9e9b 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -64,7 +64,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { let warning = proc_macro_warning::Warning::new_deprecated("ImplicitCallIndex") .index(call_index_warnings.len()) .old("use implicit call indices") - .alternative("ensure that all calls have the `pallet::call_index` attribute or that the `dev-mode` of the pallet is enabled") + .new("ensure that all calls have a `pallet::call_index` attribute or put the pallet into `dev` mode") .help_links(&[ "https://github.com/paritytech/substrate/pull/12891", "https://github.com/paritytech/substrate/pull/11381" @@ -86,7 +86,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight") .index(weight_warnings.len()) .old("use hard-coded constant as call weight") - .alternative("benchmark all calls or put the pallet into `dev` mode") + .new("benchmark all calls or put the pallet into `dev` mode") .help_link("https://github.com/paritytech/substrate/pull/13798") .span(lit.span()) .build(); diff --git a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr index aed53b07b5e63..d10bf1359019a 100644 --- a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr +++ b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr @@ -1,3 +1,16 @@ +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_argument_invalid_bound.rs:19:20 + | +19 | #[pallet::weight(0)] + | ^ + | + = note: `-D deprecated` implied by `-D warnings` + error[E0277]: `::Bar` doesn't implement `std::fmt::Debug` --> tests/pallet_ui/call_argument_invalid_bound.rs:21:36 | diff --git a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr index 476258c03becd..7173cdcd47361 100644 --- a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr +++ b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr @@ -1,3 +1,16 @@ +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_argument_invalid_bound_2.rs:19:20 + | +19 | #[pallet::weight(0)] + | ^ + | + = note: `-D deprecated` implied by `-D warnings` + error[E0277]: `::Bar` doesn't implement `std::fmt::Debug` --> tests/pallet_ui/call_argument_invalid_bound_2.rs:21:36 | diff --git a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr index 395da09cb0d6d..1b084dd2f76bc 100644 --- a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr +++ b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr @@ -1,3 +1,16 @@ +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_argument_invalid_bound_3.rs:21:20 + | +21 | #[pallet::weight(0)] + | ^ + | + = note: `-D deprecated` implied by `-D warnings` + error[E0277]: `Bar` doesn't implement `std::fmt::Debug` --> tests/pallet_ui/call_argument_invalid_bound_3.rs:23:36 | diff --git a/frame/support/test/tests/pallet_ui/call_missing_index.rs b/frame/support/test/tests/pallet_ui/call_missing_index.rs index 7e305a573d622..98c49f493e50d 100644 --- a/frame/support/test/tests/pallet_ui/call_missing_index.rs +++ b/frame/support/test/tests/pallet_ui/call_missing_index.rs @@ -15,6 +15,11 @@ mod pallet { pub fn foo(_: OriginFor) -> DispatchResult { Ok(()) } + + #[pallet::weight(0)] + pub fn bar(_: OriginFor) -> DispatchResult { + Ok(()) + } } } diff --git a/frame/support/test/tests/pallet_ui/call_missing_index.stderr b/frame/support/test/tests/pallet_ui/call_missing_index.stderr index 9d00204979211..82dbe1d24c28e 100644 --- a/frame/support/test/tests/pallet_ui/call_missing_index.stderr +++ b/frame/support/test/tests/pallet_ui/call_missing_index.stderr @@ -1,12 +1,47 @@ -error: use of deprecated struct `pallet::warnings::foo`: - Implicit call indices are deprecated in favour of explicit ones. - Please ensure that all calls have the `pallet::call_index` attribute or that the - `dev-mode` of the pallet is enabled. For more info see: - and - . +error: use of deprecated constant `pallet::warnings::ImplicitCallIndex_0::_w`: + It is deprecated to use implicit call indices. + Please instead ensure that all calls have a `pallet::call_index` attribute or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_missing_index.rs:15:10 | 15 | pub fn foo(_: OriginFor) -> DispatchResult { | ^^^ | = note: `-D deprecated` implied by `-D warnings` + +error: use of deprecated constant `pallet::warnings::ImplicitCallIndex_1::_w`: + It is deprecated to use implicit call indices. + Please instead ensure that all calls have a `pallet::call_index` attribute or put the pallet into `dev` mode. + + For more info see: + + + --> tests/pallet_ui/call_missing_index.rs:20:10 + | +20 | pub fn bar(_: OriginFor) -> DispatchResult { + | ^^^ + +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_missing_index.rs:14:20 + | +14 | #[pallet::weight(0)] + | ^ + +error: use of deprecated constant `pallet::warnings::ConstantWeight_1::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_missing_index.rs:19:20 + | +19 | #[pallet::weight(0)] + | ^ diff --git a/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.rs b/frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.rs similarity index 70% rename from frame/support/test/tests/pallet_ui/weight_argument_has_suffix.rs rename to frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.rs index 99195d21be62e..c122877e8a075 100644 --- a/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.rs @@ -1,6 +1,6 @@ #[frame_support::pallet] mod pallet { - use frame_support::pallet_prelude::DispatchResultWithPostInfo; + use frame_support::pallet_prelude::DispatchResult; use frame_system::pallet_prelude::OriginFor; #[pallet::config] @@ -13,7 +13,7 @@ mod pallet { impl Pallet { #[pallet::call_index(0)] #[pallet::weight(10_000something)] - pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo { Ok(().into()) } + pub fn foo(_: OriginFor) -> DispatchResult { Ok(()) } } } diff --git a/frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.stderr b/frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.stderr new file mode 100644 index 0000000000000..0651f003b9e23 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_argument_has_suffix.stderr @@ -0,0 +1,20 @@ +error: invalid suffix `something` for number literal + --> tests/pallet_ui/call_weight_argument_has_suffix.rs:15:26 + | +15 | #[pallet::weight(10_000something)] + | ^^^^^^^^^^^^^^^ invalid suffix `something` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_weight_argument_has_suffix.rs:15:26 + | +15 | #[pallet::weight(10_000something)] + | ^^^^^^^^^^^^^^^ + | + = note: `-D deprecated` implied by `-D warnings` diff --git a/frame/support/test/tests/pallet_ui/call_weight_const_warning.rs b/frame/support/test/tests/pallet_ui/call_weight_const_warning.rs new file mode 100644 index 0000000000000..2e5dc2a649e70 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_const_warning.rs @@ -0,0 +1,21 @@ +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(123_u64)] + pub fn foo(_: OriginFor) -> DispatchResult { Ok(()) } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_const_warning.stderr b/frame/support/test/tests/pallet_ui/call_weight_const_warning.stderr new file mode 100644 index 0000000000000..b04c3ec395ce6 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_const_warning.stderr @@ -0,0 +1,12 @@ +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_weight_const_warning.rs:15:26 + | +15 | #[pallet::weight(123_u64)] + | ^^^^^^^ + | + = note: `-D deprecated` implied by `-D warnings` diff --git a/frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.rs b/frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.rs new file mode 100644 index 0000000000000..798911dba33d9 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.rs @@ -0,0 +1,25 @@ +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(123)] + pub fn foo(_: OriginFor) -> DispatchResult { Ok(()) } + + #[pallet::call_index(1)] + #[pallet::weight(123_custom_prefix)] + pub fn bar(_: OriginFor) -> DispatchResult { Ok(()) } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.stderr b/frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.stderr new file mode 100644 index 0000000000000..c656790207504 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_const_warning_twice.stderr @@ -0,0 +1,31 @@ +error: invalid suffix `custom_prefix` for number literal + --> tests/pallet_ui/call_weight_const_warning_twice.rs:19:26 + | +19 | #[pallet::weight(123_custom_prefix)] + | ^^^^^^^^^^^^^^^^^ invalid suffix `custom_prefix` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_weight_const_warning_twice.rs:15:26 + | +15 | #[pallet::weight(123)] + | ^^^ + | + = note: `-D deprecated` implied by `-D warnings` + +error: use of deprecated constant `pallet::warnings::ConstantWeight_1::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/call_weight_const_warning_twice.rs:19:26 + | +19 | #[pallet::weight(123_custom_prefix)] + | ^^^^^^^^^^^^^^^^^ diff --git a/frame/support/test/tests/pallet_ui/dev_mode_without_arg_max_encoded_len.stderr b/frame/support/test/tests/pallet_ui/dev_mode_without_arg_max_encoded_len.stderr index c9de991135082..cf502ac5be475 100644 --- a/frame/support/test/tests/pallet_ui/dev_mode_without_arg_max_encoded_len.stderr +++ b/frame/support/test/tests/pallet_ui/dev_mode_without_arg_max_encoded_len.stderr @@ -1,9 +1,10 @@ -error: use of deprecated struct `pallet::warnings::my_call`: - Implicit call indices are deprecated in favour of explicit ones. - Please ensure that all calls have the `pallet::call_index` attribute or that the - `dev-mode` of the pallet is enabled. For more info see: - and - . +error: use of deprecated constant `pallet::warnings::ImplicitCallIndex_0::_w`: + It is deprecated to use implicit call indices. + Please instead ensure that all calls have a `pallet::call_index` attribute or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs:25:10 | 25 | pub fn my_call(_origin: OriginFor) -> DispatchResult { @@ -11,6 +12,17 @@ error: use of deprecated struct `pallet::warnings::my_call`: | = note: `-D deprecated` implied by `-D warnings` +error: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: + It is deprecated to use hard-coded constant as call weight. + Please instead benchmark all calls or put the pallet into `dev` mode. + + For more info see: + + --> tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs:24:20 + | +24 | #[pallet::weight(0)] + | ^ + error[E0277]: the trait bound `Vec: MaxEncodedLen` is not satisfied --> tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs:11:12 | diff --git a/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr b/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr deleted file mode 100644 index df9b0798ab93d..0000000000000 --- a/frame/support/test/tests/pallet_ui/weight_argument_has_suffix.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error: invalid suffix `something` for number literal - --> tests/pallet_ui/weight_argument_has_suffix.rs:15:26 - | -15 | #[pallet::weight(10_000something)] - | ^^^^^^^^^^^^^^^ invalid suffix `something` - | - = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) From b46281fe4746cbffae443581537e161cb6beb208 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 3 Apr 2023 17:49:00 +0200 Subject: [PATCH 4/7] Update dep Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 4 +++- frame/support/procedural/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc0c355595140..3e93adf3f96f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7514,7 +7514,9 @@ dependencies = [ [[package]] name = "proc-macro-warning" -version = "0.1.2" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d4f284d87b9cedc2ff57223cbc4e3937cd6063c01e92c8e2a8c080df0013933" dependencies = [ "proc-macro2", "quote", diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index 58da1cc8dccd7..6dbdd3b3a594d 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -23,7 +23,7 @@ proc-macro2 = "1.0.37" quote = "1.0.10" syn = { version = "1.0.98", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } -proc-macro-warning = { version = "0.1.2", path = "../../../../proc-macro-warning", default-features = false } +proc-macro-warning = { version = "0.2.0", default-features = false } [features] default = ["std"] From a6791febd9518779784bb574893c17fc4625eaea Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 3 Apr 2023 18:09:50 +0200 Subject: [PATCH 5/7] Ignore hardcoded weight warning To be fixed in https://github.com/paritytech/substrate/issues/13813 Signed-off-by: Oliver Tale-Yazdi --- frame/benchmarking/pov/src/lib.rs | 4 ++-- frame/benchmarking/src/tests.rs | 2 +- frame/benchmarking/src/tests_instance.rs | 4 ++-- frame/examples/offchain-worker/src/lib.rs | 6 +++--- frame/membership/src/lib.rs | 14 +++++++------- frame/nicks/src/lib.rs | 8 ++++---- frame/scored-pool/src/lib.rs | 12 ++++++------ frame/sudo/src/lib.rs | 2 +- frame/utility/src/tests.rs | 4 ++-- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/frame/benchmarking/pov/src/lib.rs b/frame/benchmarking/pov/src/lib.rs index dccfe72d3f243..66000e54151b0 100644 --- a/frame/benchmarking/pov/src/lib.rs +++ b/frame/benchmarking/pov/src/lib.rs @@ -120,14 +120,14 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn emit_event(_origin: OriginFor) -> DispatchResult { Self::deposit_event(Event::TestEvent); Ok(()) } #[pallet::call_index(1)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn noop(_origin: OriginFor) -> DispatchResult { Ok(()) } diff --git a/frame/benchmarking/src/tests.rs b/frame/benchmarking/src/tests.rs index 453e8e125cbb3..80b631bb73668 100644 --- a/frame/benchmarking/src/tests.rs +++ b/frame/benchmarking/src/tests.rs @@ -29,7 +29,7 @@ use sp_runtime::{ use sp_std::prelude::*; use std::cell::RefCell; -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] mod pallet_test { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; diff --git a/frame/benchmarking/src/tests_instance.rs b/frame/benchmarking/src/tests_instance.rs index d49d7cc817c6b..92d78b9ecbbe1 100644 --- a/frame/benchmarking/src/tests_instance.rs +++ b/frame/benchmarking/src/tests_instance.rs @@ -61,7 +61,7 @@ mod pallet_test { ::OtherEvent: Into<>::RuntimeEvent>, { #[pallet::call_index(0)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn set_value(origin: OriginFor, n: u32) -> DispatchResult { let _sender = ensure_signed(origin)?; Value::::put(n); @@ -69,7 +69,7 @@ mod pallet_test { } #[pallet::call_index(1)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn dummy(origin: OriginFor, _n: u32) -> DispatchResult { let _sender = ensure_none(origin)?; Ok(()) diff --git a/frame/examples/offchain-worker/src/lib.rs b/frame/examples/offchain-worker/src/lib.rs index 1a63955c04741..6ce8524174200 100644 --- a/frame/examples/offchain-worker/src/lib.rs +++ b/frame/examples/offchain-worker/src/lib.rs @@ -229,7 +229,7 @@ pub mod pallet { /// This example is not focused on correctness of the oracle itself, but rather its /// purpose is to showcase offchain worker capabilities. #[pallet::call_index(0)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn submit_price(origin: OriginFor, price: u32) -> DispatchResultWithPostInfo { // Retrieve sender of the transaction. let who = ensure_signed(origin)?; @@ -255,7 +255,7 @@ pub mod pallet { /// This example is not focused on correctness of the oracle itself, but rather its /// purpose is to showcase offchain worker capabilities. #[pallet::call_index(1)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn submit_price_unsigned( origin: OriginFor, _block_number: T::BlockNumber, @@ -272,7 +272,7 @@ pub mod pallet { } #[pallet::call_index(2)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn submit_price_unsigned_with_signed_payload( origin: OriginFor, price_payload: PricePayload, diff --git a/frame/membership/src/lib.rs b/frame/membership/src/lib.rs index 0be33a95613fe..e703b88f3657e 100644 --- a/frame/membership/src/lib.rs +++ b/frame/membership/src/lib.rs @@ -168,7 +168,7 @@ pub mod pallet { /// /// May only be called from `T::AddOrigin`. #[pallet::call_index(0)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn add_member(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { T::AddOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; @@ -191,7 +191,7 @@ pub mod pallet { /// /// May only be called from `T::RemoveOrigin`. #[pallet::call_index(1)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn remove_member(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { T::RemoveOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; @@ -215,7 +215,7 @@ pub mod pallet { /// /// Prime membership is *not* passed from `remove` to `add`, if extant. #[pallet::call_index(2)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn swap_member( origin: OriginFor, remove: AccountIdLookupOf, @@ -249,7 +249,7 @@ pub mod pallet { /// /// May only be called from `T::ResetOrigin`. #[pallet::call_index(3)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn reset_members(origin: OriginFor, members: Vec) -> DispatchResult { T::ResetOrigin::ensure_origin(origin)?; @@ -272,7 +272,7 @@ pub mod pallet { /// /// Prime membership is passed from the origin account to `new`, if extant. #[pallet::call_index(4)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn change_key(origin: OriginFor, new: AccountIdLookupOf) -> DispatchResult { let remove = ensure_signed(origin)?; let new = T::Lookup::lookup(new)?; @@ -307,7 +307,7 @@ pub mod pallet { /// /// May only be called from `T::PrimeOrigin`. #[pallet::call_index(5)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn set_prime(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { T::PrimeOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; @@ -321,7 +321,7 @@ pub mod pallet { /// /// May only be called from `T::PrimeOrigin`. #[pallet::call_index(6)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn clear_prime(origin: OriginFor) -> DispatchResult { T::PrimeOrigin::ensure_origin(origin)?; Prime::::kill(); diff --git a/frame/nicks/src/lib.rs b/frame/nicks/src/lib.rs index 5f510ce8e4cc0..92865c773d886 100644 --- a/frame/nicks/src/lib.rs +++ b/frame/nicks/src/lib.rs @@ -131,7 +131,7 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(0)] - #[pallet::weight(50_000_000)] + #[pallet::weight({50_000_000})] pub fn set_name(origin: OriginFor, name: Vec) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -160,7 +160,7 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(1)] - #[pallet::weight(70_000_000)] + #[pallet::weight({70_000_000})] pub fn clear_name(origin: OriginFor) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -183,7 +183,7 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(2)] - #[pallet::weight(70_000_000)] + #[pallet::weight({70_000_000})] pub fn kill_name(origin: OriginFor, target: AccountIdLookupOf) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; @@ -207,7 +207,7 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(3)] - #[pallet::weight(70_000_000)] + #[pallet::weight({70_000_000})] pub fn force_name( origin: OriginFor, target: AccountIdLookupOf, diff --git a/frame/scored-pool/src/lib.rs b/frame/scored-pool/src/lib.rs index 336a69a798477..8bd44e2ffac8a 100644 --- a/frame/scored-pool/src/lib.rs +++ b/frame/scored-pool/src/lib.rs @@ -70,7 +70,7 @@ //! //! #[pallet::call] //! impl Pallet { -//! #[pallet::weight(0)] +//! #[pallet::weight({0})] //! pub fn candidate(origin: OriginFor) -> DispatchResult { //! let who = ensure_signed(origin)?; //! @@ -311,7 +311,7 @@ pub mod pallet { /// The `index` parameter of this function must be set to /// the index of the transactor in the `Pool`. #[pallet::call_index(0)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn submit_candidacy(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(!>::contains_key(&who), Error::::AlreadyInPool); @@ -341,7 +341,7 @@ pub mod pallet { /// The `index` parameter of this function must be set to /// the index of the transactor in the `Pool`. #[pallet::call_index(1)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn withdraw_candidacy(origin: OriginFor, index: u32) -> DispatchResult { let who = ensure_signed(origin)?; @@ -360,7 +360,7 @@ pub mod pallet { /// The `index` parameter of this function must be set to /// the index of `dest` in the `Pool`. #[pallet::call_index(2)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn kick( origin: OriginFor, dest: AccountIdLookupOf, @@ -385,7 +385,7 @@ pub mod pallet { /// The `index` parameter of this function must be set to /// the index of the `dest` in the `Pool`. #[pallet::call_index(3)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn score( origin: OriginFor, dest: AccountIdLookupOf, @@ -425,7 +425,7 @@ pub mod pallet { /// /// May only be called from root. #[pallet::call_index(4)] - #[pallet::weight(0)] + #[pallet::weight({0})] pub fn change_member_count(origin: OriginFor, count: u32) -> DispatchResult { ensure_root(origin)?; Self::update_member_count(count).map_err(Into::into) diff --git a/frame/sudo/src/lib.rs b/frame/sudo/src/lib.rs index 47309833a0681..1bc206e0063e4 100644 --- a/frame/sudo/src/lib.rs +++ b/frame/sudo/src/lib.rs @@ -195,7 +195,7 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(2)] - #[pallet::weight(0)] + #[pallet::weight({0})] // FIXME pub fn set_key( origin: OriginFor, new: AccountIdLookupOf, diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 04f2728242874..d23c57e69bec5 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -41,7 +41,7 @@ use sp_runtime::{ type BlockNumber = u64; // example module to test behaviors. -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] pub mod example { use frame_support::{dispatch::WithPostDispatchInfo, pallet_prelude::*}; use frame_system::pallet_prelude::*; @@ -91,7 +91,7 @@ pub mod example { mod mock_democracy { pub use pallet::*; - #[frame_support::pallet] + #[frame_support::pallet(dev_mode)] pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; From 682a8fe2d4de67418b6650143fadb66b4d652672 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 3 Apr 2023 19:31:29 +0200 Subject: [PATCH 6/7] Fix test pallet Signed-off-by: Oliver Tale-Yazdi --- frame/collective/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/collective/src/tests.rs b/frame/collective/src/tests.rs index 79f6cc27fadbd..2550ab3ed2017 100644 --- a/frame/collective/src/tests.rs +++ b/frame/collective/src/tests.rs @@ -51,7 +51,7 @@ frame_support::construct_runtime!( mod mock_democracy { pub use pallet::*; - #[frame_support::pallet] + #[frame_support::pallet(dev_mode)] pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; From 4c2e35fdcf8935b45ecf938b6a912ad7b2095654 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 3 Apr 2023 20:34:06 +0200 Subject: [PATCH 7/7] Fix more tests Signed-off-by: Oliver Tale-Yazdi --- frame/executive/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 5003920eadcb5..ba4155446261c 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -700,7 +700,7 @@ mod tests { const TEST_KEY: &[u8] = b":test:key:"; - #[frame_support::pallet] + #[frame_support::pallet(dev_mode)] mod custom { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*;