From 3f41186b2e869d0eb5422ff7a0b9ed0324fe9cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 26 Jul 2016 20:31:25 +0200 Subject: [PATCH] Fixing some clippy warnings (#1728) * Fixing warnings * Fixing unnecessary ref * Removing unnecessary operation --- ethcore/src/account_provider.rs | 2 +- ethcore/src/block.rs | 2 +- ethcore/src/block_queue.rs | 8 ++++---- ethcore/src/blockchain/blockchain.rs | 4 ++-- ethcore/src/client/client.rs | 12 ++++++------ ethcore/src/client/config.rs | 2 +- ethcore/src/client/test_client.rs | 6 +++--- ethcore/src/evm/interpreter/mod.rs | 6 +++--- ethcore/src/executive.rs | 10 +++++----- ethcore/src/externalities.rs | 4 ++-- ethcore/src/header.rs | 2 +- ethcore/src/lib.rs | 11 ++++------- ethcore/src/miner/work_notify.rs | 2 +- ethcore/src/pod_account.rs | 4 ++-- ethcore/src/service.rs | 4 ++-- ethcore/src/state.rs | 12 ++++++------ ethcore/src/verification/verification.rs | 4 ++-- parity/configuration.rs | 2 +- parity/helpers.rs | 2 ++ parity/informant.rs | 6 +++--- parity/main.rs | 2 +- util/src/bytes.rs | 2 +- util/src/crypto.rs | 2 +- util/src/error.rs | 2 +- util/src/journaldb/earlymergedb.rs | 2 +- util/src/journaldb/overlayrecentdb.rs | 2 +- util/src/lib.rs | 8 ++------ util/src/network/connection.rs | 2 +- util/src/network/discovery.rs | 4 ++-- util/src/network/host.rs | 6 +++--- util/src/network/session.rs | 6 +++--- util/src/overlaydb.rs | 2 +- util/src/trie/standardmap.rs | 2 +- util/src/trie/triedb.rs | 10 +++++----- util/src/trie/triedbmut.rs | 8 ++++---- util/src/triehash.rs | 2 +- 36 files changed, 81 insertions(+), 86 deletions(-) diff --git a/ethcore/src/account_provider.rs b/ethcore/src/account_provider.rs index 1738fb82a..6e3b9c94d 100644 --- a/ethcore/src/account_provider.rs +++ b/ethcore/src/account_provider.rs @@ -192,7 +192,7 @@ impl AccountProvider { pub fn accounts_info(&self) -> Result, Error> { let r: HashMap = self.sstore.accounts() .into_iter() - .map(|a| (H160(a.clone().into()), self.account_meta(a).unwrap_or(Default::default()))) + .map(|a| (H160(a.clone().into()), self.account_meta(a).unwrap_or_else(|_| Default::default()))) .collect(); Ok(r) } diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 2be475410..d0f62b4a1 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -339,7 +339,7 @@ impl<'x> OpenBlock<'x> { let t = outcome.trace; self.block.traces.as_mut().map(|traces| traces.push(t.expect("self.block.traces.is_some(): so we must be tracing: qed"))); self.block.receipts.push(outcome.receipt); - Ok(&self.block.receipts.last().unwrap()) + Ok(self.block.receipts.last().unwrap()) } Err(x) => Err(From::from(x)) } diff --git a/ethcore/src/block_queue.rs b/ethcore/src/block_queue.rs index 02535fa11..bbe10a1e4 100644 --- a/ethcore/src/block_queue.rs +++ b/ethcore/src/block_queue.rs @@ -284,10 +284,10 @@ impl BlockQueue { /// Check if the block is currently in the queue pub fn block_status(&self, hash: &H256) -> BlockStatus { - if self.processing.read().contains(&hash) { + if self.processing.read().contains(hash) { return BlockStatus::Queued; } - if self.verification.bad.lock().contains(&hash) { + if self.verification.bad.lock().contains(hash) { return BlockStatus::Bad; } BlockStatus::Unknown @@ -340,7 +340,7 @@ impl BlockQueue { bad.reserve(block_hashes.len()); for hash in block_hashes { bad.insert(hash.clone()); - processing.remove(&hash); + processing.remove(hash); } let mut new_verified = VecDeque::new(); @@ -362,7 +362,7 @@ impl BlockQueue { } let mut processing = self.processing.write(); for hash in block_hashes { - processing.remove(&hash); + processing.remove(hash); } } diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 045146c7e..842dd3307 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -512,7 +512,7 @@ impl BlockChain { let _lock = self.insert_lock.lock(); // store block in db - self.blocks_db.put(&hash, &bytes).unwrap(); + self.blocks_db.put(&hash, bytes).unwrap(); let info = self.block_info(bytes); @@ -633,7 +633,7 @@ impl BlockChain { if self.is_known(&first) { Some(AncestryIter { current: first, - chain: &self, + chain: self, }) } else { None diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 18a54de70..f75df22bf 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -281,7 +281,7 @@ impl Client { } // Verify Block Family - let verify_family_result = self.verifier.verify_block_family(&header, &block.bytes, engine, self.chain.deref()); + let verify_family_result = self.verifier.verify_block_family(header, &block.bytes, engine, self.chain.deref()); if let Err(e) = verify_family_result { warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); return Err(()); @@ -299,7 +299,7 @@ impl Client { let last_hashes = self.build_last_hashes(header.parent_hash.clone()); let db = self.state_db.lock().boxed_clone(); - let enact_result = enact_verified(&block, engine, self.tracedb.tracing_enabled(), db, &parent, last_hashes, &self.vm_factory, self.trie_factory.clone()); + let enact_result = enact_verified(block, engine, self.tracedb.tracing_enabled(), db, &parent, last_hashes, &self.vm_factory, self.trie_factory.clone()); if let Err(e) = enact_result { warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); return Err(()); @@ -307,7 +307,7 @@ impl Client { // Final Verification let locked_block = enact_result.unwrap(); - if let Err(e) = self.verifier.verify_block_final(&header, locked_block.block().header()) { + if let Err(e) = self.verifier.verify_block_final(header, locked_block.block().header()) { warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); return Err(()); } @@ -468,7 +468,7 @@ impl Client { pub fn import_queued_transactions(&self, transactions: &[Bytes]) -> usize { let _timer = PerfTimer::new("import_queued_transactions"); self.queue_transactions.fetch_sub(transactions.len(), AtomicOrdering::SeqCst); - let txs = transactions.iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect(); + let txs = transactions.iter().filter_map(|bytes| UntrustedRlp::new(bytes).as_val().ok()).collect(); let results = self.miner.import_external_transactions(self, txs); results.len() } @@ -684,7 +684,7 @@ impl BlockChainClient for Client { } fn block(&self, id: BlockID) -> Option { - if let &BlockID::Pending = &id { + if let BlockID::Pending = id { if let Some(block) = self.miner.pending_block() { return Some(block.rlp_bytes(Seal::Without)); } @@ -703,7 +703,7 @@ impl BlockChainClient for Client { } fn block_total_difficulty(&self, id: BlockID) -> Option { - if let &BlockID::Pending = &id { + if let BlockID::Pending = id { if let Some(block) = self.miner.pending_block() { return Some(*block.header.difficulty() + self.block_total_difficulty(BlockID::Latest).expect("blocks in chain have details; qed")); } diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs index 4cfd04e2d..90b4ac405 100644 --- a/ethcore/src/client/config.rs +++ b/ethcore/src/client/config.rs @@ -46,7 +46,7 @@ impl FromStr for DatabaseCompactionProfile { match s { "ssd" | "default" => Ok(DatabaseCompactionProfile::Default), "hdd" => Ok(DatabaseCompactionProfile::HDD), - _ => Err(format!("Invalid compaction profile given. Expected hdd/ssd (default).")), + _ => Err("Invalid compaction profile given. Expected hdd/ssd (default).".into()), } } } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index e0280b388..926777222 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -190,7 +190,7 @@ impl TestBlockChainClient { gas_price: U256::one(), nonce: U256::zero() }; - let signed_tx = tx.sign(&keypair.secret()); + let signed_tx = tx.sign(keypair.secret()); txs.append(&signed_tx); txs.out() }, @@ -366,8 +366,8 @@ impl BlockChainClient for TestBlockChainClient { fn block_body(&self, id: BlockID) -> Option { self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| { let mut stream = RlpStream::new_list(2); - stream.append_raw(Rlp::new(&r).at(1).as_raw(), 1); - stream.append_raw(Rlp::new(&r).at(2).as_raw(), 1); + stream.append_raw(Rlp::new(r).at(1).as_raw(), 1); + stream.append_raw(Rlp::new(r).at(2).as_raw(), 1); stream.out() })) } diff --git a/ethcore/src/evm/interpreter/mod.rs b/ethcore/src/evm/interpreter/mod.rs index a43592c6d..cf715a378 100644 --- a/ethcore/src/evm/interpreter/mod.rs +++ b/ethcore/src/evm/interpreter/mod.rs @@ -96,13 +96,13 @@ impl evm::Evm for Interpreter { self.mem.clear(); let code = ¶ms.code.as_ref().unwrap(); - let valid_jump_destinations = self.find_jump_destinations(&code); + let valid_jump_destinations = self.find_jump_destinations(code); let mut gasometer = Gasometer::::new(try!(Cost::from_u256(params.gas))); let mut stack = VecStack::with_capacity(ext.schedule().stack_limit, U256::zero()); let mut reader = CodeReader { position: 0, - code: &code + code: code }; let infos = &*instructions::INSTRUCTIONS; @@ -274,7 +274,7 @@ impl Interpreter { return Ok(InstructionResult::Ok); } - let create_result = ext.create(&gas.as_u256(), &endowment, &contract_code); + let create_result = ext.create(&gas.as_u256(), &endowment, contract_code); return match create_result { ContractCreateResult::Created(address, gas_left) => { stack.push(address_to_u256(address)); diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index ef6af43b3..240ecf3c6 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -370,7 +370,7 @@ impl<'a> Executive<'a> { let gas = params.gas; let created = params.address.clone(); - let mut subvmtracer = vm_tracer.prepare_subtrace(¶ms.code.as_ref().expect("two ways into create (Externalities::create and Executive::transact_with_tracer); both place `Some(...)` `code` in `params`; qed")); + let mut subvmtracer = vm_tracer.prepare_subtrace(params.code.as_ref().expect("two ways into create (Externalities::create and Executive::transact_with_tracer); both place `Some(...)` `code` in `params`; qed")); let res = { self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::InitContract(trace_output.as_mut()), &mut subtracer, &mut subvmtracer) @@ -1009,7 +1009,7 @@ mod tests { gas: U256::from(100_000), gas_price: U256::zero(), nonce: U256::zero() - }.sign(&keypair.secret()); + }.sign(keypair.secret()); let sender = t.sender().unwrap(); let contract = contract_address(&sender, &U256::zero()); @@ -1076,7 +1076,7 @@ mod tests { gas: U256::from(100_000), gas_price: U256::zero(), nonce: U256::one() - }.sign(&keypair.secret()); + }.sign(keypair.secret()); let sender = t.sender().unwrap(); let mut state_result = get_temp_state(); @@ -1109,7 +1109,7 @@ mod tests { gas: U256::from(80_001), gas_price: U256::zero(), nonce: U256::zero() - }.sign(&keypair.secret()); + }.sign(keypair.secret()); let sender = t.sender().unwrap(); let mut state_result = get_temp_state(); @@ -1144,7 +1144,7 @@ mod tests { gas: U256::from(100_000), gas_price: U256::one(), nonce: U256::zero() - }.sign(&keypair.secret()); + }.sign(keypair.secret()); let sender = t.sender().unwrap(); let mut state_result = get_temp_state(); diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 6dea52037..74bceca98 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -272,7 +272,7 @@ impl<'a, T, V> Ext for Externalities<'a, T, V> where T: 'a + Tracer, V: 'a + VMT } fn env_info(&self) -> &EnvInfo { - &self.env_info + self.env_info } fn depth(&self) -> usize { @@ -455,7 +455,7 @@ mod tests { { let vm_factory = Default::default(); let mut ext = Externalities::new(state, &setup.env_info, &*setup.engine, &vm_factory, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer); - ext.suicide(&refund_account); + ext.suicide(refund_account); } assert_eq!(setup.sub_state.suicides.len(), 1); diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index d5272ce2e..43b4537c4 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -234,7 +234,7 @@ impl Header { s.append(&self.extra_data); if let Seal::With = with_seal { for b in &self.seal { - s.append_raw(&b, 1); + s.append_raw(b, 1); } } } diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index b8de63adb..147232683 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -15,23 +15,20 @@ // along with Parity. If not, see . #![warn(missing_docs)] +#![cfg_attr(feature="benches", feature(test))] #![cfg_attr(feature="dev", feature(plugin))] #![cfg_attr(feature="dev", plugin(clippy))] -// Clippy config -// TODO [todr] not really sure +// Clippy settings +// Most of the time much more readable #![cfg_attr(feature="dev", allow(needless_range_loop))] // Shorter than if-else #![cfg_attr(feature="dev", allow(match_bool))] -// Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref. +// Keeps consistency (all lines with `.clone()`). #![cfg_attr(feature="dev", allow(clone_on_copy))] -// In most cases it expresses function flow better -#![cfg_attr(feature="dev", allow(if_not_else))] // TODO [todr] a lot of warnings to be fixed -#![cfg_attr(feature="dev", allow(needless_borrow))] #![cfg_attr(feature="dev", allow(assign_op_pattern))] -#![cfg_attr(feature="benches", feature(test))] //! Ethcore library //! diff --git a/ethcore/src/miner/work_notify.rs b/ethcore/src/miner/work_notify.rs index b9952e14b..557f02f31 100644 --- a/ethcore/src/miner/work_notify.rs +++ b/ethcore/src/miner/work_notify.rs @@ -35,7 +35,7 @@ pub struct WorkPoster { impl WorkPoster { pub fn new(urls: &[String]) -> Self { let urls = urls.into_iter().filter_map(|u| { - match Url::parse(&u) { + match Url::parse(u) { Ok(url) => Some(url), Err(e) => { warn!("Error parsing URL {} : {}", u, e); diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index 9b6d953b2..833ae9b6b 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -143,8 +143,8 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option for ClientIoHandler { fn message(&self, _io: &IoContext, net_message: &ClientIoMessage) { match *net_message { ClientIoMessage::BlockVerified => { self.client.import_verified_blocks(); } - ClientIoMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(&transactions); } + ClientIoMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(transactions); } _ => {} // ignore other messages } } @@ -175,7 +175,7 @@ mod tests { let service = ClientService::start( ClientConfig::default(), get_test_spec(), - &temp_path.as_path(), + temp_path.as_path(), Arc::new(Miner::with_spec(get_test_spec())), ); assert!(service.is_ok()); diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index effda5f0f..ca19101d8 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -122,7 +122,7 @@ impl State { fn insert_cache(&self, address: &Address, account: Option) { if let Some(ref mut snapshot) = self.snapshots.borrow_mut().last_mut() { - if !snapshot.contains_key(&address) { + if !snapshot.contains_key(address) { snapshot.insert(address.clone(), self.cache.borrow_mut().insert(address.clone(), account)); return; } @@ -132,7 +132,7 @@ impl State { fn note_cache(&self, address: &Address) { if let Some(ref mut snapshot) = self.snapshots.borrow_mut().last_mut() { - if !snapshot.contains_key(&address) { + if !snapshot.contains_key(address) { snapshot.insert(address.clone(), self.cache.borrow().get(address).cloned()); } } @@ -151,7 +151,7 @@ impl State { /// Create a new contract at address `contract`. If there is already an account at the address /// it will have its code reset, ready for `init_code()`. pub fn new_contract(&mut self, contract: &Address, balance: U256) { - self.insert_cache(&contract, Some(Account::new_contract(balance, self.account_start_nonce))); + self.insert_cache(contract, Some(Account::new_contract(balance, self.account_start_nonce))); } /// Remove an existing account. @@ -162,7 +162,7 @@ impl State { /// Determine whether an account exists. pub fn exists(&self, a: &Address) -> bool { let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR); - self.cache.borrow().get(&a).unwrap_or(&None).is_some() || db.contains(&a) + self.cache.borrow().get(a).unwrap_or(&None).is_some() || db.contains(a) } /// Get the balance of account `a`. @@ -329,7 +329,7 @@ impl State { let have_key = self.cache.borrow().contains_key(a); if !have_key { let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR); - self.insert_cache(a, db.get(&a).map(Account::from_rlp)) + self.insert_cache(a, db.get(a).map(Account::from_rlp)) } if require_code { if let Some(ref mut account) = self.cache.borrow_mut().get_mut(a).unwrap().as_mut() { @@ -350,7 +350,7 @@ impl State { let have_key = self.cache.borrow().contains_key(a); if !have_key { let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR); - self.insert_cache(a, db.get(&a).map(Account::from_rlp)) + self.insert_cache(a, db.get(a).map(Account::from_rlp)) } else { self.note_cache(a); } diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index c6b75416b..d3e782764 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -350,7 +350,7 @@ mod tests { gas: U256::from(30_000), gas_price: U256::from(40_000), nonce: U256::one() - }.sign(&keypair.secret()); + }.sign(keypair.secret()); let tr2 = Transaction { action: Action::Create, @@ -359,7 +359,7 @@ mod tests { gas: U256::from(30_000), gas_price: U256::from(40_000), nonce: U256::from(2) - }.sign(&keypair.secret()); + }.sign(keypair.secret()); let good_transactions = [ tr1.clone(), tr2.clone() ]; diff --git a/parity/configuration.rs b/parity/configuration.rs index 8ac7a2af0..29301dfd3 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -522,7 +522,7 @@ impl Configuration { self.args.flag_geth || self.args.flag_no_signer; - return !signer_disabled; + !signer_disabled } } diff --git a/parity/helpers.rs b/parity/helpers.rs index 05c6e54ea..1018437c5 100644 --- a/parity/helpers.rs +++ b/parity/helpers.rs @@ -184,6 +184,7 @@ pub fn default_network_config() -> ::util::NetworkConfiguration { } } +#[cfg_attr(feature = "dev", allow(too_many_arguments))] pub fn to_client_config( cache_config: &CacheConfig, dirs: &Directories, @@ -356,6 +357,7 @@ mod tests { } #[test] + #[cfg_attr(feature = "dev", allow(float_cmp))] fn test_to_price() { assert_eq!(to_price("1").unwrap(), 1.0); assert_eq!(to_price("2.3").unwrap(), 2.3); diff --git a/parity/informant.rs b/parity/informant.rs index ef83b8b77..429c8e28e 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -108,12 +108,12 @@ impl Informant { info!(target: "import", "{} {} {}", match importing { - true => format!("Syncing {} {} {} {}+{} Qed", + true => format!("Syncing {} {} {} {}+{} Qed", paint(White.bold(), format!("{:>8}", format!("#{}", chain_info.best_block_number))), paint(White.bold(), format!("{}", chain_info.best_block_hash)), { let last_report = match write_report.deref() { &Some(ref last_report) => last_report.clone(), _ => ClientReport::default() }; - format!("{} blk/s {} tx/s {} Mgas/s", + format!("{} blk/s {} tx/s {} Mgas/s", paint(Yellow.bold(), format!("{:4}", ((report.blocks_imported - last_report.blocks_imported) * 1000) as u64 / elapsed.as_milliseconds())), paint(Yellow.bold(), format!("{:4}", ((report.transactions_applied - last_report.transactions_applied) * 1000) as u64 / elapsed.as_milliseconds())), paint(Yellow.bold(), format!("{:3}", ((report.gas_processed - last_report.gas_processed) / From::from(elapsed.as_milliseconds() * 1000)).low_u64())) @@ -160,7 +160,7 @@ impl ChainNotify for Informant { let importing = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3 || self.sync.as_ref().map_or(false, |s| s.status().is_major_syncing()); if Instant::now() > *last_import + Duration::from_secs(1) && !importing { - if let Some(block) = imported.last().and_then(|h| self.client.block(BlockID::Hash(h.clone()))) { + if let Some(block) = imported.last().and_then(|h| self.client.block(BlockID::Hash(*h))) { let view = BlockView::new(&block); let header = view.header(); let tx_count = view.transactions_count(); diff --git a/parity/main.rs b/parity/main.rs index b5c68d27b..4c1aae65e 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -113,7 +113,7 @@ fn start() -> Result { fn main() { // just redirect to the sync::main() - if std::env::args().nth(1).map(|arg| arg == "sync").unwrap_or(false) { + if std::env::args().nth(1).map_or(false, |arg| arg == "sync") { sync::main(); return; } diff --git a/util/src/bytes.rs b/util/src/bytes.rs index 7426609d6..dfd21fd90 100644 --- a/util/src/bytes.rs +++ b/util/src/bytes.rs @@ -195,7 +195,7 @@ pub trait Populatable { /// If `d` is smaller, will leave some bytes untouched. fn copy_raw(&mut self, d: &[u8]) { use std::io::Write; - self.as_slice_mut().write(&d).unwrap(); + self.as_slice_mut().write(d).unwrap(); } /// Copies the raw representation of an object `d` to `self`, overwriting as necessary. diff --git a/util/src/crypto.rs b/util/src/crypto.rs index b92bb2bae..44b3b5508 100644 --- a/util/src/crypto.rs +++ b/util/src/crypto.rs @@ -273,7 +273,7 @@ pub mod ecdh { let publ = try!(key::PublicKey::from_slice(context, &pdata)); // no way to create SecretKey from raw byte array. let sec: &key::SecretKey = unsafe { ::std::mem::transmute(secret) }; - let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec); + let shared = ecdh::SharedSecret::new_raw(context, &publ, sec); let mut s = crypto::Secret::new(); s.copy_from_slice(&shared[0..32]); diff --git a/util/src/error.rs b/util/src/error.rs index f5048445b..bc57cfc55 100644 --- a/util/src/error.rs +++ b/util/src/error.rs @@ -82,7 +82,7 @@ impl fmt::Display for UtilError { UtilError::BaseData(ref err) => f.write_fmt(format_args!("{}", err)), UtilError::Network(ref err) => f.write_fmt(format_args!("{}", err)), UtilError::Decoder(ref err) => f.write_fmt(format_args!("{}", err)), - UtilError::SimpleString(ref msg) => f.write_str(&msg), + UtilError::SimpleString(ref msg) => f.write_str(msg), UtilError::BadSize => f.write_str("Bad input size."), UtilError::Snappy(ref err) => f.write_fmt(format_args!("{}", err)), } diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index 45e9202b4..2fe4ca10d 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -131,7 +131,7 @@ impl EarlyMergeDB { // this is the first entry for this node in the journal. if backing.get(h).expect("Low-level database error. Some issue with your hard disk?").is_some() { // already in the backing DB. start counting, and remember it was already in. - Self::set_already_in(batch, &h); + Self::set_already_in(batch, h); refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: true}); if trace { trace!(target: "jdb.fine", " insert({}): New to queue, in DB: Recording and inserting into queue", h); diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index a4d3005a8..082692403 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -193,7 +193,7 @@ impl OverlayRecentDB { #[inline] fn to_short_key(key: &H256) -> H256 { let mut k = H256::new(); - &mut k[0..DB_PREFIX_LEN].copy_from_slice(&key[0..DB_PREFIX_LEN]); + k[0..DB_PREFIX_LEN].copy_from_slice(&key[0..DB_PREFIX_LEN]); k } } diff --git a/util/src/lib.rs b/util/src/lib.rs index bcd9df971..c2899b851 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -19,20 +19,16 @@ #![cfg_attr(feature="dev", plugin(clippy))] // Clippy settings -// TODO [todr] not really sure +// Most of the time much more readable #![cfg_attr(feature="dev", allow(needless_range_loop))] // Shorter than if-else #![cfg_attr(feature="dev", allow(match_bool))] // We use that to be more explicit about handled cases #![cfg_attr(feature="dev", allow(match_same_arms))] -// Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref. +// Keeps consistency (all lines with `.clone()`). #![cfg_attr(feature="dev", allow(clone_on_copy))] -// In most cases it expresses function flow better -#![cfg_attr(feature="dev", allow(if_not_else))] // TODO [todr] a lot of warnings to be fixed -#![cfg_attr(feature="dev", allow(needless_borrow))] #![cfg_attr(feature="dev", allow(assign_op_pattern))] -#![cfg_attr(feature="dev", allow(unnecessary_operation))] //! Ethcore-util library diff --git a/util/src/network/connection.rs b/util/src/network/connection.rs index 86e4249d7..cbc9f39d7 100644 --- a/util/src/network/connection.rs +++ b/util/src/network/connection.rs @@ -355,7 +355,7 @@ impl EncryptedConnection { self.encoder.encrypt(&mut RefReadBuffer::new(&header), &mut RefWriteBuffer::new(&mut packet), false).expect("Invalid length or padding"); EncryptedConnection::update_mac(&mut self.egress_mac, &mut self.mac_encoder, &packet[0..16]); self.egress_mac.clone().finalize(&mut packet[16..32]); - self.encoder.encrypt(&mut RefReadBuffer::new(&payload), &mut RefWriteBuffer::new(&mut packet[32..(32 + len)]), padding == 0).expect("Invalid length or padding"); + self.encoder.encrypt(&mut RefReadBuffer::new(payload), &mut RefWriteBuffer::new(&mut packet[32..(32 + len)]), padding == 0).expect("Invalid length or padding"); if padding != 0 { let pad = [0u8; 16]; self.encoder.encrypt(&mut RefReadBuffer::new(&pad[0..padding]), &mut RefWriteBuffer::new(&mut packet[(32 + len)..(32 + len + padding)]), true).expect("Invalid length or padding"); diff --git a/util/src/network/discovery.rs b/util/src/network/discovery.rs index 5670c4cfa..d71ff1252 100644 --- a/util/src/network/discovery.rs +++ b/util/src/network/discovery.rs @@ -167,7 +167,7 @@ impl Discovery { } fn clear_ping(&mut self, id: &NodeId) { - let mut bucket = self.node_buckets.get_mut(Discovery::distance(&self.id, &id) as usize).unwrap(); + let mut bucket = self.node_buckets.get_mut(Discovery::distance(&self.id, id) as usize).unwrap(); if let Some(node) = bucket.nodes.iter_mut().find(|n| &n.address.id == id) { node.timeout = None; } @@ -438,7 +438,7 @@ impl Discovery { } let mut packets = Discovery::prepare_neighbours_packets(&nearest); for p in packets.drain(..) { - self.send_packet(PACKET_NEIGHBOURS, &from, &p); + self.send_packet(PACKET_NEIGHBOURS, from, &p); } trace!(target: "discovery", "Sent {} Neighbours to {:?}", nearest.len(), &from); Ok(None) diff --git a/util/src/network/host.rs b/util/src/network/host.rs index f90e8cd57..bcad97cfe 100644 --- a/util/src/network/host.rs +++ b/util/src/network/host.rs @@ -355,11 +355,11 @@ impl Host { let keys = if let Some(ref secret) = config.use_secret { KeyPair::from_secret(secret.clone()).unwrap() } else { - config.config_path.clone().and_then(|ref p| load_key(&Path::new(&p))) + config.config_path.clone().and_then(|ref p| load_key(Path::new(&p))) .map_or_else(|| { let key = KeyPair::create().unwrap(); if let Some(path) = config.config_path.clone() { - save_key(&Path::new(&path), &key.secret()); + save_key(Path::new(&path), key.secret()); } key }, @@ -1099,7 +1099,7 @@ fn save_key(path: &Path, key: &Secret) { return; } }; - if let Err(e) = restrict_permissions_owner(&path) { + if let Err(e) = restrict_permissions_owner(path) { warn!(target: "network", "Failed to modify permissions of the file (chmod: {})", e); } if let Err(e) = file.write(&key.hex().into_bytes()) { diff --git a/util/src/network/session.rs b/util/src/network/session.rs index c19dfbcf8..d90ecb062 100644 --- a/util/src/network/session.rs +++ b/util/src/network/session.rs @@ -128,7 +128,7 @@ impl Session { nonce: &H256, stats: Arc, host: &HostInfo) -> Result where Message: Send + Clone { let originated = id.is_some(); - let mut handshake = Handshake::new(token, id, socket, &nonce, stats).expect("Can't create handshake"); + let mut handshake = Handshake::new(token, id, socket, nonce, stats).expect("Can't create handshake"); try!(handshake.start(io, host, originated)); Ok(Session { state: State::Handshake(handshake), @@ -313,7 +313,7 @@ impl Session { self.connection().token() } - fn read_packet(&mut self, io: &IoContext, packet: Packet, host: &HostInfo) -> Result + fn read_packet(&mut self, io: &IoContext, packet: Packet, host: &HostInfo) -> Result where Message: Send + Sync + Clone { if packet.data.len() < 2 { return Err(From::from(NetworkError::BadProtocol)); @@ -381,7 +381,7 @@ impl Session { self.send(io, rlp) } - fn read_hello(&mut self, io: &IoContext, rlp: &UntrustedRlp, host: &HostInfo) -> Result<(), UtilError> + fn read_hello(&mut self, io: &IoContext, rlp: &UntrustedRlp, host: &HostInfo) -> Result<(), UtilError> where Message: Send + Sync + Clone { let protocol = try!(rlp.val_at::(0)); let client_version = try!(rlp.val_at::(1)); diff --git a/util/src/overlaydb.rs b/util/src/overlaydb.rs index 63ec3dd50..fcf08795b 100644 --- a/util/src/overlaydb.rs +++ b/util/src/overlaydb.rs @@ -168,7 +168,7 @@ impl OverlayDB { pub fn revert(&mut self) { self.overlay.clear(); } /// Get the number of references that would be committed. - pub fn commit_refs(&self, key: &H256) -> i32 { self.overlay.raw(&key).map_or(0, |&(_, refs)| refs) } + pub fn commit_refs(&self, key: &H256) -> i32 { self.overlay.raw(key).map_or(0, |&(_, refs)| refs) } /// Get the refs and value of the given key. fn payload(&self, key: &H256) -> Option<(Bytes, u32)> { diff --git a/util/src/trie/standardmap.rs b/util/src/trie/standardmap.rs index 216d29ad0..28e4c76f7 100644 --- a/util/src/trie/standardmap.rs +++ b/util/src/trie/standardmap.rs @@ -106,7 +106,7 @@ impl StandardMap { Alphabet::All => Self::random_bytes(self.min_key, self.journal_key, seed), Alphabet::Low => Self::random_word(low, self.min_key, self.journal_key, seed), Alphabet::Mid => Self::random_word(mid, self.min_key, self.journal_key, seed), - Alphabet::Custom(ref a) => Self::random_word(&a, self.min_key, self.journal_key, seed), + Alphabet::Custom(ref a) => Self::random_word(a, self.min_key, self.journal_key, seed), }; let v = match self.value_mode { ValueMode::Mirror => k.clone(), diff --git a/util/src/trie/triedb.rs b/util/src/trie/triedb.rs index a50904cc1..9feeb0370 100644 --- a/util/src/trie/triedb.rs +++ b/util/src/trie/triedb.rs @@ -132,7 +132,7 @@ impl<'db> TrieDB<'db> { /// Get the data of the root node. fn root_data(&self) -> &[u8] { - self.db.get(&self.root).expect("Trie root not found!") + self.db.get(self.root).expect("Trie root not found!") } /// Get the root node as a `Node`. @@ -184,7 +184,7 @@ impl<'db> TrieDB<'db> { /// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists. fn do_lookup<'a, 'key>(&'a self, key: &NibbleSlice<'key>) -> Option<&'a [u8]> where 'a: 'key { let root_rlp = self.root_data(); - self.get_from_node(&root_rlp, key) + self.get_from_node(root_rlp, key) } /// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no @@ -340,7 +340,7 @@ impl<'db> Trie for TrieDB<'db> { Box::new(TrieDB::iter(self)) } - fn root(&self) -> &H256 { &self.root } + fn root(&self) -> &H256 { self.root } fn contains(&self, key: &[u8]) -> bool { self.get(key).is_some() @@ -354,7 +354,7 @@ impl<'db> Trie for TrieDB<'db> { impl<'db> fmt::Debug for TrieDB<'db> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(writeln!(f, "c={:?} [", self.hash_count)); - let root_rlp = self.db.get(&self.root).expect("Trie root not found!"); + let root_rlp = self.db.get(self.root).expect("Trie root not found!"); try!(self.fmt_all(Node::decoded(root_rlp), f, 0)); writeln!(f, "]") } @@ -373,7 +373,7 @@ fn iterator() { { let mut t = TrieDBMut::new(&mut memdb, &mut root); for x in &d { - t.insert(&x, &x); + t.insert(x, x); } } assert_eq!(d.iter().map(|i|i.to_vec()).collect::>(), TrieDB::new(&memdb, &root).unwrap().iter().map(|x|x.0).collect::>()); diff --git a/util/src/trie/triedbmut.rs b/util/src/trie/triedbmut.rs index c50a66cc8..68d56f4d8 100644 --- a/util/src/trie/triedbmut.rs +++ b/util/src/trie/triedbmut.rs @@ -401,7 +401,7 @@ impl<'a> TrieDBMut<'a> { /// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists. fn do_db_lookup<'x, 'key>(&'x self, hash: &H256, key: NibbleSlice<'key>) -> Option<&'x [u8]> where 'x: 'key { - self.db.get(hash).and_then(|node_rlp| self.get_from_db_node(&node_rlp, key)) + self.db.get(hash).and_then(|node_rlp| self.get_from_db_node(node_rlp, key)) } /// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no @@ -868,7 +868,7 @@ impl<'a> TrieDBMut<'a> { impl<'a> TrieMut for TrieDBMut<'a> { fn root(&mut self) -> &H256 { self.commit(); - &self.root + self.root } fn is_empty(&self) -> bool { @@ -938,7 +938,7 @@ mod tests { for i in 0..v.len() { let key: &[u8]= &v[i].0; let val: &[u8] = &v[i].1; - t.insert(&key, &val); + t.insert(key, val); } t } @@ -946,7 +946,7 @@ mod tests { fn unpopulate_trie<'db>(t: &mut TrieDBMut<'db>, v: &[(Vec, Vec)]) { for i in v { let key: &[u8]= &i.0; - t.remove(&key); + t.remove(key); } } diff --git a/util/src/triehash.rs b/util/src/triehash.rs index e95c3b5f9..f49b588d4 100644 --- a/util/src/triehash.rs +++ b/util/src/triehash.rs @@ -213,7 +213,7 @@ fn hash256rlp(input: &[(Vec, Vec)], pre_len: usize, stream: &mut RlpStre .skip(1) // get minimum number of shared nibbles between first and each successive .fold(key.len(), | acc, &(ref k, _) | { - cmp::min(key.shared_prefix_len(&k), acc) + cmp::min(key.shared_prefix_len(k), acc) }); // if shared prefix is higher than current prefix append its