From 21ecaddac1c15a75d4172335cf1e0bac26761075 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 28 May 2019 10:56:05 +1000 Subject: [PATCH] Fix various clippy lints --- beacon_node/client/src/client_config.rs | 2 +- eth2/fork_choice/src/bitwise_lmd_ghost.rs | 7 +++---- eth2/fork_choice/src/optimized_lmd_ghost.rs | 7 +++---- eth2/utils/fixed_len_vec/src/impls.rs | 2 +- eth2/utils/ssz/src/decode.rs | 4 +--- eth2/utils/ssz/src/decode/impls.rs | 10 ++++------ 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index d8d3f2c4a..15512342c 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -98,7 +98,7 @@ impl ClientConfig { // Custom bootnodes if let Some(boot_addresses_str) = args.value_of("boot-nodes") { - let boot_addresses_split = boot_addresses_str.split(","); + let boot_addresses_split = boot_addresses_str.split(','); for boot_address in boot_addresses_split { if let Ok(boot_address) = boot_address.parse::() { config.net_conf.boot_nodes.append(&mut vec![boot_address]); diff --git a/eth2/fork_choice/src/bitwise_lmd_ghost.rs b/eth2/fork_choice/src/bitwise_lmd_ghost.rs index 129dca985..2d1b4e508 100644 --- a/eth2/fork_choice/src/bitwise_lmd_ghost.rs +++ b/eth2/fork_choice/src/bitwise_lmd_ghost.rs @@ -120,12 +120,11 @@ impl BitwiseLMDGhost { // not in the cache recursively search for ancestors using a log-lookup if let Some(ancestor) = { - let ancestor_lookup = self.ancestors + let ancestor_lookup = *self.ancestors [log2_int((block_height - target_height - 1u64).as_u64()) as usize] .get(&block_hash) //TODO: Panic if we can't lookup and fork choice fails - .expect("All blocks should be added to the ancestor log lookup table") - .clone(); + .expect("All blocks should be added to the ancestor log lookup table"); self.get_ancestor(ancestor_lookup, target_height, &spec) } { // add the result to the cache @@ -152,7 +151,7 @@ impl BitwiseLMDGhost { // these have already been weighted by balance for (hash, votes) in latest_votes.iter() { if let Some(ancestor) = self.get_ancestor(*hash, block_height, spec) { - let current_vote_value = current_votes.get(&ancestor).unwrap_or_else(|| &0).clone(); + let current_vote_value = *current_votes.get(&ancestor).unwrap_or_else(|| &0); current_votes.insert(ancestor, current_vote_value + *votes); total_vote_count += votes; } diff --git a/eth2/fork_choice/src/optimized_lmd_ghost.rs b/eth2/fork_choice/src/optimized_lmd_ghost.rs index 351c4decd..ada8ce9cb 100644 --- a/eth2/fork_choice/src/optimized_lmd_ghost.rs +++ b/eth2/fork_choice/src/optimized_lmd_ghost.rs @@ -120,12 +120,11 @@ impl OptimizedLMDGhost { // not in the cache recursively search for ancestors using a log-lookup if let Some(ancestor) = { - let ancestor_lookup = self.ancestors + let ancestor_lookup = *self.ancestors [log2_int((block_height - target_height - 1u64).as_u64()) as usize] .get(&block_hash) //TODO: Panic if we can't lookup and fork choice fails - .expect("All blocks should be added to the ancestor log lookup table") - .clone(); + .expect("All blocks should be added to the ancestor log lookup table"); self.get_ancestor(ancestor_lookup, target_height, &spec) } { // add the result to the cache @@ -152,7 +151,7 @@ impl OptimizedLMDGhost { // these have already been weighted by balance for (hash, votes) in latest_votes.iter() { if let Some(ancestor) = self.get_ancestor(*hash, block_height, spec) { - let current_vote_value = current_votes.get(&ancestor).unwrap_or_else(|| &0).clone(); + let current_vote_value = *current_votes.get(&ancestor).unwrap_or_else(|| &0); current_votes.insert(ancestor, current_vote_value + *votes); total_vote_count += votes; } diff --git a/eth2/utils/fixed_len_vec/src/impls.rs b/eth2/utils/fixed_len_vec/src/impls.rs index e1c54c1f7..691c8ee89 100644 --- a/eth2/utils/fixed_len_vec/src/impls.rs +++ b/eth2/utils/fixed_len_vec/src/impls.rs @@ -100,7 +100,7 @@ where } fn from_ssz_bytes(bytes: &[u8]) -> Result { - if bytes.len() == 0 { + if bytes.is_empty() { Ok(FixedLenVec::from(vec![])) } else if T::is_ssz_fixed_len() { bytes diff --git a/eth2/utils/ssz/src/decode.rs b/eth2/utils/ssz/src/decode.rs index 891104733..6934f1708 100644 --- a/eth2/utils/ssz/src/decode.rs +++ b/eth2/utils/ssz/src/decode.rs @@ -102,9 +102,7 @@ impl<'a> SszDecoderBuilder<'a> { .and_then(|o| Some(o.offset)) .unwrap_or_else(|| BYTES_PER_LENGTH_OFFSET); - if previous_offset > offset { - return Err(DecodeError::OutOfBoundsByte { i: offset }); - } else if offset > self.bytes.len() { + if (previous_offset > offset) || (offset > self.bytes.len()) { return Err(DecodeError::OutOfBoundsByte { i: offset }); } diff --git a/eth2/utils/ssz/src/decode/impls.rs b/eth2/utils/ssz/src/decode/impls.rs index 8a5a36780..213f19bf5 100644 --- a/eth2/utils/ssz/src/decode/impls.rs +++ b/eth2/utils/ssz/src/decode/impls.rs @@ -54,11 +54,9 @@ impl Decode for bool { match bytes[0] { 0b0000_0000 => Ok(false), 0b0000_0001 => Ok(true), - _ => { - return Err(DecodeError::BytesInvalid( - format!("Out-of-range for boolean: {}", bytes[0]).to_string(), - )) - } + _ => Err(DecodeError::BytesInvalid( + format!("Out-of-range for boolean: {}", bytes[0]).to_string(), + )), } } } @@ -121,7 +119,7 @@ impl Decode for Vec { } fn from_ssz_bytes(bytes: &[u8]) -> Result { - if bytes.len() == 0 { + if bytes.is_empty() { Ok(vec![]) } else if T::is_ssz_fixed_len() { bytes