diff --git a/fil-proofs-tooling/src/bin/micro.rs b/fil-proofs-tooling/src/bin/micro.rs index 8e882b275..b8e210f9b 100644 --- a/fil-proofs-tooling/src/bin/micro.rs +++ b/fil-proofs-tooling/src/bin/micro.rs @@ -311,9 +311,10 @@ mod tests { use super::*; #[test] + #[allow(clippy::float_cmp)] fn test_time_to_us() { - assert_eq!(time_to_us("123.12 us"), 123.12); - assert_eq!(time_to_us("1.0 s"), 1_000_000.); + assert_eq!(time_to_us("123.12 us"), 123.12); // No math done on 'us' so strict float cmp is ok. + assert_eq!(time_to_us("1.0 s"), 1_000_000.); // Multiplication, so strict float cmp is ok. } #[test] @@ -371,8 +372,8 @@ median [138.33 us 143.23 us] med. abs. dev. [1.7507 ms 8.4109 ms]"; unit: Some("us".to_string()) }), r_2: Some(Interval { - start: 0.8124914, - end: 0.8320154, + start: 0.812_491_4, + end: 0.832_015_4, unit: None }), std_dev: Some(Interval { @@ -449,8 +450,8 @@ median [138.33 us 143.23 us] med. abs. dev. [1.7507 ms 8.4109 ms]"; unit: Some("us".to_string()) }), r_2: Some(Interval { - start: 0.8124914, - end: 0.8320154, + start: 0.812_491_4, + end: 0.832_015_4, unit: None }), std_dev: Some(Interval { diff --git a/filecoin-proofs/benches/preprocessing.rs b/filecoin-proofs/benches/preprocessing.rs index 2e43e6296..cf2bd7fa9 100644 --- a/filecoin-proofs/benches/preprocessing.rs +++ b/filecoin-proofs/benches/preprocessing.rs @@ -55,7 +55,7 @@ fn preprocessing_benchmark(c: &mut Criterion) { }); stop_profile(); }, - vec![128, 256, 512, 256_000, 512_000, 1024_000, 2048_000], + vec![128, 256, 512, 256_000, 512_000, 1_024_000, 2_048_000], ) .sample_size(10) .throughput(|s| Throughput::Bytes(*s as u64)) diff --git a/filecoin-proofs/src/fr32.rs b/filecoin-proofs/src/fr32.rs index 4ba25f0e4..a4d9b7e9f 100644 --- a/filecoin-proofs/src/fr32.rs +++ b/filecoin-proofs/src/fr32.rs @@ -948,7 +948,7 @@ mod tests { .chunks(FR32_PADDING_MAP.data_bits) .into_iter() { - padded_data.extend(data_unit.into_iter()); + padded_data.extend(data_unit); // To avoid reconverting the iterator, we deduce if we need the padding // by the length of `padded_data`: a full data unit would not leave the diff --git a/filecoin-proofs/src/fr32_reader.rs b/filecoin-proofs/src/fr32_reader.rs index 4352402bf..9486a3f6e 100644 --- a/filecoin-proofs/src/fr32_reader.rs +++ b/filecoin-proofs/src/fr32_reader.rs @@ -328,9 +328,9 @@ mod tests { buffer.copy_from_slice(&val[..]); buffer.reset_available(64); - for i in 0..8 { + for (i, &byte) in val.iter().enumerate().take(8) { let read = buffer.read_u8(); - assert_eq!(read, val[i], "failed to read byte {}", i); + assert_eq!(read, byte, "failed to read byte {}", i); } } @@ -499,7 +499,7 @@ mod tests { let raw_data: BitVec = BitVec::from(raw_data); for data_unit in raw_data.into_iter().chunks(DATA_BITS as usize).into_iter() { - padded_data.extend(data_unit.into_iter()); + padded_data.extend(data_unit); // To avoid reconverting the iterator, we deduce if we need the padding // by the length of `padded_data`: a full data unit would not leave the @@ -515,14 +515,16 @@ mod tests { } fn validate_fr32(bytes: &[u8]) { - let chunks = (bytes.len() as f64 / 32 as f64).ceil() as usize; + let chunks = (bytes.len() as f64 / 32_f64).ceil() as usize; for (i, chunk) in bytes.chunks(32).enumerate() { - let _ = storage_proofs::fr32::bytes_into_fr(chunk).expect(&format!( - "chunk {}/{} cannot be converted to valid Fr: {:?}", - i + 1, - chunks, - chunk - )); + let _ = storage_proofs::fr32::bytes_into_fr(chunk).unwrap_or_else(|_| { + panic!( + "chunk {}/{} cannot be converted to valid Fr: {:?}", + i + 1, + chunks, + chunk + ) + }); } } @@ -542,13 +544,13 @@ mod tests { let mut reader = Fr32Reader::new(io::Cursor::new(&source)); reader.read_to_end(&mut buf).unwrap(); - for i in 0..31 { - assert_eq!(buf[i], i as u8 + 1); + for (i, &byte) in buf.iter().enumerate().take(31) { + assert_eq!(byte, i as u8 + 1); } assert_eq!(buf[31], 63); // Six least significant bits of 0xff assert_eq!(buf[32], (1 << 2) | 0b11); // 7 - for i in 33..63 { - assert_eq!(buf[i], (i as u8 - 31) << 2); + for (i, &byte) in buf.iter().enumerate().skip(33).take(30) { + assert_eq!(byte, (i as u8 - 31) << 2); } assert_eq!(buf[63], (0x0f << 2)); // 4-bits of ones, half of 0xff, shifted by two, followed by two bits of 0-padding. assert_eq!(buf[64], 0x0f | 9 << 4); // The last half of 0xff, 'followed' by 9. diff --git a/filecoin-proofs/src/pieces.rs b/filecoin-proofs/src/pieces.rs index 59e05b991..d5e6a849e 100644 --- a/filecoin-proofs/src/pieces.rs +++ b/filecoin-proofs/src/pieces.rs @@ -483,7 +483,7 @@ mod tests { assert!( verify_pieces( &comm_d, - &vec![a.clone(), b.clone(), c.clone(), d.clone()], + &[a.clone(), b.clone(), c.clone(), d.clone()], sector_size ) .expect("failed to verify"), @@ -491,30 +491,28 @@ mod tests { ); assert!( - verify_pieces(&comm_d, &vec![e.clone(), c.clone(), d.clone()], sector_size) - .expect("failed to verify"), + verify_pieces(&comm_d, &[e.clone(), c, d], sector_size).expect("failed to verify"), "[e, c, d]" ); assert!( - verify_pieces(&comm_d, &vec![e.clone(), f.clone()], sector_size) - .expect("failed to verify"), + verify_pieces(&comm_d, &[e, f.clone()], sector_size).expect("failed to verify"), "[e, f]" ); assert!( - verify_pieces(&comm_d, &vec![a.clone(), b.clone(), f.clone()], sector_size) - .expect("failed to verify"), + verify_pieces(&comm_d, &[a, b, f], sector_size).expect("failed to verify"), "[a, b, f]" ); assert!( - verify_pieces(&comm_d, &vec![g], sector_size).expect("failed to verify"), + verify_pieces(&comm_d, &[g], sector_size).expect("failed to verify"), "[g]" ); } #[test] + #[allow(clippy::identity_op)] fn test_verify_padded_pieces() { // [ // {(A0 00) (BB BB)} -> A(1) P(1) P(1) P(1) B(4) @@ -556,7 +554,7 @@ mod tests { pad.clone(), pad.clone(), pad.clone(), - pad.clone(), + pad, ]; let hash = |a, b| { diff --git a/filecoin-proofs/tests/api.rs b/filecoin-proofs/tests/api.rs index 91b162830..2573fe396 100644 --- a/filecoin-proofs/tests/api.rs +++ b/filecoin-proofs/tests/api.rs @@ -331,8 +331,7 @@ fn create_seal( ) -> Result<(SectorId, NamedTempFile, Commitment, tempfile::TempDir)> { init_logger(); - let number_of_bytes_in_piece = - UnpaddedBytesAmount::from(PaddedBytesAmount(sector_size.clone())); + let number_of_bytes_in_piece = UnpaddedBytesAmount::from(PaddedBytesAmount(sector_size)); let piece_bytes: Vec = (0..number_of_bytes_in_piece.0) .map(|_| rand::random::()) @@ -359,7 +358,7 @@ fn create_seal( let sealed_sector_file = NamedTempFile::new()?; let mut unseal_file = NamedTempFile::new()?; let config = PoRepConfig { - sector_size: SectorSize(sector_size.clone()), + sector_size: SectorSize(sector_size), partitions: PoRepProofPartitions( *POREP_PARTITIONS.read().unwrap().get(§or_size).unwrap(), ), @@ -396,8 +395,8 @@ fn create_seal( sealed_sector_file.path(), )?; - let comm_d = pre_commit_output.comm_d.clone(); - let comm_r = pre_commit_output.comm_r.clone(); + let comm_d = pre_commit_output.comm_d; + let comm_r = pre_commit_output.comm_r; validate_cache_for_commit::<_, _, Tree>(cache_dir.path(), sealed_sector_file.path())?; diff --git a/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs b/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs index 2c0a1a5b2..5c669be86 100644 --- a/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs +++ b/filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs @@ -41,7 +41,7 @@ fn nothing_to_fetch_if_cache_fully_hydrated() -> Result<(), FailureError> { "aaa.vk".to_string(), ParameterData { cid: "".to_string(), - digest: aaa_checksum.clone(), + digest: aaa_checksum, sector_size: 1234, }, ); diff --git a/filecoin-proofs/tests/paramfetch/support/session.rs b/filecoin-proofs/tests/paramfetch/support/session.rs index 62cd27090..8f6195fbf 100644 --- a/filecoin-proofs/tests/paramfetch/support/session.rs +++ b/filecoin-proofs/tests/paramfetch/support/session.rs @@ -4,7 +4,6 @@ use std::path::{Path, PathBuf}; use failure::SyncFailure; use rexpect::session::PtyBashSession; -use tempfile; use tempfile::TempDir; use crate::support::{cargo_bin, spawn_bash_with_retries}; @@ -52,7 +51,7 @@ impl ParamFetchSessionBuilder { filename: P, r: &mut R, ) -> ParamFetchSessionBuilder { - let mut pbuf = self.cache_dir.path().clone().to_path_buf(); + let mut pbuf = self.cache_dir.path().to_path_buf(); pbuf.push(filename.as_ref()); let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); @@ -78,7 +77,7 @@ impl ParamFetchSessionBuilder { s.push_str(&wl.join(",")); s }) - .unwrap_or("".to_string()); + .unwrap_or_else(|| "".to_string()); let json_argument = if self.manifest.is_some() { format!("--json={:?}", self.manifest.unwrap()) diff --git a/filecoin-proofs/tests/parampublish/read_metadata_files.rs b/filecoin-proofs/tests/parampublish/read_metadata_files.rs index ab07c673c..9de336549 100644 --- a/filecoin-proofs/tests/parampublish/read_metadata_files.rs +++ b/filecoin-proofs/tests/parampublish/read_metadata_files.rs @@ -21,11 +21,11 @@ fn fails_if_missing_metadata_file() -> Result<(), FailureError> { #[test] fn fails_if_malformed_metadata_file() -> Result<(), FailureError> { - let mut malformed: &[u8] = &vec![42]; + let mut malformed: &[u8] = &[42]; let (mut session, _) = ParamPublishSessionBuilder::new() .with_session_timeout_ms(1000) - .with_files(&vec!["v11-aaa.vk", "v11-aaa.params"]) + .with_files(&["v11-aaa.vk", "v11-aaa.params"]) .with_file_and_bytes("v11-aaa.meta", &mut malformed) .with_prompt_disabled() .build(); diff --git a/filecoin-proofs/tests/parampublish/support/session.rs b/filecoin-proofs/tests/parampublish/support/session.rs index bf2dc916d..796f61981 100644 --- a/filecoin-proofs/tests/parampublish/support/session.rs +++ b/filecoin-proofs/tests/parampublish/support/session.rs @@ -5,7 +5,6 @@ use std::path::{Path, PathBuf}; use failure::SyncFailure; use rand::Rng; use rexpect::session::PtyBashSession; -use tempfile; use tempfile::TempDir; use storage_proofs::parameter_cache::{CacheEntryMetadata, PARAMETER_CACHE_ENV_VAR}; @@ -25,7 +24,7 @@ impl ParamPublishSessionBuilder { pub fn new() -> ParamPublishSessionBuilder { let temp_dir = tempfile::tempdir().expect("could not create temp dir"); - let mut pbuf = temp_dir.path().clone().to_path_buf(); + let mut pbuf = temp_dir.path().to_path_buf(); pbuf.push("parameters.json"); File::create(&pbuf).expect("failed to create file in temp dir"); @@ -49,21 +48,20 @@ impl ParamPublishSessionBuilder { /// Create empty files with the given names in the cache directory. pub fn with_files>(self, filenames: &[P]) -> ParamPublishSessionBuilder { - filenames - .into_iter() - .fold(self, |acc, item| acc.with_file(item)) + filenames.iter().fold(self, |acc, item| acc.with_file(item)) } /// Create a file containing 32 random bytes with the given name in the /// cache directory. pub fn with_file>(mut self, filename: P) -> ParamPublishSessionBuilder { - let mut pbuf = self.cache_dir.path().clone().to_path_buf(); + let mut pbuf = self.cache_dir.path().to_path_buf(); pbuf.push(filename.as_ref()); let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); - file.write(&random_bytes).expect("failed to write bytes"); + file.write_all(&random_bytes) + .expect("failed to write bytes"); self.cached_file_pbufs.push(pbuf); self @@ -75,7 +73,7 @@ impl ParamPublishSessionBuilder { filename: P, r: &mut R, ) -> ParamPublishSessionBuilder { - let mut pbuf = self.cache_dir.path().clone().to_path_buf(); + let mut pbuf = self.cache_dir.path().to_path_buf(); pbuf.push(filename.as_ref()); let mut file = File::create(&pbuf).expect("failed to create file in temp dir"); @@ -124,8 +122,7 @@ impl ParamPublishSessionBuilder { let cache_dir_path = format!("{:?}", self.cache_dir.path()); let cache_contents: Vec = std::fs::read_dir(&self.cache_dir) - .expect(&format!("failed to read cache dir {:?}", self.cache_dir)) - .into_iter() + .unwrap_or_else(|_| panic!("failed to read cache dir {:?}", self.cache_dir)) .map(|x| x.expect("failed to get dir entry")) .map(|x| x.path()) .collect(); diff --git a/filecoin-proofs/tests/parampublish/write_json_manifest.rs b/filecoin-proofs/tests/parampublish/write_json_manifest.rs index 2c75c4781..0e7a2cda3 100644 --- a/filecoin-proofs/tests/parampublish/write_json_manifest.rs +++ b/filecoin-proofs/tests/parampublish/write_json_manifest.rs @@ -79,7 +79,7 @@ fn filename_to_checksum>( .file_name() .and_then(|os_str| os_str.to_str()) .map(|s| s.to_string()) - .unwrap_or("".to_string()), + .unwrap_or_else(|| "".to_string()), ipfs_bin .compute_checksum(item) .expect("failed to compute checksum"), diff --git a/storage-proofs/core/benches/blake2s.rs b/storage-proofs/core/benches/blake2s.rs index cd31ccb4d..26a728254 100644 --- a/storage-proofs/core/benches/blake2s.rs +++ b/storage-proofs/core/benches/blake2s.rs @@ -14,7 +14,7 @@ impl<'a> Circuit for Blake2sExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -51,13 +51,9 @@ fn blake2s_benchmark(c: &mut Criterion) { fn blake2s_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); - let groth_params = generate_random_parameters::( - Blake2sExample { - data: &vec![None; 256], - }, - &mut rng1, - ) - .unwrap(); + let groth_params = + generate_random_parameters::(Blake2sExample { data: &[None; 256] }, &mut rng1) + .unwrap(); let params = vec![32]; diff --git a/storage-proofs/core/benches/drgraph.rs b/storage-proofs/core/benches/drgraph.rs index 7746ad198..f7afb7f58 100644 --- a/storage-proofs/core/benches/drgraph.rs +++ b/storage-proofs/core/benches/drgraph.rs @@ -2,6 +2,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Parameter use storage_proofs_core::drgraph::*; use storage_proofs_core::hasher::pedersen::*; +#[allow(clippy::unit_arg)] fn drgraph(c: &mut Criterion) { let params = vec![12, 24, 128, 1024]; diff --git a/storage-proofs/core/benches/merkle.rs b/storage-proofs/core/benches/merkle.rs index a55a3718f..26315eb17 100644 --- a/storage-proofs/core/benches/merkle.rs +++ b/storage-proofs/core/benches/merkle.rs @@ -5,7 +5,7 @@ use storage_proofs_core::merkle::{create_base_merkle_tree, BinaryMerkleTree}; fn merkle_benchmark(c: &mut Criterion) { #[cfg(feature = "big-sector-sizes-bench")] - let params = vec![128, 1024, 1048576]; + let params = vec![128, 1024, 1_048_576]; #[cfg(not(feature = "big-sector-sizes-bench"))] let params = vec![128, 1024]; diff --git a/storage-proofs/core/benches/pedersen.rs b/storage-proofs/core/benches/pedersen.rs index 1ffadc56c..752316556 100644 --- a/storage-proofs/core/benches/pedersen.rs +++ b/storage-proofs/core/benches/pedersen.rs @@ -15,7 +15,7 @@ impl<'a> Circuit for PedersenExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -45,7 +45,7 @@ impl<'a> Circuit for PedersenMdExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -106,9 +106,7 @@ fn pedersen_md_benchmark(c: &mut Criterion) { fn pedersen_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); let groth_params = generate_random_parameters::( - PedersenExample { - data: &vec![None; 256], - }, + PedersenExample { data: &[None; 256] }, &mut rng1, ) .unwrap(); @@ -160,9 +158,7 @@ fn pedersen_circuit_benchmark(c: &mut Criterion) { fn pedersen_md_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); let groth_params = generate_random_parameters::( - PedersenMdExample { - data: &vec![None; 256], - }, + PedersenMdExample { data: &[None; 256] }, &mut rng1, ) .unwrap(); @@ -216,5 +212,6 @@ criterion_group!( pedersen_benchmark, pedersen_md_benchmark, pedersen_circuit_benchmark, + pedersen_md_circuit_benchmark, ); criterion_main!(benches); diff --git a/storage-proofs/core/benches/sha256.rs b/storage-proofs/core/benches/sha256.rs index f75bec6b7..df88c6638 100644 --- a/storage-proofs/core/benches/sha256.rs +++ b/storage-proofs/core/benches/sha256.rs @@ -17,7 +17,7 @@ impl<'a> Circuit for Sha256Example<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( diff --git a/storage-proofs/core/benches/xor.rs b/storage-proofs/core/benches/xor.rs index a685f641f..8ae466237 100644 --- a/storage-proofs/core/benches/xor.rs +++ b/storage-proofs/core/benches/xor.rs @@ -17,7 +17,7 @@ impl<'a> Circuit for XorExample<'a> { fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { let key: Vec = self .key - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -28,7 +28,7 @@ impl<'a> Circuit for XorExample<'a> { .collect::, SynthesisError>>()?; let data: Vec = self .data - .into_iter() + .iter() .enumerate() .map(|(i, b)| { Ok(Boolean::from(boolean::AllocatedBit::alloc( @@ -68,8 +68,8 @@ fn xor_circuit_benchmark(c: &mut Criterion) { let mut rng1 = thread_rng(); let groth_params = generate_random_parameters::( XorExample { - key: &vec![None; 8 * 32], - data: &vec![None; 256], + key: &[None; 8 * 32], + data: &[None; 256], }, &mut rng1, ) diff --git a/storage-proofs/core/src/crypto/feistel.rs b/storage-proofs/core/src/crypto/feistel.rs index 3f8f0c0d9..afa98b340 100644 --- a/storage-proofs/core/src/crypto/feistel.rs +++ b/storage-proofs/core/src/crypto/feistel.rs @@ -183,10 +183,8 @@ mod tests { if expect_success { assert!(equal, "failed to permute (n = {})", n); assert!(in_range, "output number is too big (n = {})", n); - } else { - if !equal || !in_range { - failed = true; - } + } else if !equal || !in_range { + failed = true; } } if !expect_success { diff --git a/storage-proofs/core/src/crypto/pedersen.rs b/storage-proofs/core/src/crypto/pedersen.rs index 4fc530e73..830237915 100644 --- a/storage-proofs/core/src/crypto/pedersen.rs +++ b/storage-proofs/core/src/crypto/pedersen.rs @@ -405,8 +405,8 @@ mod tests { let hashed = pedersen_md_no_padding(&flat); let mut hasher = Hasher::new(&x[0]).unwrap(); - for k in 1..5 { - hasher.update(&x[k]).unwrap(); + for val in x.iter().skip(1).take(4) { + hasher.update(&val).unwrap(); } let hasher_final = hasher.finalize().unwrap(); diff --git a/storage-proofs/core/src/drgraph.rs b/storage-proofs/core/src/drgraph.rs index 599dc5eb8..1b309676d 100644 --- a/storage-proofs/core/src/drgraph.rs +++ b/storage-proofs/core/src/drgraph.rs @@ -264,7 +264,7 @@ mod tests { let degree = BASE_DEGREE; let porep_id = [123; 32]; - for size in vec![4, 16, 256, 2048] { + for &size in &[4, 16, 256, 2048] { let g = BucketGraph::::new(size, degree, 0, porep_id).unwrap(); assert_eq!(g.size(), size, "wrong nodes count"); diff --git a/storage-proofs/core/src/fr32.rs b/storage-proofs/core/src/fr32.rs index 17fba632a..47ccfebee 100644 --- a/storage-proofs/core/src/fr32.rs +++ b/storage-proofs/core/src/fr32.rs @@ -109,8 +109,8 @@ mod tests { use super::*; fn bytes_fr_test(bytes: Fr32Ary, expect_success: bool) { - let mut b = &bytes[..]; - let fr_result = bytes_into_fr(&mut b); + let b = &bytes[..]; + let fr_result = bytes_into_fr(&b); if expect_success { let f = fr_result.expect("Failed to convert bytes to `Fr`"); let b2 = fr_into_bytes(&f); @@ -164,8 +164,7 @@ mod tests { } fn bytes_into_frs_into_bytes_test(bytes: &Fr32) { - let mut bytes = bytes.clone(); - let frs = bytes_into_frs(&mut bytes).expect("Failed to convert bytes into a `Vec`"); + let frs = bytes_into_frs(bytes).expect("Failed to convert bytes into a `Vec`"); assert!(frs.len() == 3); let bytes_back = frs_into_bytes(&frs); assert!(bytes.to_vec() == bytes_back); diff --git a/storage-proofs/core/src/gadgets/constraint.rs b/storage-proofs/core/src/gadgets/constraint.rs index 4b761a636..5935e806a 100644 --- a/storage-proofs/core/src/gadgets/constraint.rs +++ b/storage-proofs/core/src/gadgets/constraint.rs @@ -136,7 +136,7 @@ mod tests { let res = add(cs.namespace(|| "a+b"), &a, &b).expect("add failed"); - let mut tmp = a.get_value().unwrap().clone(); + let mut tmp = a.get_value().unwrap(); tmp.add_assign(&b.get_value().unwrap()); assert_eq!(res.get_value().unwrap(), tmp); @@ -156,7 +156,7 @@ mod tests { let res = sub(cs.namespace(|| "a-b"), &a, &b).expect("subtraction failed"); - let mut tmp = a.get_value().unwrap().clone(); + let mut tmp = a.get_value().unwrap(); tmp.sub_assign(&b.get_value().unwrap()); assert_eq!(res.get_value().unwrap(), tmp); diff --git a/storage-proofs/core/src/gadgets/uint64.rs b/storage-proofs/core/src/gadgets/uint64.rs index fe944c95a..da51f2ae3 100644 --- a/storage-proofs/core/src/gadgets/uint64.rs +++ b/storage-proofs/core/src/gadgets/uint64.rs @@ -184,8 +184,8 @@ mod test { let b = UInt64::from_bits_be(&v); for (i, bit) in b.bits.iter().enumerate() { - match bit { - &Boolean::Constant(bit) => { + match *bit { + Boolean::Constant(bit) => { assert!(bit == ((b.value.unwrap() >> i) & 1 == 1)); } _ => unreachable!(), @@ -216,8 +216,8 @@ mod test { let b = UInt64::from_bits(&v); for (i, bit) in b.bits.iter().enumerate() { - match bit { - &Boolean::Constant(bit) => { + match *bit { + Boolean::Constant(bit) => { assert!(bit == ((b.value.unwrap() >> i) & 1 == 1)); } _ => unreachable!(), diff --git a/storage-proofs/core/src/hasher/poseidon.rs b/storage-proofs/core/src/hasher/poseidon.rs index 4f44b1b04..580e3a074 100644 --- a/storage-proofs/core/src/hasher/poseidon.rs +++ b/storage-proofs/core/src/hasher/poseidon.rs @@ -425,7 +425,7 @@ mod tests { PoseidonDomain(Fr::one().into_repr()), ]; - let t = MerkleTree::::new(values.iter().map(|x| *x)).unwrap(); + let t = MerkleTree::::new(values.iter().copied()).unwrap(); let p = t.gen_proof(0).unwrap(); // create a proof for the first value =k Fr::one() @@ -453,7 +453,7 @@ mod tests { PoseidonDomain(Fr::one().into_repr()), ]; - let t = MerkleTree::::new(leaves.iter().map(|x| *x)).unwrap(); + let t = MerkleTree::::new(leaves.iter().copied()).unwrap(); assert_eq!(t.leafs(), 4); diff --git a/storage-proofs/core/src/merkle/proof.rs b/storage-proofs/core/src/merkle/proof.rs index df9fbcd77..e0a1cae51 100644 --- a/storage-proofs/core/src/merkle/proof.rs +++ b/storage-proofs/core/src/merkle/proof.rs @@ -718,7 +718,6 @@ mod tests { use super::super::*; use generic_array::typenum; - use rand; use crate::hasher::{Blake2sHasher, Domain, PedersenHasher, PoseidonHasher, Sha256Hasher}; use crate::merkle::{generate_tree, MerkleProofTrait}; diff --git a/storage-proofs/core/src/util.rs b/storage-proofs/core/src/util.rs index b42ac7ff9..92a796ac2 100644 --- a/storage-proofs/core/src/util.rs +++ b/storage-proofs/core/src/util.rs @@ -258,7 +258,7 @@ mod tests { let val_vec = fr_into_bytes(&val_fr); let val_num = - num::AllocatedNum::alloc(cs.namespace(|| "val_num"), || Ok(val_fr.into())).unwrap(); + num::AllocatedNum::alloc(cs.namespace(|| "val_num"), || Ok(val_fr)).unwrap(); let val_num_bits = val_num.to_bits_le(cs.namespace(|| "val_bits")).unwrap(); let bits = diff --git a/storage-proofs/porep/benches/encode.rs b/storage-proofs/porep/benches/encode.rs index 8d3b557a1..0d8cc1cf0 100644 --- a/storage-proofs/porep/benches/encode.rs +++ b/storage-proofs/porep/benches/encode.rs @@ -51,7 +51,6 @@ fn kdf_benchmark(c: &mut Criterion) { let (data, exp_data) = raw_data.split_at_mut(data.len()); let graph = &graph; - let replica_id = replica_id.clone(); b.iter(|| { black_box(create_label_exp( @@ -69,7 +68,6 @@ fn kdf_benchmark(c: &mut Criterion) { group.bench_function("non-exp", |b| { let mut data = data.clone(); let graph = &graph; - let replica_id = replica_id.clone(); b.iter(|| black_box(create_label(graph, None, &replica_id, &mut data, 1, 2))) }); diff --git a/storage-proofs/porep/benches/parents.rs b/storage-proofs/porep/benches/parents.rs index 4dff9a4e9..39b328048 100644 --- a/storage-proofs/porep/benches/parents.rs +++ b/storage-proofs/porep/benches/parents.rs @@ -37,7 +37,6 @@ fn stop_profile() { fn stop_profile() {} fn pregenerate_graph(size: usize) -> StackedBucketGraph { - let seed = [1u8; 28]; StackedBucketGraph::::new_stacked(size, BASE_DEGREE, EXP_DEGREE, [32; 32]).unwrap() } @@ -47,6 +46,7 @@ fn parents_loop>(graph: &G, parents: &mut [u32]) { .collect() } +#[allow(clippy::unit_arg)] fn parents_loop_benchmark(cc: &mut Criterion) { let sizes = vec![10, 50, 1000]; diff --git a/storage-proofs/porep/src/drg/circuit.rs b/storage-proofs/porep/src/drg/circuit.rs index 964e7b7de..00003f5de 100644 --- a/storage-proofs/porep/src/drg/circuit.rs +++ b/storage-proofs/porep/src/drg/circuit.rs @@ -382,14 +382,14 @@ mod tests { (mmapped_data.as_mut()).into(), None, config, - replica_path.clone(), + replica_path, ) .expect("failed to replicate"); let pub_inputs = drg::PublicInputs { replica_id: Some(replica_id.into()), challenges: vec![challenge], - tau: Some(tau.into()), + tau: Some(tau), }; let priv_inputs = drg::PrivateInputs:: { diff --git a/storage-proofs/porep/src/drg/compound.rs b/storage-proofs/porep/src/drg/compound.rs index 95d761110..43deb8f0b 100644 --- a/storage-proofs/porep/src/drg/compound.rs +++ b/storage-proofs/porep/src/drg/compound.rs @@ -369,7 +369,7 @@ mod tests { (mmapped_data.as_mut()).into(), data_tree, config, - replica_path.clone(), + replica_path, ) .expect("failed to replicate"); diff --git a/storage-proofs/porep/src/drg/vanilla.rs b/storage-proofs/porep/src/drg/vanilla.rs index ce1692fa7..aca96ef38 100644 --- a/storage-proofs/porep/src/drg/vanilla.rs +++ b/storage-proofs/porep/src/drg/vanilla.rs @@ -621,7 +621,6 @@ mod tests { test_helper::setup_replica, util::{data_at_node, default_rows_to_discard}, }; - use tempfile; use crate::stacked::BINARY_ARITY; @@ -666,7 +665,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config.clone(), - replica_path.clone(), + replica_path, ) .expect("replication failed"); @@ -678,7 +677,7 @@ mod tests { &pp, &replica_id, mmapped_data.as_mut(), - Some(config.clone()), + Some(config), ) .unwrap_or_else(|e| { panic!("Failed to extract data from `DrgPoRep`: {}", e); @@ -745,7 +744,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config.clone(), - replica_path.clone(), + replica_path, ) .expect("replication failed"); @@ -848,7 +847,7 @@ mod tests { let pub_inputs = PublicInputs::<::Domain> { replica_id: Some(replica_id), challenges: vec![challenge, challenge], - tau: Some(tau.clone().into()), + tau: Some(tau), }; let priv_inputs = PrivateInputs:: { @@ -876,7 +875,7 @@ mod tests { let proof = Proof::new( real_proof.replica_nodes.clone(), fake_parents, - real_proof.nodes.clone().into(), + real_proof.nodes.clone(), ); let is_valid = @@ -915,7 +914,7 @@ mod tests { let proof2 = Proof::new( real_proof.replica_nodes, fake_proof_parents, - real_proof.nodes.into(), + real_proof.nodes, ); assert!( @@ -927,7 +926,7 @@ mod tests { "verified in error -- with wrong parent proofs" ); - return (); + return; } let proof = real_proof; @@ -937,7 +936,7 @@ mod tests { PublicInputs::<::Domain> { replica_id: Some(replica_id), challenges: vec![if challenge == 1 { 2 } else { 1 }], - tau: Some(tau.into()), + tau: Some(tau), }; let verified = DrgPoRep::::verify( &pp, diff --git a/storage-proofs/porep/src/stacked/circuit/create_label.rs b/storage-proofs/porep/src/stacked/circuit/create_label.rs index 315707737..39a722be4 100644 --- a/storage-proofs/porep/src/stacked/circuit/create_label.rs +++ b/storage-proofs/porep/src/stacked/circuit/create_label.rs @@ -157,7 +157,7 @@ mod tests { let out = create_label_circuit( cs.namespace(|| "create_label"), &id_bits, - parents_bits.clone(), + parents_bits, layer_alloc, node_alloc, ) diff --git a/storage-proofs/porep/src/stacked/circuit/hash.rs b/storage-proofs/porep/src/stacked/circuit/hash.rs index bdd3ab9d4..2b327cbec 100644 --- a/storage-proofs/porep/src/stacked/circuit/hash.rs +++ b/storage-proofs/porep/src/stacked/circuit/hash.rs @@ -105,7 +105,7 @@ mod tests { assert!(cs.is_satisfied(), "constraints not satisfied"); assert_eq!(cs.num_constraints(), 598); - let expected: Fr = vanilla_hash_single_column(&vals).into(); + let expected: Fr = vanilla_hash_single_column(&vals); assert_eq!( expected, diff --git a/storage-proofs/porep/src/stacked/circuit/proof.rs b/storage-proofs/porep/src/stacked/circuit/proof.rs index 2f9eb4f05..3cf1478a2 100644 --- a/storage-proofs/porep/src/stacked/circuit/proof.rs +++ b/storage-proofs/porep/src/stacked/circuit/proof.rs @@ -426,7 +426,7 @@ mod tests { degree, expansion_degree, porep_id: arbitrary_porep_id, - layer_challenges: layer_challenges.clone(), + layer_challenges, }; let pp = StackedDrg::::setup(&sp).expect("setup failed"); @@ -449,7 +449,7 @@ mod tests { PublicInputs::<::Domain, ::Domain> { replica_id: replica_id.into(), seed, - tau: Some(tau.into()), + tau: Some(tau), k: None, }; @@ -458,13 +458,10 @@ mod tests { // Convert TemporaryAux to TemporaryAuxCache, which instantiates all // elements based on the configs stored in TemporaryAux. - let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path.clone()) + let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path) .expect("failed to restore contents of t_aux"); - let priv_inputs = PrivateInputs:: { - p_aux: p_aux.into(), - t_aux: t_aux.into(), - }; + let priv_inputs = PrivateInputs:: { p_aux, t_aux }; let proofs = StackedDrg::::prove_all_partitions( &pp, @@ -487,16 +484,10 @@ mod tests { // Verify that MetricCS returns the same metrics as TestConstraintSystem. let mut cs = MetricCS::::new(); - StackedCompound::::circuit( - &pub_inputs, - as CircuitComponent>::ComponentPrivateInputs::default(), - &proofs[0], - &pp, - None, - ) - .expect("circuit failed") - .synthesize(&mut cs.namespace(|| "stacked drgporep")) - .expect("failed to synthesize circuit"); + StackedCompound::::circuit(&pub_inputs, (), &proofs[0], &pp, None) + .expect("circuit failed") + .synthesize(&mut cs.namespace(|| "stacked drgporep")) + .expect("failed to synthesize circuit"); assert_eq!(cs.num_inputs(), expected_inputs, "wrong number of inputs"); assert_eq!( @@ -507,16 +498,10 @@ mod tests { } let mut cs = TestConstraintSystem::::new(); - StackedCompound::::circuit( - &pub_inputs, - as CircuitComponent>::ComponentPrivateInputs::default(), - &proofs[0], - &pp, - None, - ) - .expect("circuit failed") - .synthesize(&mut cs.namespace(|| "stacked drgporep")) - .expect("failed to synthesize circuit"); + StackedCompound::::circuit(&pub_inputs, (), &proofs[0], &pp, None) + .expect("circuit failed") + .synthesize(&mut cs.namespace(|| "stacked drgporep")) + .expect("failed to synthesize circuit"); assert!(cs.is_satisfied(), "constraints not satisfied"); assert_eq!(cs.num_inputs(), expected_inputs, "wrong number of inputs"); @@ -597,7 +582,7 @@ mod tests { degree, expansion_degree, porep_id: arbitrary_porep_id, - layer_challenges: layer_challenges.clone(), + layer_challenges, }, partitions: Some(partition_count), priority: false, @@ -645,7 +630,7 @@ mod tests { // Convert TemporaryAux to TemporaryAuxCache, which instantiates all // elements based on the configs stored in TemporaryAux. - let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path.clone()) + let t_aux = TemporaryAuxCache::::new(&t_aux, replica_path) .expect("failed to restore contents of t_aux"); let private_inputs = PrivateInputs:: { p_aux, t_aux }; diff --git a/storage-proofs/porep/src/stacked/vanilla/proof.rs b/storage-proofs/porep/src/stacked/vanilla/proof.rs index 87d646dfc..b316b97c1 100644 --- a/storage-proofs/porep/src/stacked/vanilla/proof.rs +++ b/storage-proofs/porep/src/stacked/vanilla/proof.rs @@ -1286,14 +1286,14 @@ mod tests { let replica_path = cache_dir.path().join("replica-path"); let mut mmapped_data = setup_replica(&data, &replica_path); - let challenges = LayerChallenges::new(DEFAULT_STACKED_LAYERS, 5); + let layer_challenges = LayerChallenges::new(DEFAULT_STACKED_LAYERS, 5); let sp = SetupParams { nodes, degree: BASE_DEGREE, expansion_degree: EXP_DEGREE, porep_id: [32; 32], - layer_challenges: challenges.clone(), + layer_challenges, }; let pp = StackedDrg::::setup(&sp).expect("setup failed"); @@ -1304,7 +1304,7 @@ mod tests { (mmapped_data.as_mut()).into(), None, config.clone(), - replica_path.clone(), + replica_path, ) .expect("replication failed"); @@ -1316,7 +1316,7 @@ mod tests { &pp, &replica_id, mmapped_data.as_mut(), - Some(config.clone()), + Some(config), ) .expect("failed to extract data"); @@ -1428,8 +1428,7 @@ mod tests { challenges.clone(), ); test_prove_verify::>( - n, - challenges.clone(), + n, challenges, ); } @@ -1471,7 +1470,7 @@ mod tests { degree, expansion_degree, porep_id: arbitrary_porep_id, - layer_challenges: challenges.clone(), + layer_challenges: challenges, }; let pp = StackedDrg::::setup(&sp).expect("setup failed"); @@ -1550,7 +1549,7 @@ mod tests { degree, expansion_degree, porep_id: [32; 32], - layer_challenges: layer_challenges.clone(), + layer_challenges, }; // When this fails, the call to setup should panic, but seems to actually hang (i.e. neither return nor panic) for some reason. diff --git a/storage-proofs/post/src/election/circuit.rs b/storage-proofs/post/src/election/circuit.rs index 19b4a741b..ff547dfb2 100644 --- a/storage-proofs/post/src/election/circuit.rs +++ b/storage-proofs/post/src/election/circuit.rs @@ -297,7 +297,7 @@ mod tests { comm_r: Some(comm_r.into()), comm_c: Some(comm_c.into()), comm_r_last: Some(comm_r_last.into()), - partial_ticket: Some(candidate.partial_ticket.into()), + partial_ticket: Some(candidate.partial_ticket), randomness: Some(randomness.into()), prover_id: Some(prover_id.into()), sector_id: Some(candidate.sector_id.into()),