diff --git a/account/api/src/provider.rs b/account/api/src/provider.rs index d8ef109af2..7a23210f12 100644 --- a/account/api/src/provider.rs +++ b/account/api/src/provider.rs @@ -5,8 +5,7 @@ use starcoin_types::account_config::token_code::TokenCode; use starcoin_types::sign_message::{SignedMessage, SigningMessage}; use starcoin_types::transaction::{RawUserTransaction, SignedUserTransaction}; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum AccountProviderStrategy { #[default] RPC, @@ -14,7 +13,6 @@ pub enum AccountProviderStrategy { PrivateKey, } - pub trait AccountProvider { fn create_account(&self, password: String) -> Result; diff --git a/account/src/account_test.rs b/account/src/account_test.rs index bba50ab6cb..705f421f48 100644 --- a/account/src/account_test.rs +++ b/account/src/account_test.rs @@ -187,7 +187,7 @@ pub fn test_wallet_account() -> Result<()> { let hash_value = HashValue::sha3_256_of(&public_key.to_bytes()); let key = AuthenticationKey::new(*HashValue::sha3_256_of(&public_key.to_bytes()).as_ref()); - let sign = vec![ + let sign = [ 227, 94, 250, 168, 43, 200, 137, 74, 61, 254, 197, 71, 245, 135, 201, 43, 222, 190, 56, 235, 247, 254, 56, 247, 108, 36, 250, 192, 143, 236, 101, 153, 61, 241, 129, 47, 38, 146, 213, 9, 79, 56, 90, 210, 179, 53, 73, 208, 248, 231, 22, 9, 55, 177, 154, 212, 248, 2, 66, diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 9fb712053a..6dac2047a4 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -1284,7 +1284,9 @@ impl BlockChain { let pre_total_difficulty = parent_status .map(|status| status.total_difficulty()) .unwrap_or_default(); - let total_difficulty = pre_total_difficulty + header.difficulty(); + let total_difficulty = pre_total_difficulty + .checked_add(header.difficulty()) + .ok_or(format_err!("failed to calculate total difficulty"))?; block_accumulator.append(&[block_id])?; let txn_accumulator_info: AccumulatorInfo = txn_accumulator.get_info(); diff --git a/chain/tests/test_txn_info_and_proof.rs b/chain/tests/test_txn_info_and_proof.rs index d817366953..749d64d622 100644 --- a/chain/tests/test_txn_info_and_proof.rs +++ b/chain/tests/test_txn_info_and_proof.rs @@ -34,7 +34,7 @@ fn test_transaction_info_and_proof() -> Result<()> { //put the genesis txn, the genesis block metadata txn do not generate txn info all_txns.push(Transaction::UserTransaction( - genesis_block.body.transactions.get(0).cloned().unwrap(), + genesis_block.body.transactions.first().cloned().unwrap(), )); (0..block_count).for_each(|_block_idx| { diff --git a/cmd/db-exporter/src/main.rs b/cmd/db-exporter/src/main.rs index 5b0aced7c6..c392c0b6bc 100644 --- a/cmd/db-exporter/src/main.rs +++ b/cmd/db-exporter/src/main.rs @@ -862,7 +862,7 @@ pub fn apply_block( } if let Some(last_block) = blocks.last() { - let start = blocks.get(0).unwrap().header().number(); + let start = blocks.first().unwrap().header().number(); let end = last_block.header().number(); println!( "current number {}, import [{},{}] block number", @@ -2138,7 +2138,7 @@ pub fn apply_turbo_stm_block( } if let Some(last_block) = blocks.last() { - let start = blocks.get(0).unwrap().header().number(); + let start = blocks.first().unwrap().header().number(); let end = last_block.header().number(); println!( "current number {}, import [{},{}] block number", diff --git a/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs b/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs index 1326356e2c..f4de302deb 100644 --- a/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs +++ b/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs @@ -146,11 +146,8 @@ impl CommandAction for GenerateMultisigTxnCommand { unreachable!() }; let mut raw_txn_view: RawUserTransactionView = raw_txn.clone().try_into()?; - raw_txn_view.decoded_payload = Some( - ctx.state() - .decode_txn_payload(raw_txn.payload())? - .try_into()?, - ); + raw_txn_view.decoded_payload = + Some(ctx.state().decode_txn_payload(raw_txn.payload())?.into()); // Use `eprintln` instead of `println`, for keep the cli stdout's format(such as json) is not broken by print. eprintln!( "Prepare to sign the transaction: \n {}", diff --git a/cmd/starcoin/src/cli_state.rs b/cmd/starcoin/src/cli_state.rs index 6b5d8b2a71..47a75af33f 100644 --- a/cmd/starcoin/src/cli_state.rs +++ b/cmd/starcoin/src/cli_state.rs @@ -287,8 +287,7 @@ impl CliState { raw_txn: raw_txn.clone(), })?; let mut raw_txn_view: RawUserTransactionView = raw_txn.clone().try_into()?; - raw_txn_view.decoded_payload = - Some(self.decode_txn_payload(raw_txn.payload())?.try_into()?); + raw_txn_view.decoded_payload = Some(self.decode_txn_payload(raw_txn.payload())?.into()); let mut execute_result = ExecuteResultView::new(raw_txn_view, raw_txn.to_hex(), dry_output); if only_dry_run diff --git a/cmd/tx-factory/src/main.rs b/cmd/tx-factory/src/main.rs index 45958fed46..f2606c14bc 100644 --- a/cmd/tx-factory/src/main.rs +++ b/cmd/tx-factory/src/main.rs @@ -133,7 +133,7 @@ fn main() { let batch_size = opts.batch_size; let mut connected = RpcClient::connect_ipc(opts.ipc_path.clone()); - while matches!(connected, Err(_)) { + while connected.is_err() { std::thread::sleep(Duration::from_millis(1000)); connected = RpcClient::connect_ipc(opts.ipc_path.clone()); info!("re connecting..."); @@ -316,7 +316,7 @@ impl TxnMocker { let result = self.client.submit_transaction(user_txn); // increase sequence number if added in pool. - if matches!(result, Ok(_)) { + if result.is_ok() { self.next_sequence_number += 1; } if blocking { @@ -374,7 +374,7 @@ impl TxnMocker { let txn_hash = user_txn.id(); let result = self.client.submit_transaction(user_txn); - if matches!(result, Ok(_)) && blocking { + if result.is_ok() && blocking { self.client.watch_txn( txn_hash, Some(Duration::from_secs(self.watch_timeout as u64)), @@ -495,7 +495,7 @@ impl TxnMocker { expiration_timestamp, )?; let result = self.submit_txn(txn, self.account_address, true); - if matches!(result, Ok(_)) { + if result.is_ok() { info!("account transfer submit ok."); } else { info!("error: {:?}", result); diff --git a/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs b/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs index 2aa9a185d0..30b317cf91 100644 --- a/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs +++ b/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs @@ -309,7 +309,7 @@ fn test_batch_insertion() { let tree = JellyfishMerkleTree::new(&db); let mut batches2 = vec![]; - for (_idx, sub_vec) in batches.iter().enumerate() { + for sub_vec in batches.iter() { for x in sub_vec { batches2.push(vec![(x.0, Some(x.1.clone()))]); } @@ -555,7 +555,7 @@ fn test_put_blob_sets() { let mut root_hashes_one_by_one = vec![]; let mut batch_one_by_one = TreeUpdateBatch::default(); { - let mut iter = keys.clone().into_iter().zip(values.clone().into_iter()); + let mut iter = keys.clone().into_iter().zip(values.clone()); let db = MockTreeStore::default(); let tree = JellyfishMerkleTree::new(&db); @@ -579,7 +579,7 @@ fn test_put_blob_sets() { } } { - let mut iter = keys.into_iter().zip(values.into_iter()); + let mut iter = keys.into_iter().zip(values); let db = MockTreeStore::default(); let tree = JellyfishMerkleTree::new(&db); let mut blob_sets = vec![]; @@ -649,7 +649,7 @@ fn many_versions_get_proof_and_verify_tree_root(seed: &[u8], num_versions: usize let mut roots = vec![]; let mut current_root = None; - for (_idx, kvs) in kvs.iter().enumerate() { + for kvs in kvs.iter() { let (root, batch) = tree .put_blob_set(current_root, vec![(kvs.0.into(), kvs.1.clone())]) .unwrap(); @@ -659,7 +659,7 @@ fn many_versions_get_proof_and_verify_tree_root(seed: &[u8], num_versions: usize } // Update value of all keys - for (_idx, kvs) in kvs.iter().enumerate() { + for kvs in kvs.iter() { let (root, batch) = tree .put_blob_set(current_root, vec![(kvs.0.into(), kvs.2.clone())]) .unwrap(); @@ -764,8 +764,8 @@ proptest! { } } -fn test_existent_keys_impl<'a>( - tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>, +fn test_existent_keys_impl( + tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>, root_hash: HashValue, existent_kvs: &HashMap, ) { @@ -778,8 +778,8 @@ fn test_existent_keys_impl<'a>( } } -fn test_nonexistent_keys_impl<'a>( - tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>, +fn test_nonexistent_keys_impl( + tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>, root_hash: HashValue, nonexistent_keys: &[HashValueKey], ) { @@ -792,8 +792,8 @@ fn test_nonexistent_keys_impl<'a>( } } -fn test_nonexistent_key_value_update_impl<'a>( - tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>, +fn test_nonexistent_key_value_update_impl( + tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>, db: &MockTreeStore, root_hash: HashValue, noneexistent_kv: (HashValue, Blob), diff --git a/commons/forkable-jellyfish-merkle/src/lib.rs b/commons/forkable-jellyfish-merkle/src/lib.rs index 9604e0289c..dc368bc037 100644 --- a/commons/forkable-jellyfish-merkle/src/lib.rs +++ b/commons/forkable-jellyfish-merkle/src/lib.rs @@ -354,7 +354,7 @@ where blob_sets: Vec)>>, ) -> Result<(Vec, TreeUpdateBatch)> { let mut tree_cache = TreeCache::new(self.reader, state_root_hash); - for (_idx, blob_set) in blob_sets.into_iter().enumerate() { + for blob_set in blob_sets.into_iter() { assert!( !blob_set.is_empty(), "Transactions that output empty write set should not be included.", diff --git a/commons/service-registry/src/bus/sys_bus.rs b/commons/service-registry/src/bus/sys_bus.rs index 9a00fae149..2506743aaf 100644 --- a/commons/service-registry/src/bus/sys_bus.rs +++ b/commons/service-registry/src/bus/sys_bus.rs @@ -88,7 +88,7 @@ impl SysBus { M: Send + Clone + Debug + 'static, { let type_id = TypeId::of::(); - let topic_subscribes = self.subscriptions.entry(type_id).or_insert_with(Vec::new); + let topic_subscribes = self.subscriptions.entry(type_id).or_default(); debug!("do_subscribe: {:?}", subscription); topic_subscribes.push(Box::new(subscription)); } @@ -249,7 +249,7 @@ mod tests { let mut bus = SysBus::new(); let receiver = bus.oneshot::(); assert_eq!(1, bus.len_by_type::()); - let job = task::spawn(async { receiver.await }); + let job = task::spawn(receiver); Delay::new(Duration::from_millis(10)).await; bus.broadcast(Message {}); let result = job.await; diff --git a/config/src/api_config.rs b/config/src/api_config.rs index c2ff0dae6f..e59e117a90 100644 --- a/config/src/api_config.rs +++ b/config/src/api_config.rs @@ -82,8 +82,7 @@ impl FromStr for Api { } } -#[derive(Debug, Clone)] -#[derive(Default)] +#[derive(Debug, Clone, Default)] pub enum ApiSet { // Unsafe context (like jsonrpc over http) #[default] @@ -98,8 +97,6 @@ pub enum ApiSet { List(HashSet), } - - impl PartialEq for ApiSet { fn eq(&self, other: &Self) -> bool { self.list_apis() == other.list_apis() diff --git a/config/src/genesis_config.rs b/config/src/genesis_config.rs index 612d7305f2..4701f31ac9 100644 --- a/config/src/genesis_config.rs +++ b/config/src/genesis_config.rs @@ -201,8 +201,6 @@ impl BuiltinNetworkID { } } - - impl From for ChainNetwork { fn from(network: BuiltinNetworkID) -> Self { ChainNetwork::new( diff --git a/config/src/network_config.rs b/config/src/network_config.rs index c9594aa5b6..70538bd9dd 100644 --- a/config/src/network_config.rs +++ b/config/src/network_config.rs @@ -127,8 +127,8 @@ impl Seeds { } pub fn merge(&mut self, other: &Seeds) { let mut seeds = HashSet::new(); - seeds.extend(self.0.clone().into_iter()); - seeds.extend(other.0.clone().into_iter()); + seeds.extend(self.0.clone()); + seeds.extend(other.0.clone()); let mut seeds: Vec = seeds.into_iter().collect(); //keep order in config seeds.sort(); diff --git a/consensus/src/consensus_test.rs b/consensus/src/consensus_test.rs index 7c1997a186..c3fe95bb4f 100644 --- a/consensus/src/consensus_test.rs +++ b/consensus/src/consensus_test.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::consensus::Consensus; use crate::difficulty::{get_next_target_helper, BlockDiffInfo}; diff --git a/executor/benchmark/src/lib.rs b/executor/benchmark/src/lib.rs index 3706971393..31ded865ba 100644 --- a/executor/benchmark/src/lib.rs +++ b/executor/benchmark/src/lib.rs @@ -108,7 +108,7 @@ impl TransactionGenerator { /// Generates transactions that allocate `init_account_balance` to every account. fn gen_create_account_transactions(&mut self, init_account_balance: u64, block_size: usize) { - for (_i, block) in self.accounts.chunks(block_size).enumerate() { + for block in self.accounts.chunks(block_size) { self.net.time_service().sleep(1000); let mut transactions = Vec::with_capacity(block_size + 1); diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index f16dc6b0ed..76c9ebdd51 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -550,7 +550,7 @@ mod tests { storage2.get_accumulator_store(AccumulatorStoreType::Transaction), ); - let genesis_txn = genesis_block.body.transactions.get(0).cloned().unwrap(); + let genesis_txn = genesis_block.body.transactions.first().cloned().unwrap(); assert_eq!( txn_accumulator.get_leaf(0).unwrap().unwrap(), storage1 diff --git a/miner/src/create_block_template/mod.rs b/miner/src/create_block_template/mod.rs index 5e6ba1ae50..3f68cf408d 100644 --- a/miner/src/create_block_template/mod.rs +++ b/miner/src/create_block_template/mod.rs @@ -230,7 +230,7 @@ where pub fn insert_uncle(&mut self, uncle: BlockHeader) { self.parent_uncle .entry(uncle.parent_hash()) - .or_insert_with(Vec::new) + .or_default() .push(uncle.id()); self.uncles.insert(uncle.id(), uncle); if let Some(metrics) = self.metrics.as_ref() { diff --git a/network-p2p/derive/src/helper.rs b/network-p2p/derive/src/helper.rs index 8fb54a8e91..d3c25b1357 100644 --- a/network-p2p/derive/src/helper.rs +++ b/network-p2p/derive/src/helper.rs @@ -78,7 +78,6 @@ pub fn compute_args(method: &syn::TraitItemMethod) -> Punctuated continue, }; let syn::PathSegment { ident, .. } = &segments[0]; - let ident = ident; if *ident == "Self" { continue; } diff --git a/network-p2p/peerset/tests/fuzz.rs b/network-p2p/peerset/tests/fuzz.rs index d7d5a1f29c..7940554594 100644 --- a/network-p2p/peerset/tests/fuzz.rs +++ b/network-p2p/peerset/tests/fuzz.rs @@ -81,10 +81,7 @@ fn test_once() { for _ in 0..2500 { // Each of these weights corresponds to an action that we may perform. let action_weights = [150, 90, 90, 30, 30, 1, 1, 4, 4]; - match WeightedIndex::new(&action_weights) - .unwrap() - .sample(&mut rng) - { + match WeightedIndex::new(action_weights).unwrap().sample(&mut rng) { // If we generate 0, poll the peerset. 0 => match Stream::poll_next(Pin::new(&mut peerset), cx) { Poll::Ready(Some(Message::Connect { peer_id, .. })) => { diff --git a/network-p2p/src/peer_info.rs b/network-p2p/src/peer_info.rs index eaabbdc75b..c9f28e741a 100644 --- a/network-p2p/src/peer_info.rs +++ b/network-p2p/src/peer_info.rs @@ -144,7 +144,7 @@ pub struct Node<'a>(&'a NodeInfo); impl<'a> Node<'a> { /// Returns the endpoint of an established connection to the peer. pub fn endpoint(&self) -> Option<&'a ConnectedPoint> { - self.0.endpoints.get(0) // `endpoints` will trigger an exception if no item was pushed + self.0.endpoints.first() // `endpoints` will trigger an exception if no item was pushed } /// Returns the latest version information we know of. diff --git a/network-p2p/src/service_test.rs b/network-p2p/src/service_test.rs index 35b8f7a1fc..aa01968542 100644 --- a/network-p2p/src/service_test.rs +++ b/network-p2p/src/service_test.rs @@ -507,6 +507,7 @@ const PROTOCOL_NAME: &str = "/starcoin/notify/1"; // } // +#[allow(clippy::let_underscore_future)] #[stest::test] async fn test_handshake_fail() { let protocol = ProtocolId::from("starcoin"); @@ -592,6 +593,7 @@ fn test_handshake_message() { assert_eq!(status, status2); } +#[allow(clippy::let_underscore_future)] #[stest::test] async fn test_support_protocol() { let protocol = ProtocolId::from("starcoin"); diff --git a/network/api/src/peer_provider.rs b/network/api/src/peer_provider.rs index fe51c7d0a3..54c3ff7320 100644 --- a/network/api/src/peer_provider.rs +++ b/network/api/src/peer_provider.rs @@ -85,8 +85,7 @@ impl From<(PeerInfo, u64)> for PeerDetail { } } -#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema, Default)] pub enum PeerStrategy { Random, #[default] @@ -95,8 +94,6 @@ pub enum PeerStrategy { Avg, } - - impl std::fmt::Display for PeerStrategy { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let display = match self { @@ -434,7 +431,7 @@ impl PeerSelector { } if self.len() == 1 { - return self.details.lock().get(0).map(|peer| peer.peer_id()); + return self.details.lock().first().map(|peer| peer.peer_id()); } let mut random = rand::thread_rng(); @@ -461,7 +458,7 @@ impl PeerSelector { pub fn first_peer(&self) -> Option { self.details .lock() - .get(0) + .first() .map(|peer| peer.peer_info.clone()) } diff --git a/network/api/src/tests.rs b/network/api/src/tests.rs index 801277064e..b74a829bd2 100644 --- a/network/api/src/tests.rs +++ b/network/api/src/tests.rs @@ -77,7 +77,7 @@ fn test_better_peer() { peers.push(PeerInfo::random()); } - let first_peer = peers.get(0).cloned().expect("first peer must exist."); + let first_peer = peers.first().cloned().expect("first peer must exist."); let peer_selector = PeerSelector::new(peers, PeerStrategy::default(), None); let better_selector = peer_selector.betters(first_peer.total_difficulty(), 10); diff --git a/network/src/network_p2p_handle.rs b/network/src/network_p2p_handle.rs index 4278bf7f4c..3931a80606 100644 --- a/network/src/network_p2p_handle.rs +++ b/network/src/network_p2p_handle.rs @@ -113,12 +113,10 @@ impl BusinessLayerHandle for Networkp2pHandle { self.status.info = other_chain_info; Ok(()) } - Err(error) => { - Err(anyhow!( - "failed to decode the generic data for the reason: {}", - error - )) - } + Err(error) => Err(anyhow!( + "failed to decode the generic data for the reason: {}", + error + )), } } @@ -128,12 +126,10 @@ impl BusinessLayerHandle for Networkp2pHandle { self.status.info.update_status(status); Ok(()) } - Err(error) => { - Err(anyhow!( - "failed to decode the generic data for the reason: {}", - error - )) - } + Err(error) => Err(anyhow!( + "failed to decode the generic data for the reason: {}", + error + )), } } diff --git a/rpc/api/src/types/pubsub.rs b/rpc/api/src/types/pubsub.rs index 1048ca47bb..e2c95821cb 100644 --- a/rpc/api/src/types/pubsub.rs +++ b/rpc/api/src/types/pubsub.rs @@ -58,8 +58,7 @@ impl Serialize for Result { } /// Subscription kind. -#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] -#[derive(Default)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Default)] pub enum Params { /// No parameters passed. #[default] @@ -68,8 +67,6 @@ pub enum Params { Events(EventParams), } - - impl<'a> Deserialize<'a> for Params { fn deserialize(deserializer: D) -> ::std::result::Result where diff --git a/rpc/client/src/chain_watcher.rs b/rpc/client/src/chain_watcher.rs index 58dde7e5d5..f9a1ba433b 100644 --- a/rpc/client/src/chain_watcher.rs +++ b/rpc/client/src/chain_watcher.rs @@ -118,10 +118,7 @@ impl Handler for ChainWatcher { /// This method is called for every message received by this actor. fn handle(&mut self, msg: WatchBlock, _ctx: &mut Self::Context) -> Self::Result { let (tx, rx) = oneshot::channel(); - self.watched_blocks - .entry(msg.0) - .or_insert_with(Vec::new) - .push(tx); + self.watched_blocks.entry(msg.0).or_default().push(tx); MessageResult(rx) } } diff --git a/rpc/client/src/remote_state_reader.rs b/rpc/client/src/remote_state_reader.rs index 7b0f191bc5..dd3926143c 100644 --- a/rpc/client/src/remote_state_reader.rs +++ b/rpc/client/src/remote_state_reader.rs @@ -15,8 +15,7 @@ use starcoin_vm_types::state_store::state_key::StateKey; use starcoin_vm_types::state_store::table::{TableHandle, TableInfo}; use std::str::FromStr; -#[derive(Debug, Clone, Copy)] -#[derive(Default)] +#[derive(Debug, Clone, Copy, Default)] pub enum StateRootOption { #[default] Latest, @@ -24,8 +23,6 @@ pub enum StateRootOption { BlockNumber(BlockNumber), } - - impl FromStr for StateRootOption { type Err = anyhow::Error; diff --git a/rpc/client/tests/client_server_test.rs b/rpc/client/tests/client_server_test.rs index bf053a449b..a59d78cc66 100644 --- a/rpc/client/tests/client_server_test.rs +++ b/rpc/client/tests/client_server_test.rs @@ -133,8 +133,8 @@ fn test_client_reconnect_subscribe() -> Result<()> { std::thread::sleep(Duration::from_millis(300)); let _e = node_handle.stop(); - let events1 = futures::executor::block_on(async move { handle1.await }); - let events2 = futures::executor::block_on(async move { handle2.await }); + let events1 = futures::executor::block_on(handle1); + let events2 = futures::executor::block_on(handle2); assert_ne!(events1.len(), 0); assert_ne!(events2.len(), 0); Ok(()) diff --git a/state/api/src/mock/mock_chain_state_service.rs b/state/api/src/mock/mock_chain_state_service.rs index 545a17027e..4a6da4811e 100644 --- a/state/api/src/mock/mock_chain_state_service.rs +++ b/state/api/src/mock/mock_chain_state_service.rs @@ -20,6 +20,7 @@ impl MockChainStateService { } } +#[allow(clippy::diverging_sub_expression)] #[async_trait::async_trait] impl ChainStateAsyncService for MockChainStateService { async fn get(self, _access_path: AccessPath) -> Result>> { diff --git a/state/state-tree/src/mock/mod.rs b/state/state-tree/src/mock/mod.rs index 88efa7e2e9..a58ed5cf24 100644 --- a/state/state-tree/src/mock/mod.rs +++ b/state/state-tree/src/mock/mod.rs @@ -40,7 +40,7 @@ impl StateNodeStore for MockStateNodeStore { fn write_nodes(&self, nodes: BTreeMap) -> Result<(), Error> { let mut store_nodes = self.nodes.write(); - store_nodes.extend(nodes.into_iter()); + store_nodes.extend(nodes); Ok(()) } diff --git a/state/state-tree/src/state_tree_test.rs b/state/state-tree/src/state_tree_test.rs index a890660614..36a2e5a7cf 100644 --- a/state/state-tree/src/state_tree_test.rs +++ b/state/state-tree/src/state_tree_test.rs @@ -128,7 +128,7 @@ pub fn test_put_blob_continue_commit_flush_same() -> Result<()> { assert_eq!(updates2.stale_node_index_batch.len(), 2); let account13 = update_nibble(&account11, 2, 3); - for (k, v) in vec![(account11, vec![1, 1, 0]), (account13, vec![0, 0, 0])] { + for (k, v) in [(account11, vec![1, 1, 0]), (account13, vec![0, 0, 0])] { state1.put(k, v); } assert_eq!(state1.get(&account11)?, Some(vec![1, 1, 0])); @@ -146,7 +146,7 @@ pub fn test_put_blob_continue_commit_flush_same() -> Result<()> { assert_eq!(updates1.stale_node_index_batch.len(), 2); let account23 = update_nibble(&account21, 2, 3); - for (k, v) in vec![(account21, vec![1, 1, 0]), (account23, vec![0, 0, 0])] { + for (k, v) in [(account21, vec![1, 1, 0]), (account23, vec![0, 0, 0])] { state2.put(k, v); } assert_eq!(state2.get(&account21)?, Some(vec![1, 1, 0])); @@ -190,7 +190,7 @@ pub fn test_state_proof() -> Result<()> { let account1 = update_nibble(&account1, 2, 1); let account2 = update_nibble(&account1, 2, 2); - for (k, v) in vec![(account1, vec![0, 0, 0]), (account2, vec![1, 1, 1])] { + for (k, v) in [(account1, vec![0, 0, 0]), (account2, vec![1, 1, 1])] { state.put(k, v); } let (value, _) = state.get_with_proof(&account1)?; @@ -225,7 +225,7 @@ pub fn test_state_commit() -> Result<()> { let _new_root_hash = state.commit()?; let account3 = update_nibble(&account1, 2, 3); - for (k, v) in vec![(account1, vec![1, 1, 0]), (account3, vec![0, 0, 0])] { + for (k, v) in [(account1, vec![1, 1, 0]), (account3, vec![0, 0, 0])] { state.put(k, v); } let new_root_hash = state.commit()?; diff --git a/state/statedb/src/tests.rs b/state/statedb/src/tests.rs index 2765675fa2..303a248d0e 100644 --- a/state/statedb/src/tests.rs +++ b/state/statedb/src/tests.rs @@ -25,7 +25,6 @@ fn state_keys_to_write_set(state_keys: Vec, values: Vec>) -> W state_keys .into_iter() .zip(values) - .into_iter() .map(|(key, val)| (key, WriteOp::Value(val))) .collect::>(), ) diff --git a/storage/src/tests/test_batch.rs b/storage/src/tests/test_batch.rs index caeaaf5acf..fa05c28f86 100644 --- a/storage/src/tests/test_batch.rs +++ b/storage/src/tests/test_batch.rs @@ -208,7 +208,7 @@ fn test_write_batch_multi_get() -> Result<()> { vec![id1.to_vec(), id2.to_vec()], )?; assert_eq!( - RichTransactionInfo::decode_value(&infos.get(0).unwrap().clone().unwrap())?, + RichTransactionInfo::decode_value(&infos.first().unwrap().clone().unwrap())?, transaction_info1 ); assert_eq!( @@ -260,7 +260,7 @@ fn test_cache_multi_get_no_evict() -> Result<()> { )?; assert_eq!( - RichTransactionInfo::decode_value(&infos.get(0).unwrap().clone().unwrap())?, + RichTransactionInfo::decode_value(&infos.first().unwrap().clone().unwrap())?, transaction_info1 ); assert_eq!( @@ -326,7 +326,7 @@ fn test_cache_multi_get_with_evict() -> Result<()> { vec![id1.to_vec(), id2.to_vec(), id3.to_vec()], )?; - assert!(&infos.get(0).unwrap().is_none(), "id1 has evicted"); + assert!(&infos.first().unwrap().is_none(), "id1 has evicted"); assert_eq!( RichTransactionInfo::decode_value(&infos.get(1).unwrap().clone().unwrap())?, transaction_info2 diff --git a/storage/src/tests/test_storage.rs b/storage/src/tests/test_storage.rs index be7a2eaa44..e801bda6fb 100644 --- a/storage/src/tests/test_storage.rs +++ b/storage/src/tests/test_storage.rs @@ -458,7 +458,7 @@ pub fn test_cache_evict_multi_get() -> Result<()> { TRANSACTION_INFO_PREFIX_NAME_V2, vec![id1.to_vec(), id2.to_vec(), id3.to_vec()], )?; - assert!(&cache_infos.get(0).unwrap().is_none(), "id1 has evicted"); + assert!(&cache_infos.first().unwrap().is_none(), "id1 has evicted"); assert_eq!( RichTransactionInfo::decode_value(&cache_infos.get(1).unwrap().clone().unwrap())?, transaction_info2 @@ -470,7 +470,7 @@ pub fn test_cache_evict_multi_get() -> Result<()> { let infos = storage .transaction_info_storage .multiple_get(vec![id1, id2, id3])?; - assert_eq!(infos.get(0).unwrap().clone().unwrap(), transaction_info1); + assert_eq!(infos.first().unwrap().clone().unwrap(), transaction_info1); assert_eq!(infos.get(1).unwrap().clone().unwrap(), transaction_info2); assert_eq!(infos.get(2).unwrap().clone().unwrap(), transaction_info3); Ok(()) diff --git a/storage/src/transaction/test.rs b/storage/src/transaction/test.rs index cbf90ada75..83df1a6ded 100644 --- a/storage/src/transaction/test.rs +++ b/storage/src/transaction/test.rs @@ -53,7 +53,7 @@ proptest! { .unwrap(); let txns = init_store(universe, gens, &storage); - for (_ver, txn) in txns.iter().enumerate() { + for txn in txns.iter() { prop_assert_eq!(storage .transaction_storage .get_transaction(txn.id()).unwrap().unwrap(), txn.clone()); diff --git a/sync/src/block_connector/test_illegal_block.rs b/sync/src/block_connector/test_illegal_block.rs index ec2b662895..e1b3c4e7e7 100644 --- a/sync/src/block_connector/test_illegal_block.rs +++ b/sync/src/block_connector/test_illegal_block.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::block_connector::{ create_writeable_block_chain, gen_blocks, new_block, WriteBlockChainService, }; diff --git a/sync/src/block_connector/test_write_block_chain.rs b/sync/src/block_connector/test_write_block_chain.rs index c94ebe91b9..739c45e2df 100644 --- a/sync/src/block_connector/test_write_block_chain.rs +++ b/sync/src/block_connector/test_write_block_chain.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::block_connector::WriteBlockChainService; use starcoin_account_api::AccountInfo; use starcoin_chain::{BlockChain, ChainReader}; diff --git a/sync/src/block_connector/write_block_chain.rs b/sync/src/block_connector/write_block_chain.rs index c22ff42408..cd887b69f6 100644 --- a/sync/src/block_connector/write_block_chain.rs +++ b/sync/src/block_connector/write_block_chain.rs @@ -162,7 +162,7 @@ where } fn block_exist(&self, block_id: HashValue) -> Result { - Ok(matches!(self.storage.get_block_info(block_id)?, Some(_))) + Ok(self.storage.get_block_info(block_id)?.is_some()) } pub fn get_main(&self) -> &BlockChain { diff --git a/sync/src/tasks/mock.rs b/sync/src/tasks/mock.rs index 5f5c66034d..2428863534 100644 --- a/sync/src/tasks/mock.rs +++ b/sync/src/tasks/mock.rs @@ -26,19 +26,15 @@ use starcoin_types::block::{Block, BlockIdAndNumber, BlockInfo, BlockNumber}; use std::sync::Arc; use std::time::Duration; +#[derive(Default)] pub enum ErrorStrategy { _RateLimitErr, Timeout(u64), + #[default] RandomErr, MethodNotFound, } -impl Default for ErrorStrategy { - fn default() -> Self { - ErrorStrategy::RandomErr - } -} - pub struct ErrorMocker { strategy: ErrorStrategy, pub random_error_percent: u32, diff --git a/sync/src/tasks/tests.rs b/sync/src/tasks/tests.rs index 06206f227e..bc76ee38c4 100644 --- a/sync/src/tasks/tests.rs +++ b/sync/src/tasks/tests.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::tasks::block_sync_task::SyncBlockData; use crate::tasks::mock::{ErrorStrategy, MockBlockIdFetcher, SyncNodeMocker}; use crate::tasks::{ diff --git a/sync/src/verified_rpc_client.rs b/sync/src/verified_rpc_client.rs index 5dcaabe6dc..fd9e4d301e 100644 --- a/sync/src/verified_rpc_client.rs +++ b/sync/src/verified_rpc_client.rs @@ -64,7 +64,7 @@ where resp: Vec>, ) -> Result>, RpcVerifyError> { req.into_iter() - .zip(resp.into_iter()) + .zip(resp) .map(|(req_item, resp_item)| { if let Some(resp_item) = resp_item { if (self)(&req_item, &resp_item) { diff --git a/txpool/src/test.rs b/txpool/src/test.rs index e205b388e6..d70e1ede1d 100644 --- a/txpool/src/test.rs +++ b/txpool/src/test.rs @@ -108,7 +108,6 @@ async fn test_pool_pending() -> Result<()> { let metrics_config: &MetricsConfig = &node_config.metrics; let txn_vec = (0..pool_size + expect_reject) - .into_iter() .map(|index| generate_txn(node_config.clone(), index)) .collect::>(); @@ -152,7 +151,6 @@ async fn test_pool_pending() -> Result<()> { ); let txn_vec = (pool_size..(pool_size + expect_reject)) - .into_iter() .map(|index| generate_txn(node_config.clone(), index)) .collect::>(); diff --git a/vm/gas-algebra-ext/src/natives.rs b/vm/gas-algebra-ext/src/natives.rs index 664128179b..8608b07db5 100644 --- a/vm/gas-algebra-ext/src/natives.rs +++ b/vm/gas-algebra-ext/src/natives.rs @@ -197,16 +197,11 @@ mod tests { #[test] fn optional_should_be_honored() { - assert!(matches!( - GasParameters::from_on_chain_gas_schedule( - &[("test.foo".to_string(), 0)].into_iter().collect(), - ), - Some(_) - )); - - assert!(matches!( - GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()), - None - )); + assert!(GasParameters::from_on_chain_gas_schedule( + &[("test.foo".to_string(), 0)].into_iter().collect(), + ) + .is_some()); + + assert!(GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()).is_none()); } } diff --git a/vm/gas-algebra-ext/src/params.rs b/vm/gas-algebra-ext/src/params.rs index 872a96ee7e..f33c1fb1ef 100644 --- a/vm/gas-algebra-ext/src/params.rs +++ b/vm/gas-algebra-ext/src/params.rs @@ -88,18 +88,11 @@ mod tests { #[test] fn optional_should_be_honored() { - assert!( - matches!( - GasParameters::from_on_chain_gas_schedule( - &[("test.foo".to_string(), 0)].into_iter().collect(), - ), - Some(_) - ) - ); - - assert!(matches!( - GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()), - None - )); + assert!(GasParameters::from_on_chain_gas_schedule( + &[("test.foo".to_string(), 0)].into_iter().collect(), + ) + .is_some()); + + assert!(GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()).is_none(),); } } diff --git a/vm/move-package-manager/src/lib.rs b/vm/move-package-manager/src/lib.rs index 2f1f2723e9..42d6592394 100644 --- a/vm/move-package-manager/src/lib.rs +++ b/vm/move-package-manager/src/lib.rs @@ -60,8 +60,7 @@ pub struct TestOpts { format: Format, } -#[derive(Debug, Eq, PartialEq)] -#[derive(Default)] +#[derive(Debug, Eq, PartialEq, Default)] enum Format { #[default] Pretty, @@ -98,8 +97,6 @@ impl FromStr for Format { } } - - #[derive(Args, Debug)] pub struct IntegrationTestCommand { #[clap(flatten)] diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index 52fc6ff013..9ce76866b4 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -77,7 +77,7 @@ impl MVHashMap { pub fn write(&self, key: &K, version: Version, data: V) { let (txn_idx, incarnation) = version; - let mut map = self.data.entry(key.clone()).or_insert(BTreeMap::new()); + let mut map = self.data.entry(key.clone()).or_default(); let prev_cell = map.insert( txn_idx, CachePadded::new(WriteCell::new_from(FLAG_DONE, incarnation, data)), diff --git a/vm/mvhashmap/src/unit_tests/proptest_types.rs b/vm/mvhashmap/src/unit_tests/proptest_types.rs index 739db06211..4a9b588419 100644 --- a/vm/mvhashmap/src/unit_tests/proptest_types.rs +++ b/vm/mvhashmap/src/unit_tests/proptest_types.rs @@ -44,7 +44,7 @@ where baseline .entry(k.clone()) - .or_insert_with(BTreeMap::new) + .or_default() .insert(idx, value_to_update); } Self(baseline) diff --git a/vm/resource-viewer/src/lib.rs b/vm/resource-viewer/src/lib.rs index cc9c044620..48febc6732 100644 --- a/vm/resource-viewer/src/lib.rs +++ b/vm/resource-viewer/src/lib.rs @@ -168,10 +168,7 @@ impl<'a> MoveValueAnnotator<'a> { Ok(AnnotatedMoveStruct { abilities: ty.abilities.0, type_: struct_tag, - value: field_names - .into_iter() - .zip(annotated_fields.into_iter()) - .collect(), + value: field_names.into_iter().zip(annotated_fields).collect(), }) } diff --git a/vm/starcoin-transactional-test-harness/src/fork_chain.rs b/vm/starcoin-transactional-test-harness/src/fork_chain.rs index 9d0dda112d..37a8c6e6aa 100644 --- a/vm/starcoin-transactional-test-harness/src/fork_chain.rs +++ b/vm/starcoin-transactional-test-harness/src/fork_chain.rs @@ -325,10 +325,7 @@ impl ChainApi for MockChainApi { } else if number <= current_number { let hash = number_hash_map.get(&number).map(|h| *h); let block_view = match hash { - Some(hash) => match storage.get_block_info(hash)? { - Some(b) => Some(BlockInfoView::try_from(b)?), - None => None, - }, + Some(hash) => storage.get_block_info(hash)?.map(BlockInfoView::from), None => None, }; Ok(block_view) diff --git a/vm/starcoin-transactional-test-harness/src/lib.rs b/vm/starcoin-transactional-test-harness/src/lib.rs index 8727440b00..3c44589575 100644 --- a/vm/starcoin-transactional-test-harness/src/lib.rs +++ b/vm/starcoin-transactional-test-harness/src/lib.rs @@ -998,7 +998,7 @@ impl<'a> StarcoinTestAdapter<'a> { ) })?; - let signer = match signers.get(0) { + let signer = match signers.first() { Some(addr) => self.compiled_state.resolve_address(addr), None => package.package_address(), }; @@ -1254,7 +1254,7 @@ impl<'a> MoveTestAdapter<'a> for StarcoinTestAdapter<'a> { } match is_vec_u8 { true => { - assert_eq!(vals.get(0), Some(&MoveValue::U8(48))); + assert_eq!(vals.first(), Some(&MoveValue::U8(48))); assert_eq!(vals.get(1), Some(&MoveValue::U8(120))); let mut vals_compress = vec![]; for i in (2..vals.len()).step_by(2) { diff --git a/vm/transaction-builder-generator/src/dart.rs b/vm/transaction-builder-generator/src/dart.rs index 4ef84c9b9b..44006b43c9 100644 --- a/vm/transaction-builder-generator/src/dart.rs +++ b/vm/transaction-builder-generator/src/dart.rs @@ -488,10 +488,10 @@ return TransactionPayloadScriptFunctionItem(ScriptFunction(module,function,ty_ar )?; self.out.indent(); - for (_, ty_arg) in abi.ty_args().iter().enumerate() { + for ty_arg in abi.ty_args().iter() { writeln!(self.out, "{},", ty_arg.name(),)?; } - for (_, arg) in abi.args().iter().enumerate() { + for arg in abi.args().iter() { writeln!(self.out, "{},", arg.name(),)?; } self.out.unindent(); diff --git a/vm/transaction-builder/src/lib.rs b/vm/transaction-builder/src/lib.rs index 0019c4512b..dfa9602d4e 100644 --- a/vm/transaction-builder/src/lib.rs +++ b/vm/transaction-builder/src/lib.rs @@ -376,7 +376,7 @@ pub fn build_init_script_v1(net: &ChainNetwork) -> ScriptFunction { .genesis_key_pair .as_ref() .map(|(_, public_key)| AuthenticationKey::ed25519(public_key).to_vec()) - .unwrap_or_else(Vec::new); + .unwrap_or_default(); let association_auth_key = AuthenticationKey::multi_ed25519(&genesis_config.association_key_pair.1).to_vec(); @@ -539,7 +539,7 @@ pub fn build_init_script_v2(net: &ChainNetwork) -> ScriptFunction { .genesis_key_pair .as_ref() .map(|(_, public_key)| AuthenticationKey::ed25519(public_key).to_vec()) - .unwrap_or_else(Vec::new); + .unwrap_or_default(); let association_auth_key = AuthenticationKey::multi_ed25519(&genesis_config.association_key_pair.1).to_vec(); diff --git a/vm/types/src/account_config/resources/auto_accept_token.rs b/vm/types/src/account_config/resources/auto_accept_token.rs index c49bae97a7..859ac8bf0c 100644 --- a/vm/types/src/account_config/resources/auto_accept_token.rs +++ b/vm/types/src/account_config/resources/auto_accept_token.rs @@ -26,7 +26,7 @@ impl AutoAcceptToken { && struct_tag.module.as_str() == Self::MODULE_NAME && struct_tag.name.as_str() == Self::STRUCT_NAME { - if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.get(0) { + if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.first() { Some((*(token_tag.clone())).into()) } else { None diff --git a/vm/types/src/account_config/resources/balance.rs b/vm/types/src/account_config/resources/balance.rs index d4e8561f8c..a9070483e8 100644 --- a/vm/types/src/account_config/resources/balance.rs +++ b/vm/types/src/account_config/resources/balance.rs @@ -47,7 +47,7 @@ impl BalanceResource { && struct_tag.module.as_str() == Self::MODULE_NAME && struct_tag.name.as_str() == Self::STRUCT_NAME { - if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.get(0) { + if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.first() { Some((*(token_tag.clone())).into()) } else { None diff --git a/vm/types/src/genesis_config.rs b/vm/types/src/genesis_config.rs index d13dd35d98..2e6e8eedd2 100644 --- a/vm/types/src/genesis_config.rs +++ b/vm/types/src/genesis_config.rs @@ -10,8 +10,7 @@ use std::cmp::Ordering; use std::fmt::{self, Formatter}; use std::fmt::{Debug, Display}; use std::str::FromStr; -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Default)] pub enum StdlibVersion { #[default] Latest, @@ -73,8 +72,6 @@ impl Ord for StdlibVersion { } } - - impl FromStr for StdlibVersion { type Err = anyhow::Error; @@ -127,8 +124,6 @@ impl ConsensusStrategy { } } - - impl fmt::Display for ConsensusStrategy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/vm/types/src/on_chain_resource/nft.rs b/vm/types/src/on_chain_resource/nft.rs index a26d661afb..344d2121c5 100644 --- a/vm/types/src/on_chain_resource/nft.rs +++ b/vm/types/src/on_chain_resource/nft.rs @@ -294,7 +294,7 @@ impl NFTGallery { { if struct_tag.type_params.len() == 2 { let (meta_type, body_type) = ( - struct_tag.type_params.get(0).cloned().unwrap(), + struct_tag.type_params.first().cloned().unwrap(), struct_tag.type_params.get(1).cloned().unwrap(), ); Some(NFTType { @@ -346,7 +346,7 @@ impl IdentifierNFT { { if struct_tag.type_params.len() == 2 { let (meta_type, body_type) = ( - struct_tag.type_params.get(0).cloned().unwrap(), + struct_tag.type_params.first().cloned().unwrap(), struct_tag.type_params.get(1).cloned().unwrap(), ); Some(NFTType { diff --git a/vm/types/src/token/token_code.rs b/vm/types/src/token/token_code.rs index 02ec55af8c..ec6b885b3c 100644 --- a/vm/types/src/token/token_code.rs +++ b/vm/types/src/token/token_code.rs @@ -163,7 +163,7 @@ mod test { parse_type_tag(token).unwrap(), TypeTag::Struct(Box::new(type_tag.clone())) ); - assert_eq!(tc, type_tag.try_into().unwrap()); + assert_eq!(tc, type_tag.into()); } #[derive(Serialize, Deserialize, Debug, Clone, PartialOrd, Eq, PartialEq)] diff --git a/vm/types/src/transaction/authenticator.rs b/vm/types/src/transaction/authenticator.rs index e4cc3575c5..87462678ca 100644 --- a/vm/types/src/transaction/authenticator.rs +++ b/vm/types/src/transaction/authenticator.rs @@ -520,7 +520,6 @@ mod tests { let mut key_gen = KeyGen::from_os_rng(); let threshold = 2; let pubkeys = (0..2) - .into_iter() .map(|_| key_gen.generate_keypair().1) .collect::>(); let account_public_key = AccountPublicKey::multi(pubkeys.clone(), threshold).unwrap(); diff --git a/vm/types/src/write_set.rs b/vm/types/src/write_set.rs index e37993c855..5bede2efef 100644 --- a/vm/types/src/write_set.rs +++ b/vm/types/src/write_set.rs @@ -7,6 +7,7 @@ use crate::state_store::state_key::StateKey; use anyhow::Result; use serde::{Deserialize, Serialize}; +use std::ops::Add; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub enum WriteOp { @@ -30,10 +31,8 @@ impl std::fmt::Debug for WriteOp { WriteOp::Value(value) => write!( f, "Value({})", - value - .iter() - .map(|byte| format!("{:02x}", byte)) - .collect::() + value.iter().fold(String::new(), |acc, byte| acc + .add(format!("{:02x}", byte).as_str())) ), WriteOp::Deletion => write!(f, "Deletion"), } diff --git a/vm/vm-runtime/src/errors.rs b/vm/vm-runtime/src/errors.rs index 71d6b2ea89..386088fc9d 100644 --- a/vm/vm-runtime/src/errors.rs +++ b/vm/vm-runtime/src/errors.rs @@ -110,7 +110,7 @@ pub fn convert_normal_success_epilogue_error(error: VMError) -> Result<(), VMSta let (category, reason) = error_split(code); match (category, reason) { (LIMIT_EXCEEDED, EINSUFFICIENT_BALANCE) => { - if location != account_module_abort() {} + let _ = location != account_module_abort(); VMStatus::MoveAbort(location, code) } (category, reason) => {