Fixing all clippy lints

This commit is contained in:
Tomusdrw
2016-01-19 13:47:30 +01:00
parent 6ead6b7847
commit c746f0e62c
25 changed files with 80 additions and 74 deletions

View File

@@ -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" }

View File

@@ -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);

View File

@@ -96,7 +96,7 @@ impl JournalDB {
})) {
let rlp = Rlp::new(&rlp_data);
let to_remove: Vec<H256> = 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));

View File

@@ -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![],
}

View File

@@ -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
//!

View File

@@ -15,25 +15,25 @@ fn rlp_at() {
assert!(rlp.is_list());
//let animals = <Vec<String> as rlp::Decodable>::decode_untrusted(&rlp).unwrap();
let animals: Vec<String> = 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::<String>().unwrap(), "cat".to_string());
//assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_owned());
assert_eq!(cat.as_val::<String>().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::<String>().unwrap(), "dog".to_string());
//assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_owned());
assert_eq!(dog.as_val::<String>().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::<String>().unwrap(), "cat".to_string());
//assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_owned());
assert_eq!(cat_again.as_val::<String>().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);
}

View File

@@ -692,7 +692,7 @@ mod tests {
}
}
fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &Vec<(Vec<u8>, Vec<u8>)>) -> TrieDBMut<'db> {
fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &[(Vec<u8>, Vec<u8>)]) -> 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<u8>, Vec<u8>)>) {
for i in &v {
fn unpopulate_trie<'db>(t: &mut TrieDBMut<'db>, v: &[(Vec<u8>, Vec<u8>)]) {
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);

View File

@@ -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]);