diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 4d77d7aa5..945c37617 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -216,9 +216,7 @@ impl BeaconChain { .iter() .map(|root| match self.get_block(root)? { Some(block) => Ok(block.body), - None => Err(Error::DBInconsistent( - format!("Missing block: {}", root).into(), - )), + None => Err(Error::DBInconsistent(format!("Missing block: {}", root))), }) .collect(); diff --git a/beacon_node/beacon_chain/src/iter.rs b/beacon_node/beacon_chain/src/iter.rs index b54dd1d2a..1b5e382b0 100644 --- a/beacon_node/beacon_chain/src/iter.rs +++ b/beacon_node/beacon_chain/src/iter.rs @@ -57,7 +57,7 @@ impl Iterator for BlockRootsIterator { return None; } - self.slot = self.slot - 1; + self.slot -= 1; match self.beacon_state.get_block_root(self.slot) { Ok(root) => Some(*root), @@ -73,7 +73,7 @@ impl Iterator for BlockRootsIterator { self.beacon_state.get_block_root(self.slot).ok().cloned() } - _ => return None, + _ => None, } } } diff --git a/beacon_node/eth2-libp2p/src/config.rs b/beacon_node/eth2-libp2p/src/config.rs index 2a2701883..ee2add75e 100644 --- a/beacon_node/eth2-libp2p/src/config.rs +++ b/beacon_node/eth2-libp2p/src/config.rs @@ -57,12 +57,12 @@ impl Config { pub fn apply_cli_args(&mut self, args: &ArgMatches) -> Result<(), &'static str> { if let Some(listen_address_str) = args.value_of("listen-address") { - let listen_addresses = listen_address_str.split(",").map(Into::into).collect(); + let listen_addresses = listen_address_str.split(',').map(Into::into).collect(); self.listen_addresses = listen_addresses; } if let Some(boot_addresses_str) = args.value_of("boot-nodes") { - let boot_addresses = boot_addresses_str.split(",").map(Into::into).collect(); + let boot_addresses = boot_addresses_str.split(',').map(Into::into).collect(); self.boot_nodes = boot_addresses; } diff --git a/beacon_node/eth2-libp2p/src/rpc/protocol.rs b/beacon_node/eth2-libp2p/src/rpc/protocol.rs index d75e53e6c..de52f964e 100644 --- a/beacon_node/eth2-libp2p/src/rpc/protocol.rs +++ b/beacon_node/eth2-libp2p/src/rpc/protocol.rs @@ -42,7 +42,7 @@ impl RequestId { } /// Return the previous id. - pub fn previous(&self) -> Self { + pub fn previous(self) -> Self { Self(self.0 - 1) } } @@ -220,7 +220,7 @@ impl Encode for RPCEvent { } => SszContainer { is_request: true, id: (*id).into(), - other: (*method_id).into(), + other: *method_id, bytes: match body { RPCRequest::Hello(body) => body.as_ssz_bytes(), RPCRequest::Goodbye(body) => body.as_ssz_bytes(), @@ -237,7 +237,7 @@ impl Encode for RPCEvent { } => SszContainer { is_request: false, id: (*id).into(), - other: (*method_id).into(), + other: *method_id, bytes: match result { RPCResponse::Hello(response) => response.as_ssz_bytes(), RPCResponse::BeaconBlockRoots(response) => response.as_ssz_bytes(), diff --git a/beacon_node/network/src/message_handler.rs b/beacon_node/network/src/message_handler.rs index adafae145..40a396c3b 100644 --- a/beacon_node/network/src/message_handler.rs +++ b/beacon_node/network/src/message_handler.rs @@ -155,7 +155,7 @@ impl MessageHandler { if self .network_context .outstanding_outgoing_request_ids - .remove(&(peer_id.clone(), id.clone())) + .remove(&(peer_id.clone(), id)) .is_none() { warn!( @@ -250,7 +250,7 @@ impl NetworkContext { let id = self.generate_request_id(&peer_id); self.outstanding_outgoing_request_ids - .insert((peer_id.clone(), id.clone()), Instant::now()); + .insert((peer_id.clone(), id), Instant::now()); self.send_rpc_event( peer_id, diff --git a/eth2/fork_choice/src/test_utils.rs b/eth2/fork_choice/src/test_utils.rs index 840d7a76b..8ef20108a 100644 --- a/eth2/fork_choice/src/test_utils.rs +++ b/eth2/fork_choice/src/test_utils.rs @@ -57,7 +57,7 @@ fn get_chain_of_blocks( ) -> Vec<(Hash256, BeaconBlock)> { let spec = T::default_spec(); let mut blocks_and_roots: Vec<(Hash256, BeaconBlock)> = vec![]; - let mut unique_hashes = (0..).into_iter().map(|i| Hash256::from(i)); + let mut unique_hashes = (0..).map(Hash256::from); let mut random_block = BeaconBlock::random_for_test(&mut XorShiftRng::from_seed([42; 16])); random_block.previous_block_root = Hash256::zero(); let beacon_state = get_state::(validator_count); diff --git a/eth2/state_processing/src/per_block_processing/verify_indexed_attestation.rs b/eth2/state_processing/src/per_block_processing/verify_indexed_attestation.rs index 6581e516d..f06f1e900 100644 --- a/eth2/state_processing/src/per_block_processing/verify_indexed_attestation.rs +++ b/eth2/state_processing/src/per_block_processing/verify_indexed_attestation.rs @@ -49,7 +49,7 @@ fn verify_indexed_attestation_parametric( ); // Check that nobody signed with custody bit 1 (to be removed in phase 1) - if custody_bit_1_indices.len() > 0 { + if !custody_bit_1_indices.is_empty() { invalid!(Invalid::CustodyBitfieldHasSetBits); } @@ -96,7 +96,7 @@ where state .validator_registry .get(validator_idx as usize) - .ok_or(Error::Invalid(Invalid::UnknownValidator(validator_idx))) + .ok_or_else(|| Error::Invalid(Invalid::UnknownValidator(validator_idx))) .map(|validator| { aggregate_pubkey.add(&validator.pubkey); aggregate_pubkey diff --git a/eth2/state_processing/src/per_epoch_processing.rs b/eth2/state_processing/src/per_epoch_processing.rs index f7a4a1c50..5110207a3 100644 --- a/eth2/state_processing/src/per_epoch_processing.rs +++ b/eth2/state_processing/src/per_epoch_processing.rs @@ -156,7 +156,7 @@ pub fn process_crosslinks( state.previous_crosslinks = state.current_crosslinks.clone(); - for relative_epoch in vec![RelativeEpoch::Previous, RelativeEpoch::Current] { + for &relative_epoch in &[RelativeEpoch::Previous, RelativeEpoch::Current] { let epoch = relative_epoch.into_epoch(state.current_epoch()); for offset in 0..state.get_epoch_committee_count(relative_epoch)? { let shard = diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 850cfcaa6..1fbab8580 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -422,7 +422,7 @@ impl BeaconState { }; let effective_balance = self.validator_registry[candidate_index].effective_balance; if (effective_balance * MAX_RANDOM_BYTE) - >= (spec.max_effective_balance * random_byte as u64) + >= (spec.max_effective_balance * u64::from(random_byte)) { break candidate_index; } diff --git a/eth2/types/src/beacon_state/committee_cache.rs b/eth2/types/src/beacon_state/committee_cache.rs index 78af72754..aa921da82 100644 --- a/eth2/types/src/beacon_state/committee_cache.rs +++ b/eth2/types/src/beacon_state/committee_cache.rs @@ -162,7 +162,6 @@ impl CommitteeCache { let i = self.shuffled_position(validator_index)?; (0..self.committee_count) - .into_iter() .map(|nth_committee| (nth_committee, self.compute_committee_range(nth_committee))) .find(|(_, range)| { if let Some(range) = range { diff --git a/eth2/types/src/chain_spec.rs b/eth2/types/src/chain_spec.rs index b16947328..89ea97070 100644 --- a/eth2/types/src/chain_spec.rs +++ b/eth2/types/src/chain_spec.rs @@ -174,7 +174,7 @@ impl ChainSpec { /* * Time parameters */ - genesis_time: u32::max_value() as u64, + genesis_time: u64::from(u32::max_value()), seconds_per_slot: 6, min_attestation_inclusion_delay: 4, min_seed_lookahead: Epoch::new(1), diff --git a/eth2/types/src/slot_epoch.rs b/eth2/types/src/slot_epoch.rs index fbeb479d7..9a7808da4 100644 --- a/eth2/types/src/slot_epoch.rs +++ b/eth2/types/src/slot_epoch.rs @@ -77,7 +77,7 @@ impl Epoch { /// Position of some slot inside an epoch, if any. /// /// E.g., the first `slot` in `epoch` is at position `0`. - pub fn position(&self, slot: Slot, slots_per_epoch: u64) -> Option { + pub fn position(self, slot: Slot, slots_per_epoch: u64) -> Option { let start = self.start_slot(slots_per_epoch); let end = self.end_slot(slots_per_epoch); diff --git a/eth2/types/src/test_utils/builders/testing_beacon_block_builder.rs b/eth2/types/src/test_utils/builders/testing_beacon_block_builder.rs index 999e88aae..36bbe2d37 100644 --- a/eth2/types/src/test_utils/builders/testing_beacon_block_builder.rs +++ b/eth2/types/src/test_utils/builders/testing_beacon_block_builder.rs @@ -271,7 +271,7 @@ fn build_proposer_slashing( Signature::new(message, domain, secret_key) }; - TestingProposerSlashingBuilder::double_vote::(validator_index, signer, spec) + TestingProposerSlashingBuilder::double_vote::(validator_index, signer) } /// Builds an `AttesterSlashing` for some `validator_indices`. diff --git a/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs b/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs index 99c005472..67668d130 100644 --- a/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs +++ b/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs @@ -17,7 +17,7 @@ impl TestingProposerSlashingBuilder { /// - `domain: Domain` /// /// Where domain is a domain "constant" (e.g., `spec.domain_attestation`). - pub fn double_vote(proposer_index: u64, signer: F, spec: &ChainSpec) -> ProposerSlashing + pub fn double_vote(proposer_index: u64, signer: F) -> ProposerSlashing where T: EthSpec, F: Fn(u64, &[u8], Epoch, Domain) -> Signature, diff --git a/eth2/types/src/test_utils/serde_utils.rs b/eth2/types/src/test_utils/serde_utils.rs index be8f002ad..079551b58 100644 --- a/eth2/types/src/test_utils/serde_utils.rs +++ b/eth2/types/src/test_utils/serde_utils.rs @@ -13,6 +13,7 @@ where u8::from_str_radix(&s.as_str()[2..], 16).map_err(D::Error::custom) } +#[allow(clippy::trivially_copy_pass_by_ref)] // Serde requires the `byte` to be a ref. pub fn u8_to_hex_str(byte: &u8, serializer: S) -> Result where S: Serializer, diff --git a/eth2/utils/eth2_config/src/lib.rs b/eth2/utils/eth2_config/src/lib.rs index c4d4736bd..9d50a95c1 100644 --- a/eth2/utils/eth2_config/src/lib.rs +++ b/eth2/utils/eth2_config/src/lib.rs @@ -80,7 +80,7 @@ where ) })?; file.write_all(toml_encoded.as_bytes()) - .expect(&format!("Unable to write to {:?}", path)); + .unwrap_or_else(|_| panic!("Unable to write to {:?}", path)); } Ok(()) diff --git a/tests/ef_tests/src/case_result.rs b/tests/ef_tests/src/case_result.rs index cd40ac8ce..88fd353a1 100644 --- a/tests/ef_tests/src/case_result.rs +++ b/tests/ef_tests/src/case_result.rs @@ -28,13 +28,10 @@ pub fn compare_beacon_state_results_without_caches( result: &mut Result, E>, expected: &mut Option>, ) -> Result<(), Error> { - match (result.as_mut(), expected.as_mut()) { - (Ok(ref mut result), Some(ref mut expected)) => { - result.drop_all_caches(); - expected.drop_all_caches(); - } - _ => (), - }; + if let (Ok(ref mut result), Some(ref mut expected)) = (result.as_mut(), expected.as_mut()) { + result.drop_all_caches(); + expected.drop_all_caches(); + } compare_result_detailed(&result, &expected) } diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index df1a9428b..5b83ea793 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -70,7 +70,7 @@ where impl YamlDecode for Cases { /// Decodes a YAML list of test cases - fn yaml_decode(yaml: &String) -> Result { + fn yaml_decode(yaml: &str) -> Result { let mut p = 0; let mut elems: Vec<&str> = yaml .match_indices("\n- ") diff --git a/tests/ef_tests/src/cases/bls_aggregate_pubkeys.rs b/tests/ef_tests/src/cases/bls_aggregate_pubkeys.rs index 6cd37ec36..6e38743f2 100644 --- a/tests/ef_tests/src/cases/bls_aggregate_pubkeys.rs +++ b/tests/ef_tests/src/cases/bls_aggregate_pubkeys.rs @@ -10,8 +10,8 @@ pub struct BlsAggregatePubkeys { } impl YamlDecode for BlsAggregatePubkeys { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/bls_aggregate_sigs.rs b/tests/ef_tests/src/cases/bls_aggregate_sigs.rs index 5b69a6134..eeecab82c 100644 --- a/tests/ef_tests/src/cases/bls_aggregate_sigs.rs +++ b/tests/ef_tests/src/cases/bls_aggregate_sigs.rs @@ -10,8 +10,8 @@ pub struct BlsAggregateSigs { } impl YamlDecode for BlsAggregateSigs { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/bls_g2_compressed.rs b/tests/ef_tests/src/cases/bls_g2_compressed.rs index e6895ca1a..185cb58f3 100644 --- a/tests/ef_tests/src/cases/bls_g2_compressed.rs +++ b/tests/ef_tests/src/cases/bls_g2_compressed.rs @@ -16,8 +16,8 @@ pub struct BlsG2Compressed { } impl YamlDecode for BlsG2Compressed { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } @@ -46,13 +46,13 @@ impl Case for BlsG2Compressed { } // Converts a vector to u64 (from big endian) -fn bytes_to_u64(array: &Vec) -> u64 { +fn bytes_to_u64(array: &[u8]) -> u64 { let mut result: u64 = 0; for (i, value) in array.iter().rev().enumerate() { if i == 8 { break; } - result += u64::pow(2, i as u32 * 8) * (*value as u64); + result += u64::pow(2, i as u32 * 8) * u64::from(*value); } result } diff --git a/tests/ef_tests/src/cases/bls_g2_uncompressed.rs b/tests/ef_tests/src/cases/bls_g2_uncompressed.rs index 93b1e1c51..962b6aac3 100644 --- a/tests/ef_tests/src/cases/bls_g2_uncompressed.rs +++ b/tests/ef_tests/src/cases/bls_g2_uncompressed.rs @@ -16,8 +16,8 @@ pub struct BlsG2Uncompressed { } impl YamlDecode for BlsG2Uncompressed { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } @@ -56,13 +56,13 @@ impl Case for BlsG2Uncompressed { } // Converts a vector to u64 (from big endian) -fn bytes_to_u64(array: &Vec) -> u64 { +fn bytes_to_u64(array: &[u8]) -> u64 { let mut result: u64 = 0; for (i, value) in array.iter().rev().enumerate() { if i == 8 { break; } - result += u64::pow(2, i as u32 * 8) * (*value as u64); + result += u64::pow(2, i as u32 * 8) * u64::from(*value); } result } diff --git a/tests/ef_tests/src/cases/bls_priv_to_pub.rs b/tests/ef_tests/src/cases/bls_priv_to_pub.rs index c558d0142..d72a43bbb 100644 --- a/tests/ef_tests/src/cases/bls_priv_to_pub.rs +++ b/tests/ef_tests/src/cases/bls_priv_to_pub.rs @@ -10,8 +10,8 @@ pub struct BlsPrivToPub { } impl YamlDecode for BlsPrivToPub { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/bls_sign_msg.rs b/tests/ef_tests/src/cases/bls_sign_msg.rs index a361f2523..e62c3550f 100644 --- a/tests/ef_tests/src/cases/bls_sign_msg.rs +++ b/tests/ef_tests/src/cases/bls_sign_msg.rs @@ -17,8 +17,8 @@ pub struct BlsSign { } impl YamlDecode for BlsSign { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } @@ -46,13 +46,13 @@ impl Case for BlsSign { } // Converts a vector to u64 (from big endian) -fn bytes_to_u64(array: &Vec) -> u64 { +fn bytes_to_u64(array: &[u8]) -> u64 { let mut result: u64 = 0; for (i, value) in array.iter().rev().enumerate() { if i == 8 { break; } - result += u64::pow(2, i as u32 * 8) * (*value as u64); + result += u64::pow(2, i as u32 * 8) * u64::from(*value); } result } diff --git a/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs b/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs index afdb9cc31..bf1564b97 100644 --- a/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs +++ b/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs @@ -14,8 +14,8 @@ pub struct EpochProcessingCrosslinks { } impl YamlDecode for EpochProcessingCrosslinks { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs b/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs index 092a8a709..02311656e 100644 --- a/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs +++ b/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs @@ -14,8 +14,8 @@ pub struct EpochProcessingRegistryUpdates { } impl YamlDecode for EpochProcessingRegistryUpdates { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/operations_attester_slashing.rs b/tests/ef_tests/src/cases/operations_attester_slashing.rs index 1b95f4359..8f2338054 100644 --- a/tests/ef_tests/src/cases/operations_attester_slashing.rs +++ b/tests/ef_tests/src/cases/operations_attester_slashing.rs @@ -15,8 +15,8 @@ pub struct OperationsAttesterSlashing { } impl YamlDecode for OperationsAttesterSlashing { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/operations_deposit.rs b/tests/ef_tests/src/cases/operations_deposit.rs index 8100590fd..835706705 100644 --- a/tests/ef_tests/src/cases/operations_deposit.rs +++ b/tests/ef_tests/src/cases/operations_deposit.rs @@ -16,8 +16,8 @@ pub struct OperationsDeposit { } impl YamlDecode for OperationsDeposit { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/operations_exit.rs b/tests/ef_tests/src/cases/operations_exit.rs index cfe20d82b..f38f327ea 100644 --- a/tests/ef_tests/src/cases/operations_exit.rs +++ b/tests/ef_tests/src/cases/operations_exit.rs @@ -15,8 +15,8 @@ pub struct OperationsExit { } impl YamlDecode for OperationsExit { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/operations_proposer_slashing.rs b/tests/ef_tests/src/cases/operations_proposer_slashing.rs index 43293dfbc..cf498079f 100644 --- a/tests/ef_tests/src/cases/operations_proposer_slashing.rs +++ b/tests/ef_tests/src/cases/operations_proposer_slashing.rs @@ -15,8 +15,8 @@ pub struct OperationsProposerSlashing { } impl YamlDecode for OperationsProposerSlashing { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/operations_transfer.rs b/tests/ef_tests/src/cases/operations_transfer.rs index 66318e750..966023b2a 100644 --- a/tests/ef_tests/src/cases/operations_transfer.rs +++ b/tests/ef_tests/src/cases/operations_transfer.rs @@ -15,8 +15,8 @@ pub struct OperationsTransfer { } impl YamlDecode for OperationsTransfer { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } diff --git a/tests/ef_tests/src/cases/shuffling.rs b/tests/ef_tests/src/cases/shuffling.rs index 2920840c8..d7ff40e59 100644 --- a/tests/ef_tests/src/cases/shuffling.rs +++ b/tests/ef_tests/src/cases/shuffling.rs @@ -14,8 +14,8 @@ pub struct Shuffling { } impl YamlDecode for Shuffling { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } @@ -30,7 +30,6 @@ impl Case for Shuffling { // Test get_permuted_index let shuffling = (0..self.count) - .into_iter() .map(|i| { get_permutated_index(i, self.count, &seed, spec.shuffle_round_count).unwrap() }) diff --git a/tests/ef_tests/src/cases/ssz_generic.rs b/tests/ef_tests/src/cases/ssz_generic.rs index 09aba39f1..ca49d2106 100644 --- a/tests/ef_tests/src/cases/ssz_generic.rs +++ b/tests/ef_tests/src/cases/ssz_generic.rs @@ -15,8 +15,8 @@ pub struct SszGeneric { } impl YamlDecode for SszGeneric { - fn yaml_decode(yaml: &String) -> Result { - Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + fn yaml_decode(yaml: &str) -> Result { + Ok(serde_yaml::from_str(yaml).unwrap()) } } @@ -45,11 +45,7 @@ impl Case for SszGeneric { } /// Execute a `ssz_generic` test case. -fn ssz_generic_test( - should_be_ok: bool, - ssz: &String, - value: &Option, -) -> Result<(), Error> +fn ssz_generic_test(should_be_ok: bool, ssz: &str, value: &Option) -> Result<(), Error> where T: Decode + YamlDecode + Debug + PartialEq, { diff --git a/tests/ef_tests/src/cases/ssz_static.rs b/tests/ef_tests/src/cases/ssz_static.rs index 374b90bd2..3365a51e1 100644 --- a/tests/ef_tests/src/cases/ssz_static.rs +++ b/tests/ef_tests/src/cases/ssz_static.rs @@ -55,7 +55,7 @@ where } impl YamlDecode for SszStatic { - fn yaml_decode(yaml: &String) -> Result { + fn yaml_decode(yaml: &str) -> Result { serde_yaml::from_str(yaml).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } } diff --git a/tests/ef_tests/src/doc.rs b/tests/ef_tests/src/doc.rs index 301ba9178..3f4284501 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -136,14 +136,14 @@ pub fn print_failures(doc: &Doc, results: &[CaseResult]) { println!("Test Failure"); println!("Title: {}", header.title); println!("File: {:?}", doc.path); - println!(""); + println!(); println!( "{} tests, {} failures, {} passes.", results.len(), failures.len(), results.len() - failures.len() ); - println!(""); + println!(); for failure in failures { let error = failure.result.clone().unwrap_err(); @@ -157,5 +157,5 @@ pub fn print_failures(doc: &Doc, results: &[CaseResult]) { ); println!("{}", error.message()); } - println!(""); + println!(); } diff --git a/tests/ef_tests/src/yaml_decode.rs b/tests/ef_tests/src/yaml_decode.rs index 974df8311..c89dd92a9 100644 --- a/tests/ef_tests/src/yaml_decode.rs +++ b/tests/ef_tests/src/yaml_decode.rs @@ -8,14 +8,14 @@ pub use utils::*; pub trait YamlDecode: Sized { /// Decode an object from the test specification YAML. - fn yaml_decode(string: &String) -> Result; + fn yaml_decode(string: &str) -> Result; } /// Basic types can general be decoded with the `parse` fn if they implement `str::FromStr`. macro_rules! impl_via_parse { ($ty: ty) => { impl YamlDecode for $ty { - fn yaml_decode(string: &String) -> Result { + fn yaml_decode(string: &str) -> Result { string .parse::() .map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) @@ -34,7 +34,7 @@ impl_via_parse!(u64); macro_rules! impl_via_from_dec_str { ($ty: ty) => { impl YamlDecode for $ty { - fn yaml_decode(string: &String) -> Result { + fn yaml_decode(string: &str) -> Result { Self::from_dec_str(string).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } } @@ -48,7 +48,7 @@ impl_via_from_dec_str!(U256); macro_rules! impl_via_serde_yaml { ($ty: ty) => { impl YamlDecode for $ty { - fn yaml_decode(string: &String) -> Result { + fn yaml_decode(string: &str) -> Result { serde_yaml::from_str(string) .map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } diff --git a/tests/ef_tests/src/yaml_decode/utils.rs b/tests/ef_tests/src/yaml_decode/utils.rs index 059d3b5d2..7b6caac72 100644 --- a/tests/ef_tests/src/yaml_decode/utils.rs +++ b/tests/ef_tests/src/yaml_decode/utils.rs @@ -3,7 +3,7 @@ pub fn yaml_split_header_and_cases(mut yaml: String) -> (String, String) { // + 1 to skip the \n we used for matching. let mut test_cases = yaml.split_off(test_cases_start + 1); - let end_of_first_line = test_cases.find("\n").unwrap(); + let end_of_first_line = test_cases.find('\n').unwrap(); let test_cases = test_cases.split_off(end_of_first_line + 1); (yaml, test_cases)