From c746f0e62cb31a7af9e61669141be7ed32692f0b Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Tue, 19 Jan 2016 13:47:30 +0100 Subject: [PATCH] Fixing all clippy lints --- Cargo.toml | 1 + src/account.rs | 4 ++-- src/account_diff.rs | 4 ++-- src/blockchain.rs | 3 ++- src/evm/interpreter.rs | 8 ++++---- src/evm/tests.rs | 6 +++--- src/externalities.rs | 2 +- src/lib.rs | 5 +++-- src/pod_state.rs | 8 ++++---- src/spec.rs | 2 +- src/sync/range_collection.rs | 1 + src/sync/tests.rs | 17 +++++++---------- src/tests/executive.rs | 6 +++--- src/tests/state.rs | 2 +- src/tests/test_common.rs | 4 ++-- src/tests/transaction.rs | 8 ++++---- src/verification.rs | 8 ++++---- util/Cargo.toml | 1 + util/src/hash.rs | 5 +++-- util/src/journaldb.rs | 2 +- util/src/json_aid.rs | 8 ++++---- util/src/lib.rs | 2 ++ util/src/rlp/tests.rs | 28 ++++++++++++++-------------- util/src/trie/triedbmut.rs | 14 +++++++------- util/src/uint.rs | 5 +++-- 25 files changed, 80 insertions(+), 74 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0583aa78f..a01bfd594 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ time = "0.1" evmjit = { path = "rust-evmjit", optional = true } ethash = { path = "ethash" } num_cpus = "0.2" +clippy = "*" [features] jit = ["evmjit"] diff --git a/src/account.rs b/src/account.rs index c572b5589..b0fbf3f85 100644 --- a/src/account.rs +++ b/src/account.rs @@ -248,8 +248,8 @@ mod tests { let a = Account::from_rlp(&rlp); assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2"); - assert_eq!(a.storage_at(&mut db, &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64))); - assert_eq!(a.storage_at(&mut db, &H256::from(&U256::from(0x01u64))), H256::new()); + assert_eq!(a.storage_at(&db, &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64))); + assert_eq!(a.storage_at(&db, &H256::from(&U256::from(0x01u64))), H256::new()); } #[test] diff --git a/src/account_diff.rs b/src/account_diff.rs index fece8c5d7..3b01da522 100644 --- a/src/account_diff.rs +++ b/src/account_diff.rs @@ -62,8 +62,8 @@ impl AccountDiff { code: Diff::new(pre.code.clone(), post.code.clone()), storage: storage.into_iter().map(|k| (k.clone(), Diff::new( - pre.storage.get(&k).cloned().unwrap_or(H256::new()), - post.storage.get(&k).cloned().unwrap_or(H256::new()) + pre.storage.get(&k).cloned().unwrap_or_else(H256::new), + post.storage.get(&k).cloned().unwrap_or_else(H256::new) ))).collect(), }; if r.balance.is_same() && r.nonce.is_same() && r.code.is_same() && r.storage.is_empty() { diff --git a/src/blockchain.rs b/src/blockchain.rs index 6700391ad..516f18230 100644 --- a/src/blockchain.rs +++ b/src/blockchain.rs @@ -179,7 +179,7 @@ impl BlockProvider for BlockChain { const COLLECTION_QUEUE_SIZE: usize = 2; const MIN_CACHE_SIZE: usize = 1; -const MAX_CACHE_SIZE: usize = 1024 * 1024 * 1; +const MAX_CACHE_SIZE: usize = 1024 * 1024; impl BlockChain { /// Create new instance of blockchain from given Genesis @@ -659,6 +659,7 @@ mod tests { } #[test] + #[allow(cyclomatic_complexity)] fn test_small_fork() { let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a059262c330941f3fe2a34d16d6e3c7b30d2ceb37c6a0e9a994c494ee1a61d2410885aa4c8bf8e56e264c0c0".from_hex().unwrap(); let b1 = "f90261f901f9a05716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0cb52de543653d86ccd13ba3ddf8b052525b04231c6884a4db3188a184681d878a0e78628dd45a1f8dc495594d83b76c588a3ee67463260f8b7d4a42f574aeab29aa0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884562791e580a051b3ecba4e3f2b49c11d42dd0851ec514b1be3138080f72a2b6e83868275d98f8877671f479c414b47f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ca09e2709d7ec9bbe6b1bbbf0b2088828d14cd5e8642a1fee22dc74bfa89761a7f9a04bd8813dee4be989accdb708b1c2e325a7e9c695a8024e30e89d6c644e424747c0".from_hex().unwrap(); diff --git a/src/evm/interpreter.rs b/src/evm/interpreter.rs index a3c8f6802..e21074531 100644 --- a/src/evm/interpreter.rs +++ b/src/evm/interpreter.rs @@ -718,7 +718,7 @@ impl Interpreter { let big_id = stack.pop_back(); let id = big_id.low_u64() as usize; let max = id.wrapping_add(32); - let data = params.data.clone().unwrap_or(vec![]); + let data = params.data.clone().unwrap_or_else(|| vec![]); let bound = cmp::min(data.len(), max); if id < bound && big_id < U256::from(data.len()) { let mut v = data[id..bound].to_vec(); @@ -729,7 +729,7 @@ impl Interpreter { } }, instructions::CALLDATASIZE => { - stack.push(U256::from(params.data.clone().unwrap_or(vec![]).len())); + stack.push(U256::from(params.data.clone().map_or(0, |l| l.len()))); }, instructions::CODESIZE => { stack.push(U256::from(code.len())); @@ -740,10 +740,10 @@ impl Interpreter { stack.push(U256::from(len)); }, instructions::CALLDATACOPY => { - self.copy_data_to_memory(mem, stack, ¶ms.data.clone().unwrap_or(vec![])); + self.copy_data_to_memory(mem, stack, ¶ms.data.clone().unwrap_or_else(|| vec![])); }, instructions::CODECOPY => { - self.copy_data_to_memory(mem, stack, ¶ms.code.clone().unwrap_or(vec![])); + self.copy_data_to_memory(mem, stack, ¶ms.code.clone().unwrap_or_else(|| vec![])); }, instructions::EXTCODECOPY => { let address = u256_to_address(&stack.pop_back()); diff --git a/src/evm/tests.rs b/src/evm/tests.rs index 8e1b5eff4..ef5987285 100644 --- a/src/evm/tests.rs +++ b/src/evm/tests.rs @@ -19,7 +19,7 @@ struct FakeExt { logs: Vec, _suicides: HashSet
, info: EnvInfo, - _schedule: Schedule + schedule: Schedule } impl FakeExt { @@ -89,7 +89,7 @@ impl Ext for FakeExt { } fn schedule(&self) -> &Schedule { - &self._schedule + &self.schedule } fn env_info(&self) -> &EnvInfo { @@ -122,7 +122,7 @@ fn test_stack_underflow() { }; match err { - evm::Error::StackUnderflow {instruction: _, wanted, on_stack} => { + evm::Error::StackUnderflow {wanted, on_stack, ..} => { assert_eq!(wanted, 2); assert_eq!(on_stack, 0); } diff --git a/src/externalities.rs b/src/externalities.rs index 9c07f005c..b2d716d37 100644 --- a/src/externalities.rs +++ b/src/externalities.rs @@ -158,7 +158,7 @@ impl<'a> Ext for Externalities<'a> { } fn extcode(&self, address: &Address) -> Bytes { - self.state.code(address).unwrap_or(vec![]) + self.state.code(address).unwrap_or_else(|| vec![]) } #[allow(match_ref_pats)] diff --git a/src/lib.rs b/src/lib.rs index 99a300924..f9795f324 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,9 @@ #![feature(cell_extras)] #![feature(augmented_assignments)] -//#![feature(plugin)] +#![feature(plugin)] //#![plugin(interpolate_idents)] -#![allow(match_bool, needless_range_loop)] +#![plugin(clippy)] +#![allow(needless_range_loop, match_bool)] //! Ethcore's ethereum implementation //! diff --git a/src/pod_state.rs b/src/pod_state.rs index e3802c42a..68f057d9c 100644 --- a/src/pod_state.rs +++ b/src/pod_state.rs @@ -25,10 +25,10 @@ impl FromJson for PodState { let code = acc.find("code").map(&Bytes::from_json); if balance.is_some() || nonce.is_some() || storage.is_some() || code.is_some() { state.insert(address_from_hex(address), PodAccount{ - balance: balance.unwrap_or(U256::zero()), - nonce: nonce.unwrap_or(U256::zero()), - storage: storage.unwrap_or(BTreeMap::new()), - code: code.unwrap_or(Vec::new()) + balance: balance.unwrap_or_else(U256::zero), + nonce: nonce.unwrap_or_else(U256::zero), + storage: storage.unwrap_or_else(BTreeMap::new), + code: code.unwrap_or_else(Vec::new) }); } state diff --git a/src/spec.rs b/src/spec.rs index 4125191b5..2c112268f 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -176,7 +176,7 @@ impl FromJson for Spec { // let nonce = if let Some(&Json::String(ref n)) = acc.find("nonce") {U256::from_dec_str(n).unwrap_or(U256::from(0))} else {U256::from(0)}; // TODO: handle code & data if they exist. if balance.is_some() || nonce.is_some() { - state.insert(addr, GenesisAccount { balance: balance.unwrap_or(U256::from(0)), nonce: nonce.unwrap_or(U256::from(0)) }); + state.insert(addr, GenesisAccount { balance: balance.unwrap_or_else(U256::zero), nonce: nonce.unwrap_or_else(U256::zero) }); } } } diff --git a/src/sync/range_collection.rs b/src/sync/range_collection.rs index 822056ff4..b8186e5a5 100644 --- a/src/sync/range_collection.rs +++ b/src/sync/range_collection.rs @@ -191,6 +191,7 @@ impl RangeCollection for Vec<(K, Vec)> where K: Ord + PartialEq + } #[test] +#[allow(cyclomatic_complexity)] fn test_range() { use std::cmp::{Ordering}; diff --git a/src/sync/tests.rs b/src/sync/tests.rs index 05d7ac317..72c207f10 100644 --- a/src/sync/tests.rs +++ b/src/sync/tests.rs @@ -64,7 +64,7 @@ impl BlockChainClient for TestBlockChainClient { } fn block(&self, h: &H256) -> Option { - self.blocks.get(h).map(|b| b.clone()) + self.blocks.get(h).cloned() } fn block_status(&self, h: &H256) -> BlockStatus { @@ -208,7 +208,7 @@ impl<'p> SyncIo for TestIo<'p> { Ok(()) } - fn chain<'a>(&'a mut self) -> &'a mut BlockChainClient { + fn chain(&mut self) -> &mut BlockChainClient { self.chain } } @@ -265,14 +265,11 @@ impl TestNet { pub fn sync_step(&mut self) { for peer in 0..self.peers.len() { - match self.peers[peer].queue.pop_front() { - Some(packet) => { - let mut p = self.peers.get_mut(packet.recipient).unwrap(); - trace!("--- {} -> {} ---", peer, packet.recipient); - p.sync.on_packet(&mut TestIo::new(&mut p.chain, &mut p.queue, Some(peer as PeerId)), peer as PeerId, packet.packet_id, &packet.data); - trace!("----------------"); - }, - None => {} + if let Some(packet) = self.peers[peer].queue.pop_front() { + let mut p = self.peers.get_mut(packet.recipient).unwrap(); + trace!("--- {} -> {} ---", peer, packet.recipient); + p.sync.on_packet(&mut TestIo::new(&mut p.chain, &mut p.queue, Some(peer as PeerId)), peer as PeerId, packet.packet_id, &packet.data); + trace!("----------------"); } let mut p = self.peers.get_mut(peer).unwrap(); p.sync.maintain_sync(&mut TestIo::new(&mut p.chain, &mut p.queue, None)); diff --git a/src/tests/executive.rs b/src/tests/executive.rs index fe428e199..d201f7fc5 100644 --- a/src/tests/executive.rs +++ b/src/tests/executive.rs @@ -168,7 +168,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec { let mut fail = false; //let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true }; let mut fail_unless = |cond: bool, s: &str | if !cond && !fail { - failed.push(format!("[{}] {}: {}", vm, name.to_string(), s)); + failed.push(format!("[{}] {}: {}", vm, name, s)); fail = true }; @@ -245,7 +245,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec { test.find("post").map(|pre| for (addr, s) in pre.as_object().unwrap() { let address = Address::from(addr.as_ref()); - fail_unless(state.code(&address).unwrap_or(vec![]) == Bytes::from_json(&s["code"]), "code is incorrect"); + fail_unless(state.code(&address).unwrap_or_else(|| vec![]) == Bytes::from_json(&s["code"]), "code is incorrect"); fail_unless(state.balance(&address) == xjson!(&s["balance"]), "balance is incorrect"); fail_unless(state.nonce(&address) == xjson!(&s["nonce"]), "nonce is incorrect"); BTreeMap::from_json(&s["storage"]).iter().foreach(|(k, v)| fail_unless(&state.storage_at(&address, &k) == v, "storage is incorrect")); @@ -266,7 +266,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec { } - for f in failed.iter() { + for f in &failed { println!("FAILED: {:?}", f); } diff --git a/src/tests/state.rs b/src/tests/state.rs index 119e7037a..bebb37c88 100644 --- a/src/tests/state.rs +++ b/src/tests/state.rs @@ -15,7 +15,7 @@ fn do_json_test(json_data: &[u8]) -> Vec { let mut fail = false; { let mut fail_unless = |cond: bool| if !cond && !fail { - failed.push(name.to_string()); + failed.push(name.clone()); flush(format!("FAIL\n")); fail = true; true diff --git a/src/tests/test_common.rs b/src/tests/test_common.rs index 15c5364c4..adb1c35d3 100644 --- a/src/tests/test_common.rs +++ b/src/tests/test_common.rs @@ -6,7 +6,7 @@ macro_rules! declare_test { #[test] #[allow(non_snake_case)] fn $id() { - assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).len() == 0); + assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).is_empty()); } }; } @@ -18,7 +18,7 @@ macro_rules! declare_test_ignore { #[ignore] #[allow(non_snake_case)] fn $id() { - assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).len() == 0); + assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).is_empty()); } }; } diff --git a/src/tests/transaction.rs b/src/tests/transaction.rs index d4836ca84..a798a38f3 100644 --- a/src/tests/transaction.rs +++ b/src/tests/transaction.rs @@ -9,13 +9,13 @@ fn do_json_test(json_data: &[u8]) -> Vec { let ot = RefCell::new(Transaction::new()); for (name, test) in json.as_object().unwrap() { let mut fail = false; - let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); println!("Transaction: {:?}", ot.borrow()); fail = true }; + let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.clone()); println!("Transaction: {:?}", ot.borrow()); fail = true }; let schedule = match test.find("blocknumber") .and_then(|j| j.as_string()) .and_then(|s| BlockNumber::from_str(s).ok()) .unwrap_or(0) { x if x < 900000 => &old_schedule, _ => &new_schedule }; let rlp = Bytes::from_json(&test["rlp"]); - let res = UntrustedRlp::new(&rlp).as_val().map_err(|e| From::from(e)).and_then(|t: Transaction| t.validate(schedule, schedule.have_delegate_call)); + let res = UntrustedRlp::new(&rlp).as_val().map_err(From::from).and_then(|t: Transaction| t.validate(schedule, schedule.have_delegate_call)); fail_unless(test.find("transaction").is_none() == res.is_err()); if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) { let t = res.unwrap(); @@ -30,11 +30,11 @@ fn do_json_test(json_data: &[u8]) -> Vec { fail_unless(to == &xjson!(&tx["to"])); } else { *ot.borrow_mut() = t.clone(); - fail_unless(Bytes::from_json(&tx["to"]).len() == 0); + fail_unless(Bytes::from_json(&tx["to"]).is_empty()); } } } - for f in failed.iter() { + for f in &failed { println!("FAILED: {:?}", f); } failed diff --git a/src/verification.rs b/src/verification.rs index 3d852dc3e..064c0b7d7 100644 --- a/src/verification.rs +++ b/src/verification.rs @@ -64,7 +64,7 @@ pub fn verify_block_unordered(header: Header, bytes: Bytes, engine: &Engine) -> /// Phase 3 verification. Check block information against parent and uncles. pub fn verify_block_family(header: &Header, bytes: &[u8], engine: &Engine, bc: &BC) -> Result<(), Error> where BC: BlockProvider { // TODO: verify timestamp - let parent = try!(bc.block_header(&header.parent_hash).ok_or::(From::from(BlockError::UnknownParent(header.parent_hash.clone())))); + let parent = try!(bc.block_header(&header.parent_hash).ok_or_else(|| Error::from(BlockError::UnknownParent(header.parent_hash.clone())))); try!(verify_parent(&header, &parent)); try!(engine.verify_block_family(&header, &parent, Some(bytes))); @@ -122,7 +122,7 @@ pub fn verify_block_family(header: &Header, bytes: &[u8], engine: &Engine, b // cB.p^7 -------------/ // cB.p^8 let mut expected_uncle_parent = header.parent_hash.clone(); - let uncle_parent = try!(bc.block_header(&uncle.parent_hash).ok_or::(From::from(BlockError::UnknownUncleParent(uncle.parent_hash.clone())))); + let uncle_parent = try!(bc.block_header(&uncle.parent_hash).ok_or_else(|| Error::from(BlockError::UnknownUncleParent(uncle.parent_hash.clone())))); for _ in 0..depth { match bc.block_details(&expected_uncle_parent) { Some(details) => { @@ -284,7 +284,7 @@ mod tests { /// Get raw block data fn block(&self, hash: &H256) -> Option { - self.blocks.get(hash).map(|b| b.clone()) + self.blocks.get(hash).cloned() } /// Get the familial details concerning a block. @@ -302,7 +302,7 @@ mod tests { /// Get the hash of given block's number. fn block_hash(&self, index: BlockNumber) -> Option { - self.numbers.get(&index).map(|h| h.clone()) + self.numbers.get(&index).cloned() } } diff --git a/util/Cargo.toml b/util/Cargo.toml index 02fdad17f..32f6eb17c 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -24,6 +24,7 @@ heapsize = "0.2" itertools = "0.4" slab = { git = "https://github.com/arkpar/slab.git" } sha3 = { path = "sha3" } +clippy = "*" [dev-dependencies] json-tests = { path = "json-tests" } diff --git a/util/src/hash.rs b/util/src/hash.rs index 793924f8f..bdd694cfc 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -424,9 +424,9 @@ macro_rules! impl_hash { fn from(s: &'_ str) -> $from { use std::str::FromStr; if s.len() % 2 == 1 { - $from::from_str(&("0".to_owned() + &(clean_0x(s).to_owned()))[..]).unwrap_or($from::new()) + $from::from_str(&("0".to_owned() + &(clean_0x(s).to_owned()))[..]).unwrap_or_else(|_| $from::new()) } else { - $from::from_str(clean_0x(s)).unwrap_or($from::new()) + $from::from_str(clean_0x(s)).unwrap_or_else(|_| $from::new()) } } } @@ -545,6 +545,7 @@ mod tests { use std::str::FromStr; #[test] + #[allow(eq_op)] fn hash() { let h = H64([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]); assert_eq!(H64::from_str("0123456789abcdef").unwrap(), h); diff --git a/util/src/journaldb.rs b/util/src/journaldb.rs index ada9c0d2b..477aa6071 100644 --- a/util/src/journaldb.rs +++ b/util/src/journaldb.rs @@ -96,7 +96,7 @@ impl JournalDB { })) { let rlp = Rlp::new(&rlp_data); let to_remove: Vec = rlp.val_at(if canon_id == rlp.val_at(0) {2} else {1}); - for i in to_remove.iter() { + for i in &to_remove { self.forward.remove(i); } try!(self.backing.delete(&last)); diff --git a/util/src/json_aid.rs b/util/src/json_aid.rs index 417017c31..c716b8991 100644 --- a/util/src/json_aid.rs +++ b/util/src/json_aid.rs @@ -10,9 +10,9 @@ pub fn clean(s: &str) -> &str { fn u256_from_str(s: &str) -> U256 { if s.len() >= 2 && &s[0..2] == "0x" { - U256::from_str(&s[2..]).unwrap_or(U256::from(0)) + U256::from_str(&s[2..]).unwrap_or_else(|_| U256::zero()) } else { - U256::from_dec_str(s).unwrap_or(U256::from(0)) + U256::from_dec_str(s).unwrap_or_else(|_| U256::zero()) } } @@ -20,8 +20,8 @@ impl FromJson for Bytes { fn from_json(json: &Json) -> Self { match *json { Json::String(ref s) => match s.len() % 2 { - 0 => FromHex::from_hex(clean(s)).unwrap_or(vec![]), - _ => FromHex::from_hex(&("0".to_owned() + &(clean(s).to_owned()))[..]).unwrap_or(vec![]), + 0 => FromHex::from_hex(clean(s)).unwrap_or_else(|_| vec![]), + _ => FromHex::from_hex(&("0".to_owned() + &(clean(s).to_owned()))[..]).unwrap_or_else(|_| vec![]), }, _ => vec![], } diff --git a/util/src/lib.rs b/util/src/lib.rs index 5f59aca8c..578a1d47a 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -1,6 +1,8 @@ #![feature(op_assign_traits)] #![feature(augmented_assignments)] #![feature(associated_consts)] +#![feature(plugin)] +#![plugin(clippy)] #![allow(needless_range_loop, match_bool)] //! Ethcore-util library //! diff --git a/util/src/rlp/tests.rs b/util/src/rlp/tests.rs index 7c2099124..f33cec177 100644 --- a/util/src/rlp/tests.rs +++ b/util/src/rlp/tests.rs @@ -15,25 +15,25 @@ fn rlp_at() { assert!(rlp.is_list()); //let animals = as rlp::Decodable>::decode_untrusted(&rlp).unwrap(); let animals: Vec = rlp.as_val().unwrap(); - assert_eq!(animals, vec!["cat".to_string(), "dog".to_string()]); + assert_eq!(animals, vec!["cat".to_owned(), "dog".to_owned()]); let cat = rlp.at(0).unwrap(); assert!(cat.is_data()); assert_eq!(cat.as_raw(), &[0x83, b'c', b'a', b't']); - //assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_string()); - assert_eq!(cat.as_val::().unwrap(), "cat".to_string()); + //assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_owned()); + assert_eq!(cat.as_val::().unwrap(), "cat".to_owned()); let dog = rlp.at(1).unwrap(); assert!(dog.is_data()); assert_eq!(dog.as_raw(), &[0x83, b'd', b'o', b'g']); - //assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_string()); - assert_eq!(dog.as_val::().unwrap(), "dog".to_string()); + //assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_owned()); + assert_eq!(dog.as_val::().unwrap(), "dog".to_owned()); let cat_again = rlp.at(0).unwrap(); assert!(cat_again.is_data()); assert_eq!(cat_again.as_raw(), &[0x83, b'c', b'a', b't']); - //assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_string()); - assert_eq!(cat_again.as_val::().unwrap(), "cat".to_string()); + //assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_owned()); + assert_eq!(cat_again.as_val::().unwrap(), "cat".to_owned()); } } @@ -268,13 +268,13 @@ fn decode_untrusted_u256() { #[test] fn decode_untrusted_str() { - let tests = vec![DTestPair("cat".to_string(), vec![0x83, b'c', b'a', b't']), - DTestPair("dog".to_string(), vec![0x83, b'd', b'o', b'g']), - DTestPair("Marek".to_string(), + let tests = vec![DTestPair("cat".to_owned(), vec![0x83, b'c', b'a', b't']), + DTestPair("dog".to_owned(), vec![0x83, b'd', b'o', b'g']), + DTestPair("Marek".to_owned(), vec![0x85, b'M', b'a', b'r', b'e', b'k']), - DTestPair("".to_string(), vec![0x80]), + DTestPair("".to_owned(), vec![0x80]), DTestPair("Lorem ipsum dolor sit amet, consectetur adipisicing elit" - .to_string(), + .to_owned(), vec![0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i', b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', b'o', b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e', @@ -311,14 +311,14 @@ fn decode_untrusted_vector_u64() { #[test] fn decode_untrusted_vector_str() { - let tests = vec![DTestPair(vec!["cat".to_string(), "dog".to_string()], + let tests = vec![DTestPair(vec!["cat".to_owned(), "dog".to_owned()], vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'])]; run_decode_tests(tests); } #[test] fn decode_untrusted_vector_of_vectors_str() { - let tests = vec![DTestPair(vec![vec!["cat".to_string()]], + let tests = vec![DTestPair(vec![vec!["cat".to_owned()]], vec![0xc5, 0xc4, 0x83, b'c', b'a', b't'])]; run_decode_tests(tests); } diff --git a/util/src/trie/triedbmut.rs b/util/src/trie/triedbmut.rs index bd39f87ae..f52c9bc1e 100644 --- a/util/src/trie/triedbmut.rs +++ b/util/src/trie/triedbmut.rs @@ -692,7 +692,7 @@ mod tests { } } - fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &Vec<(Vec, Vec)>) -> TrieDBMut<'db> { + fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &[(Vec, Vec)]) -> TrieDBMut<'db> { let mut t = TrieDBMut::new(db, root); for i in 0..v.len() { let key: &[u8]= &v[i].0; @@ -702,8 +702,8 @@ mod tests { t } - fn unpopulate_trie<'a, 'db>(t: &mut TrieDBMut<'db>, v: &Vec<(Vec, Vec)>) { - for i in &v { + fn unpopulate_trie<'db>(t: &mut TrieDBMut<'db>, v: &[(Vec, Vec)]) { + for i in v { let key: &[u8]= &i.0; t.remove(&key); } @@ -759,7 +759,7 @@ mod tests { println!("TRIE MISMATCH"); println!(""); println!("{:?} vs {:?}", memtrie.root(), real); - for i in x.iter() { + for i in &x { println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty()); } println!("{:?}", memtrie); @@ -772,7 +772,7 @@ mod tests { println!(""); println!("remaining: {:?}", memtrie.db_items_remaining()); println!("{:?} vs {:?}", memtrie.root(), real); - for i in x.iter() { + for i in &x { println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty()); } println!("{:?}", memtrie); @@ -1049,12 +1049,12 @@ mod tests { println!("TRIE MISMATCH"); println!(""); println!("ORIGINAL... {:?}", memtrie.root()); - for i in x.iter() { + for i in &x { println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty()); } println!("{:?}", memtrie); println!("SORTED... {:?}", memtrie_sorted.root()); - for i in y.iter() { + for i in &y { println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty()); } println!("{:?}", memtrie_sorted); diff --git a/util/src/uint.rs b/util/src/uint.rs index 84005d366..bd51aad40 100644 --- a/util/src/uint.rs +++ b/util/src/uint.rs @@ -437,9 +437,9 @@ macro_rules! construct_uint { match *json { Json::String(ref s) => { if s.len() >= 2 && &s[0..2] == "0x" { - FromStr::from_str(&s[2..]).unwrap_or(Default::default()) + FromStr::from_str(&s[2..]).unwrap_or_else(|_| Default::default()) } else { - Uint::from_dec_str(s).unwrap_or(Default::default()) + Uint::from_dec_str(s).unwrap_or_else(|_| Default::default()) } }, Json::U64(u) => From::from(u), @@ -1046,6 +1046,7 @@ mod tests { } #[test] + #[allow(eq_op)] pub fn uint256_comp_test() { let small = U256([10u64, 0, 0, 0]); let big = U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]);