From 3df67b376bce34d180c46308d68d970394f2e258 Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sun, 15 Oct 2017 20:10:20 +0700 Subject: [PATCH 1/5] Removes redundant `mut` in ethcore --- ethcore/src/account_provider/stores.rs | 10 +++++----- ethcore/src/engines/mod.rs | 2 +- ethcore/src/executive.rs | 2 +- ethcore/src/miner/banning_queue.rs | 6 +++--- ethcore/src/miner/transaction_queue.rs | 4 ++-- ethcore/src/state/mod.rs | 2 +- ethcore/src/state_db.rs | 2 +- ethcore/src/verification/queue/mod.rs | 2 +- ethstore/src/dir/memory.rs | 6 +++--- ethstore/src/ethstore.rs | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ethcore/src/account_provider/stores.rs b/ethcore/src/account_provider/stores.rs index 72bc04da6..45652a8a6 100644 --- a/ethcore/src/account_provider/stores.rs +++ b/ethcore/src/account_provider/stores.rs @@ -64,7 +64,7 @@ impl AddressBook { /// Sets new name for given address. pub fn set_name(&mut self, a: Address, name: String) { { - let mut x = self.cache.entry(a) + let x = self.cache.entry(a) .or_insert_with(|| AccountMeta {name: Default::default(), meta: "{}".to_owned(), uuid: None}); x.name = name; } @@ -74,7 +74,7 @@ impl AddressBook { /// Sets new meta for given address. pub fn set_meta(&mut self, a: Address, meta: String) { { - let mut x = self.cache.entry(a) + let x = self.cache.entry(a) .or_insert_with(|| AccountMeta {name: "Anonymous".to_owned(), meta: Default::default(), uuid: None}); x.meta = meta; } @@ -253,7 +253,7 @@ impl DappsSettingsStore { /// Marks recent dapp as used pub fn mark_dapp_used(&mut self, dapp: DappId) { { - let mut entry = self.history.entry(dapp).or_insert_with(|| Default::default()); + let entry = self.history.entry(dapp).or_insert_with(|| Default::default()); entry.last_accessed = self.time.get(); } // Clear extraneous entries @@ -280,7 +280,7 @@ impl DappsSettingsStore { /// Sets accounts for specific dapp. pub fn set_accounts(&mut self, id: DappId, accounts: Option>) { { - let mut settings = self.settings.entry(id).or_insert_with(DappsSettings::default); + let settings = self.settings.entry(id).or_insert_with(DappsSettings::default); settings.accounts = accounts; } self.settings.save(JsonSettings::write); @@ -289,7 +289,7 @@ impl DappsSettingsStore { /// Sets a default account for specific dapp. pub fn set_default(&mut self, id: DappId, default: Address) { { - let mut settings = self.settings.entry(id).or_insert_with(DappsSettings::default); + let settings = self.settings.entry(id).or_insert_with(DappsSettings::default); settings.default = Some(default); } self.settings.save(JsonSettings::write); diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 2e583b179..802b4ab88 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -421,7 +421,7 @@ pub mod common { .and_then(|_| fields.state.commit()); let block_author = fields.header.author().clone(); - fields.traces.as_mut().map(move |mut traces| { + fields.traces.as_mut().map(move |traces| { let mut tracer = ExecutiveTracer::default(); tracer.trace_reward(block_author, reward, RewardType::Block); traces.push(tracer.drain()) diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 2a70689db..3709ea449 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -433,7 +433,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { // trace only top level calls to builtins to avoid DDoS attacks if self.depth == 0 { let mut trace_output = tracer.prepare_trace_output(); - if let Some(mut out) = trace_output.as_mut() { + if let Some(out) = trace_output.as_mut() { *out = output.to_owned(); } diff --git a/ethcore/src/miner/banning_queue.rs b/ethcore/src/miner/banning_queue.rs index a446da29e..d89c30b86 100644 --- a/ethcore/src/miner/banning_queue.rs +++ b/ethcore/src/miner/banning_queue.rs @@ -149,7 +149,7 @@ impl BanningTransactionQueue { /// queue. fn ban_sender(&mut self, address: Address) -> bool { let count = { - let mut count = self.senders_bans.entry(address).or_insert_with(|| 0); + let count = self.senders_bans.entry(address).or_insert_with(|| 0); *count = count.saturating_add(1); *count }; @@ -169,7 +169,7 @@ impl BanningTransactionQueue { /// Returns true if bans threshold has been reached. fn ban_recipient(&mut self, address: Address) -> bool { let count = { - let mut count = self.recipients_bans.entry(address).or_insert_with(|| 0); + let count = self.recipients_bans.entry(address).or_insert_with(|| 0); *count = count.saturating_add(1); *count }; @@ -185,7 +185,7 @@ impl BanningTransactionQueue { /// If bans threshold is reached all subsequent transactions to contracts with this codehash will be rejected. /// Returns true if bans threshold has been reached. fn ban_codehash(&mut self, code_hash: H256) -> bool { - let mut count = self.codes_bans.entry(code_hash).or_insert_with(|| 0); + let count = self.codes_bans.entry(code_hash).or_insert_with(|| 0); *count = count.saturating_add(1); match self.ban_threshold { diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index 0234af068..2accbecc0 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -341,7 +341,7 @@ impl GasPriceQueue { /// Remove an item from a BTreeMap/HashSet "multimap". /// Returns true if the item was removed successfully. pub fn remove(&mut self, gas_price: &U256, hash: &H256) -> bool { - if let Some(mut hashes) = self.backing.get_mut(gas_price) { + if let Some(hashes) = self.backing.get_mut(gas_price) { let only_one_left = hashes.len() == 1; if !only_one_left { // Operation may be ok: only if hash is in gas-price's Set. @@ -1225,7 +1225,7 @@ impl TransactionQueue { if by_nonce.is_none() { return; } - let mut by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed"); + let by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed"); while let Some(order) = by_nonce.remove(¤t_nonce) { // remove also from priority and gas_price self.future.by_priority.remove(&order); diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 96fd46ec5..dfde05921 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -962,7 +962,7 @@ impl State { // at this point the entry is guaranteed to be in the cache. Ok(RefMut::map(self.cache.borrow_mut(), |c| { - let mut entry = c.get_mut(a).expect("entry known to exist in the cache; qed"); + let entry = c.get_mut(a).expect("entry known to exist in the cache; qed"); match &mut entry.account { &mut Some(ref mut acc) => not_default(acc), diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index 6d2885a5a..a2e4dcac4 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -211,7 +211,7 @@ impl StateDB { pub fn sync_cache(&mut self, enacted: &[H256], retracted: &[H256], is_best: bool) { trace!("sync_cache id = (#{:?}, {:?}), parent={:?}, best={}", self.commit_number, self.commit_hash, self.parent_hash, is_best); let mut cache = self.account_cache.lock(); - let mut cache = &mut *cache; + let cache = &mut *cache; // Purge changes from re-enacted and retracted blocks. // Filter out commiting block if any. diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 198c63287..bf7c9ef5c 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -522,7 +522,7 @@ impl VerificationQueue { return; } let mut verified_lock = self.verification.verified.lock(); - let mut verified = &mut *verified_lock; + let verified = &mut *verified_lock; let mut bad = self.verification.bad.lock(); let mut processing = self.processing.write(); bad.reserve(hashes.len()); diff --git a/ethstore/src/dir/memory.rs b/ethstore/src/dir/memory.rs index b8c2ad9ff..bd162b5ef 100644 --- a/ethstore/src/dir/memory.rs +++ b/ethstore/src/dir/memory.rs @@ -35,7 +35,7 @@ impl KeyDirectory for MemoryDirectory { fn update(&self, account: SafeAccount) -> Result { let mut lock = self.accounts.write(); - let mut accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new); + let accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new); // If the filename is the same we just need to replace the entry accounts.retain(|acc| acc.filename != account.filename); accounts.push(account.clone()); @@ -44,14 +44,14 @@ impl KeyDirectory for MemoryDirectory { fn insert(&self, account: SafeAccount) -> Result { let mut lock = self.accounts.write(); - let mut accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new); + let accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new); accounts.push(account.clone()); Ok(account) } fn remove(&self, account: &SafeAccount) -> Result<(), Error> { let mut accounts = self.accounts.write(); - let is_empty = if let Some(mut accounts) = accounts.get_mut(&account.address) { + let is_empty = if let Some(accounts) = accounts.get_mut(&account.address) { if let Some(position) = accounts.iter().position(|acc| acc == account) { accounts.remove(position); } diff --git a/ethstore/src/ethstore.rs b/ethstore/src/ethstore.rs index f3bb24071..7588cc9fb 100755 --- a/ethstore/src/ethstore.rs +++ b/ethstore/src/ethstore.rs @@ -358,7 +358,7 @@ impl EthMultiStore { // update cache let mut cache = self.cache.write(); - let mut accounts = cache.entry(account_ref.clone()).or_insert_with(Vec::new); + let accounts = cache.entry(account_ref.clone()).or_insert_with(Vec::new); // Remove old account accounts.retain(|acc| acc != &old); // And push updated to the end From b49baed6961232600048aefb9e49f0a8d57afe0e Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sun, 15 Oct 2017 20:10:59 +0700 Subject: [PATCH 2/5] Removes redundant `mut` in hw --- hw/src/ledger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/src/ledger.rs b/hw/src/ledger.rs index 5fcac3e55..6b4c87a0a 100644 --- a/hw/src/ledger.rs +++ b/hw/src/ledger.rs @@ -255,7 +255,7 @@ impl Manager { let mut chunk_size = if chunk_index == 0 { 12 } else { 5 }; let size = min(64 - chunk_size, data.len() - offset); { - let mut chunk = &mut hid_chunk[HID_PREFIX_ZERO..]; + let chunk = &mut hid_chunk[HID_PREFIX_ZERO..]; &mut chunk[0..5].copy_from_slice(&[0x01, 0x01, APDU_TAG, (chunk_index >> 8) as u8, (chunk_index & 0xff) as u8 ]); if chunk_index == 0 { From dab40e832c358f7cc8967ccf815e8c5fe00a4cce Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sun, 15 Oct 2017 20:11:07 +0700 Subject: [PATCH 3/5] Removes redundant `mut` in rpc --- rpc/src/authcodes.rs | 2 +- rpc/src/v1/extractors.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/src/authcodes.rs b/rpc/src/authcodes.rs index c8a0731e3..f1b2a391d 100644 --- a/rpc/src/authcodes.rs +++ b/rpc/src/authcodes.rs @@ -176,7 +176,7 @@ impl AuthCodes { } // look for code - for mut code in &mut self.codes { + for code in &mut self.codes { if &as_token(&code.code) == hash { code.last_used_at = Some(time::Duration::from_secs(now)); return true; diff --git a/rpc/src/v1/extractors.rs b/rpc/src/v1/extractors.rs index a24722900..1c0fb1322 100644 --- a/rpc/src/v1/extractors.rs +++ b/rpc/src/v1/extractors.rs @@ -136,7 +136,7 @@ impl ws::RequestMiddleware for WsExtractor { } fn add_security_headers(res: &mut ws::ws::Response) { - let mut headers = res.headers_mut(); + let headers = res.headers_mut(); headers.push(("X-Frame-Options".into(), b"SAMEORIGIN".to_vec())); headers.push(("X-XSS-Protection".into(), b"1; mode=block".to_vec())); headers.push(("X-Content-Type-Options".into(), b"nosniff".to_vec())); From 74876fd4100f30d12d6a558741e315551ab2dcc4 Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sun, 15 Oct 2017 20:11:20 +0700 Subject: [PATCH 4/5] Removes redundant `mut` in sync --- sync/src/chain.rs | 10 +++++----- sync/src/transactions_stats.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 8e2b9e9f5..e60996099 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -459,7 +459,7 @@ impl ChainSync { /// Updates transactions were received by a peer pub fn transactions_received(&mut self, hashes: Vec, peer_id: PeerId) { - if let Some(mut peer_info) = self.peers.get_mut(&peer_id) { + if let Some(peer_info) = self.peers.get_mut(&peer_id) { peer_info.last_sent_transactions.extend(&hashes); } } @@ -730,7 +730,7 @@ impl ChainSync { } let result = { - let mut downloader = match block_set { + let downloader = match block_set { BlockSet::NewBlocks => &mut self.new_blocks, BlockSet::OldBlocks => { match self.old_blocks { @@ -795,7 +795,7 @@ impl ChainSync { else { let result = { - let mut downloader = match block_set { + let downloader = match block_set { BlockSet::NewBlocks => &mut self.new_blocks, BlockSet::OldBlocks => match self.old_blocks { None => { @@ -849,7 +849,7 @@ impl ChainSync { else { let result = { - let mut downloader = match block_set { + let downloader = match block_set { BlockSet::NewBlocks => &mut self.new_blocks, BlockSet::OldBlocks => match self.old_blocks { None => { @@ -2186,7 +2186,7 @@ impl ChainSync { // Select random peer to re-broadcast transactions to. let peer = random::new().gen_range(0, self.peers.len()); trace!(target: "sync", "Re-broadcasting transactions to a random peer."); - self.peers.values_mut().nth(peer).map(|mut peer_info| + self.peers.values_mut().nth(peer).map(|peer_info| peer_info.last_sent_transactions.clear() ); } diff --git a/sync/src/transactions_stats.rs b/sync/src/transactions_stats.rs index 7a1257cba..aa4aa136e 100644 --- a/sync/src/transactions_stats.rs +++ b/sync/src/transactions_stats.rs @@ -57,8 +57,8 @@ impl TransactionsStats { /// Increases number of propagations to given `enodeid`. pub fn propagated(&mut self, hash: &H256, enode_id: Option, current_block_num: BlockNumber) { let enode_id = enode_id.unwrap_or_default(); - let mut stats = self.pending_transactions.entry(*hash).or_insert_with(|| Stats::new(current_block_num)); - let mut count = stats.propagated_to.entry(enode_id).or_insert(0); + let stats = self.pending_transactions.entry(*hash).or_insert_with(|| Stats::new(current_block_num)); + let count = stats.propagated_to.entry(enode_id).or_insert(0); *count = count.saturating_add(1); } From 96b4467f86d2521bc6ec10dcea13b34782080265 Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sun, 15 Oct 2017 20:11:34 +0700 Subject: [PATCH 5/5] Removes redundant `mut` in util --- util/kvdb/src/lib.rs | 6 +++--- util/network/src/discovery.rs | 6 +++--- util/network/src/node_table.rs | 2 +- util/table/src/lib.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/util/kvdb/src/lib.rs b/util/kvdb/src/lib.rs index d10d663ba..b78ab1055 100644 --- a/util/kvdb/src/lib.rs +++ b/util/kvdb/src/lib.rs @@ -254,12 +254,12 @@ impl KeyValueDB for InMemory { for op in ops { match op { DBOp::Insert { col, key, value } => { - if let Some(mut col) = columns.get_mut(&col) { + if let Some(col) = columns.get_mut(&col) { col.insert(key.into_vec(), value); } }, DBOp::InsertCompressed { col, key, value } => { - if let Some(mut col) = columns.get_mut(&col) { + if let Some(col) = columns.get_mut(&col) { let compressed = UntrustedRlp::new(&value).compress(RlpType::Blocks); let mut value = DBValue::new(); value.append_slice(&compressed); @@ -267,7 +267,7 @@ impl KeyValueDB for InMemory { } }, DBOp::Delete { col, key } => { - if let Some(mut col) = columns.get_mut(&col) { + if let Some(col) = columns.get_mut(&col) { col.remove(&*key); } }, diff --git a/util/network/src/discovery.rs b/util/network/src/discovery.rs index 4ff389b3c..6d8e906b7 100644 --- a/util/network/src/discovery.rs +++ b/util/network/src/discovery.rs @@ -156,7 +156,7 @@ impl Discovery { trace!(target: "discovery", "Inserting {:?}", &e); let id_hash = keccak(e.id); let ping = { - let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize]; + let bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize]; let updated = if let Some(node) = bucket.nodes.iter_mut().find(|n| n.address.id == e.id) { node.address = e.clone(); node.timeout = None; @@ -169,7 +169,7 @@ impl Discovery { if bucket.nodes.len() > BUCKET_SIZE { //ping least active node - let mut last = bucket.nodes.back_mut().expect("Last item is always present when len() > 0"); + let last = bucket.nodes.back_mut().expect("Last item is always present when len() > 0"); last.timeout = Some(time::precise_time_ns()); Some(last.address.endpoint.clone()) } else { None } @@ -180,7 +180,7 @@ impl Discovery { } fn clear_ping(&mut self, id: &NodeId) { - let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize]; + let bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize]; if let Some(node) = bucket.nodes.iter_mut().find(|n| &n.address.id == id) { node.timeout = None; } diff --git a/util/network/src/node_table.rs b/util/network/src/node_table.rs index 052657db6..0b7725adc 100644 --- a/util/network/src/node_table.rs +++ b/util/network/src/node_table.rs @@ -253,7 +253,7 @@ impl NodeTable { /// Apply table changes coming from discovery pub fn update(&mut self, mut update: TableUpdates, reserved: &HashSet) { for (_, node) in update.added.drain() { - let mut entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone())); + let entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone())); entry.endpoint = node.endpoint; } for r in update.removed { diff --git a/util/table/src/lib.rs b/util/table/src/lib.rs index e84fce07d..bef453426 100644 --- a/util/table/src/lib.rs +++ b/util/table/src/lib.rs @@ -91,7 +91,7 @@ impl Table if let None = row_map { return None; } - let mut row_map = row_map.unwrap(); + let row_map = row_map.unwrap(); let val = row_map.remove(col); (val, row_map.is_empty()) };