From 81df97a737294f927162e2295a957118351caa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sat, 18 Jun 2016 15:11:10 +0200 Subject: [PATCH] Fixing warnings (#1321) --- ethcore/src/state.rs | 6 +++--- ethcore/src/tests/client.rs | 1 + ethcore/src/tests/helpers.rs | 4 ++-- sync/src/chain.rs | 2 +- sync/src/lib.rs | 5 ++--- util/src/network/host.rs | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index dc9ca582c..bdf754f3a 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -229,11 +229,11 @@ impl State { // collect all the addresses which have changed. let addresses = self.cache.borrow().iter().map(|(addr, _)| addr.clone()).collect::>(); - for a in addresses.iter() { - if self.code(a).map(|c| c.sha3() == broken_dao).unwrap_or(false) { + for a in &addresses { + if self.code(a).map_or(false, |c| c.sha3() == broken_dao) { // Figure out if the balance has been reduced. let maybe_original = SecTrieDB::new(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR).get(&a).map(Account::from_rlp); - if maybe_original.map(|original| *original.balance() > self.balance(a)).unwrap_or(false) { + if maybe_original.map_or(false, |original| *original.balance() > self.balance(a)) { return Err(Error::Transaction(TransactionError::DAORescue)); } } diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index a5459035e..f2ab62840 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -113,6 +113,7 @@ fn can_collect_garbage() { } #[test] +#[cfg_attr(feature="dev", allow(useless_vec))] fn can_generate_gas_price_statistics() { let client_result = generate_dummy_client_with_data(16, 1, &vec_into![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); let client = client_result.reference(); diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 151d53bba..48ca14bbf 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -140,7 +140,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa } pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult> { - generate_dummy_client_with_spec_and_data(Spec::new_test, block_number, 0, &(vec![])) + generate_dummy_client_with_spec_and_data(Spec::new_test, block_number, 0, &[]) } pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> GuardedTempResult> { @@ -205,7 +205,7 @@ pub fn generate_dummy_client_with_spec_and_data(get_test_spec: F, block_numbe if let Err(e) = client.import_block(b.rlp_bytes()) { panic!("error importing block which is valid by definition: {:?}", e); } - + last_header = BlockView::new(&b.rlp_bytes()).header(); db = b.drain(); } diff --git a/sync/src/chain.rs b/sync/src/chain.rs index ef05ec9d1..54e4aa7a6 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1170,7 +1170,7 @@ impl ChainSync { .expect("chain.tree_route and chain.find_uncles only return hahses of blocks that are in the blockchain. qed.")).number(); hash_rlp.append(&block_hash); hash_rlp.append(&number); - rlp_stream.append_raw(&hash_rlp.as_raw(), 1); + rlp_stream.append_raw(hash_rlp.as_raw(), 1); } Some(rlp_stream.out()) } diff --git a/sync/src/lib.rs b/sync/src/lib.rs index cabc55ace..86f70ff0a 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -124,12 +124,11 @@ impl EthSync { /// Creates and register protocol with the network service pub fn new(config: SyncConfig, chain: Arc) -> Arc { let sync = ChainSync::new(config, chain.deref()); - let sync = Arc::new(EthSync { + Arc::new(EthSync { chain: chain, sync: RwLock::new(sync), io_channel: RwLock::new(IoChannel::disconnected()), - }); - sync + }) } /// Register protocol with the network service diff --git a/util/src/network/host.rs b/util/src/network/host.rs index d859db1c3..aef56fc09 100644 --- a/util/src/network/host.rs +++ b/util/src/network/host.rs @@ -252,7 +252,7 @@ impl<'s, Message> NetworkContext<'s, Message> where Message: Send + Sync + Clone /// Check if the session is still active. pub fn is_expired(&self) -> bool { - self.session.as_ref().map(|s| s.lock().unwrap().expired()).unwrap_or(false) + self.session.as_ref().map_or(false, |s| s.lock().unwrap().expired()) } /// Register a new IO timer. 'IoHandler::timeout' will be called with the token. @@ -643,7 +643,7 @@ impl Host where Message: Send + Sync + Clone { } if s.done() { io.deregister_stream(token).unwrap_or_else(|e| debug!("Error deregistering stream: {:?}", e)); - } + } } } @@ -769,7 +769,7 @@ impl Host where Message: Send + Sync + Clone { } if deregister { io.deregister_stream(token).unwrap_or_else(|e| debug!("Error deregistering stream: {:?}", e)); - } + } } fn update_nodes(&self, io: &IoContext>, node_changes: TableUpdates) {