Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(storage-proofs): fix clippy warnings #1147

Merged
merged 33 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6861b07
style(storage-proofs): collapse else if block
Jun 3, 2020
68ec2f7
style(storage-proofs): remove unused import
Jun 3, 2020
339ed4e
refactor(storage-proofs): use iter() instead of into_iter()
Jun 3, 2020
6b00682
refactor(storage-proofs): use slice directly
Jun 3, 2020
8fc2a3e
refactor(storage-proofs): use iterator instead of for loop
Jun 3, 2020
a5ff82f
refactor(storage-proofs): remove unneeded mutable reference
Jun 3, 2020
71f094d
refactor(storage-proofs): remove unnecessary into()
Jun 3, 2020
5f5c4cd
refactor(storage-proofs): remove unnecessary clone()
Jun 3, 2020
b24a50a
refactor(storage-proofs): remove reference from match pattern
Jun 3, 2020
26f6675
refactor(storage-proofs): use dedicated `copied` method
Jun 3, 2020
8d1b060
refactor(storage-proofs): include function in criterion_group
Jun 4, 2020
1ca55ff
refactor(storage-proofs): remove unnecessary use
Jun 10, 2020
27a4174
refactor(storage-proofs): remove unnecessary ()
Jun 10, 2020
afadb20
refactor(storage-proofs): remove unused local variable
Jun 10, 2020
097349c
refactor(storage-proofs): use separators
Jun 15, 2020
747bbcc
refactor(storage-proofs): pass unit directly
Jun 15, 2020
ff23373
refactor(filecoin-proofs): use consistent underscoring
Jun 15, 2020
c43cf3c
refactor(filecoin-proofs): remove redundant import
Jun 15, 2020
5f80973
refactor(filecoin-proofs): remove unnecessary into_iter()
Jun 15, 2020
ea04524
refactor(filecoin-proofs): use iterator instead of indexing
Jun 15, 2020
6c2b6b3
refactor(filecoin-proofs): use _f64 type
Jun 15, 2020
0e3fc2e
refactor(filecoin-proofs): allow identity_op in test
Jun 15, 2020
108f8df
refactor(filecoin-proofs): remove useless use of vec!
Jun 15, 2020
255d681
refactor(filecoin-proofs): remove redundant clone
Jun 15, 2020
bd5c693
refactor(filecoin-proofs): remove clone on double reference
Jun 15, 2020
d30ab86
refactor(filecoin-proofs): use unwrap_or_else
Jun 15, 2020
f9d5822
refactor(filecoin-proofs): use iter() directly
Jun 15, 2020
3c2a891
refactor(filecoin-proofs): use write_all
Jun 15, 2020
61eed54
refactor(filecoin-proofs): remove identical conversion
Jun 15, 2020
6e198bb
refactor(filecoin-proofs): no function call after expect
Jun 15, 2020
7aba1d0
refactor(fil-proofs-tooling): add separators
Jun 15, 2020
ed71a56
refactor(fil-proofs-tooling): all clippy lint float_cmp
Jun 16, 2020
6aa355f
refactor(storage-proofs): all clippy lint unit_arg
Jun 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions fil-proofs-tooling/src/bin/micro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion filecoin-proofs/benches/preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion filecoin-proofs/src/fr32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions filecoin-proofs/src/fr32_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -499,7 +499,7 @@ mod tests {
let raw_data: BitVec<LittleEndian, u8> = 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
Expand All @@ -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
)
});
}
}

Expand All @@ -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.
Expand Down
16 changes: 7 additions & 9 deletions filecoin-proofs/src/pieces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,38 +483,36 @@ 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"),
"[a, b, c, d]"
);

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)
Expand Down Expand Up @@ -556,7 +554,7 @@ mod tests {
pad.clone(),
pad.clone(),
pad.clone(),
pad.clone(),
pad,
];

let hash = |a, b| {
Expand Down
9 changes: 4 additions & 5 deletions filecoin-proofs/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ fn create_seal<R: Rng, Tree: 'static + MerkleTreeTrait>(
) -> 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<u8> = (0..number_of_bytes_in_piece.0)
.map(|_| rand::random::<u8>())
Expand All @@ -359,7 +358,7 @@ fn create_seal<R: Rng, Tree: 'static + MerkleTreeTrait>(
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(&sector_size).unwrap(),
),
Expand Down Expand Up @@ -396,8 +395,8 @@ fn create_seal<R: Rng, Tree: 'static + MerkleTreeTrait>(
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())?;

Expand Down
2 changes: 1 addition & 1 deletion filecoin-proofs/tests/paramfetch/prompts_to_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand Down
5 changes: 2 additions & 3 deletions filecoin-proofs/tests/paramfetch/support/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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");
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions filecoin-proofs/tests/parampublish/read_metadata_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 7 additions & 10 deletions filecoin-proofs/tests/parampublish/support/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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");
Expand All @@ -49,21 +48,20 @@ impl ParamPublishSessionBuilder {

/// Create empty files with the given names in the cache directory.
pub fn with_files<P: AsRef<Path>>(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<P: AsRef<Path>>(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
Expand All @@ -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");
Expand Down Expand Up @@ -124,8 +122,7 @@ impl ParamPublishSessionBuilder {
let cache_dir_path = format!("{:?}", self.cache_dir.path());

let cache_contents: Vec<PathBuf> = 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn filename_to_checksum<P: AsRef<Path>>(
.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"),
Expand Down
12 changes: 4 additions & 8 deletions storage-proofs/core/benches/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<'a> Circuit<Bls12> for Blake2sExample<'a> {
fn synthesize<CS: ConstraintSystem<Bls12>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
let data: Vec<Boolean> = self
.data
.into_iter()
.iter()
.enumerate()
.map(|(i, b)| {
Ok(Boolean::from(boolean::AllocatedBit::alloc(
Expand Down Expand Up @@ -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::<Bls12, _, _>(
Blake2sExample {
data: &vec![None; 256],
},
&mut rng1,
)
.unwrap();
let groth_params =
generate_random_parameters::<Bls12, _, _>(Blake2sExample { data: &[None; 256] }, &mut rng1)
.unwrap();

let params = vec![32];

Expand Down
1 change: 1 addition & 0 deletions storage-proofs/core/benches/drgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion storage-proofs/core/benches/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Loading