//runtime/src/lib.rs
...
parameter_types! {
pub const TombstoneDeposit: Balance = deposit(
1,
<pallet_contracts::Pallet<Runtime>>::contract_info_size()
);
pub const DepositPerContract: Balance = TombstoneDeposit::get();
...
编译时报错:
...
Compiling node-template-runtime v3.0.0 (/home/liucz/SubstratePrivateNetwork/substrate-node-template/runtime)
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> /home/liucz/SubstratePrivateNetwork/substrate-node-template/runtime/src/lib.rs:332:7
|
332 | <pallet_contracts::Pallet<Runtime>>::contract_info_size()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.
error: could not compile `node-template-runtime`
To learn more, run the command again with --verbose.
即:error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
原因:deposit()是const声明的函数,而调用时传参的contract_info_size()不是const声明的函数,所以报错。
犹如在pow
中使用常量:
const N: usize = 3;
const N_CELLS: usize = ((2 * N + 1).pow(2)) - N * (N + 1);
会报错:
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> src/lib.rs:2:24
|
2 | const N_CELLS: usize = ((2 * N + 1).pow(2)) - N * (N + 1);
| ^^^^^^^^^^^^^^^^^^^^
You will have to expand the multiplication yourself:
const N_CELLS: usize = {
let a = 2 * N + 1;
let b = N * (N + 1);
a * a - b
};
How can I guarantee that overflow will not occur in const variables?
Rust 全局静态变量(match、lazy_static! 、phf)
Derived PartialEq cannot be used in a const function #77695
rust的tuple struct