Rust does not have native functions to produce warnings from inside proc macros. This crate provides "deprecated" warnings for your proc macro use-cases.
Building a warning is easy with the builder pattern.
```rust use procmacrowarning::Warning; let warning = Warning::newdeprecated("mymacro") .old("mymacro()") .new("mymacro::new()") .helplink("https:://example.com") .span(procmacro2::Span::call_site()) .build();
// Use the warning in a proc macro let tokens = quote::quote!(#warning); ```
Substrate (not yet, but hopefully soon 😉) uses this to emit warnings for its FRAME eDSL on deprecated behaviour.
For example not putting a call_index
on your functions produces:
``pre
warning: use of deprecated constant
pallet::warnings::ImplicitCallIndex0::w:
It is deprecated to use implicit call indices.
Please instead ensure that all calls have the
pallet::call_indexattribute or that the
dev-mode` of the pallet is enabled.
For more info see:
<https://github.com/paritytech/substrate/pull/12891>
<https://github.com/paritytech/substrate/pull/11381>
--> frame/nomination-pools/src/lib.rs:2621:10
|
2621 | pub fn claimcommission(origin: OriginFor
Or using a hard-coded weight:
``pre
warning: use of deprecated constant
pallet::warnings::ConstantWeight0::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:
<https://github.com/paritytech/substrate/pull/13798>
--> frame/nomination-pools/src/lib.rs:2620:20
|
2620 | #[pallet::weight(0)]
|
```