You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with Rust 1.48.0 there is a new const_item_mutation warning, which is triggered many times in this repo. I think the warning is right, and calling any mut metod of a constant like TOTAL is dangerous. I did not look into this in detail, but if global state is required, const need to change to static. However, maybe update should not take a mutable self reference.
warning: taking a mutable reference to a `const` item
--> contracts/cw4-stake/src/contract.rs:184:5
|
184 | / TOTAL.update(storage, |total| -> StdResult<_> {
185 | | Ok(total + new.unwrap_or_default() - old.unwrap_or_default())
186 | | })?;
| |______^
|
= note: `#[warn(const_item_mutation)]` on by default
= note: each usage of a `const` item creates a new temporary
= note: the mutable reference will refer to this temporary, not the original `const` item
note: mutable reference created due to call to this method
--> /projects/CosmWasm/cosmwasm-plus/packages/storage-plus/src/item.rs:64:5
|
64 | / pub fn update<A, E>(&mut self, store: &mut dyn Storage, action: A) -> Result<T, E>
65 | | where
66 | | A: FnOnce(T) -> Result<T, E>,
67 | | E: From<StdError>,
... |
72 | | Ok(output)
73 | | }
| |_____^
note: `const` item defined here
--> contracts/cw4-stake/src/state.rs:24:1
|
24 | pub const TOTAL: Item<u64> = Item::new(TOTAL_KEY);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: 1 warning emitted
The text was updated successfully, but these errors were encountered:
Starting with Rust 1.48.0 there is a new
const_item_mutation
warning, which is triggered many times in this repo. I think the warning is right, and calling any mut metod of aconst
ant likeTOTAL
is dangerous. I did not look into this in detail, but if global state is required,const
need to change tostatic
. However, maybeupdate
should not take a mutableself
reference.The text was updated successfully, but these errors were encountered: