Skip to content

Commit

Permalink
fix: additional clippy updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptonemo committed Jan 6, 2025
1 parent e266b9c commit 6e53c05
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 22 deletions.
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
println!("cargo::rustc-check-cfg=cfg(nightly)");

fn is_compiled_for_64_bit_arch() -> bool {
cfg!(target_pointer_width = "64")
}
Expand Down
5 changes: 2 additions & 3 deletions fil-proofs-param/src/bin/paramfetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ struct FetchProgress<R> {

impl<R: Read> Read for FetchProgress<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.reader.read(buf).map(|n| {
self.progress_bar.add(n as u64);
n
self.reader.read(buf).inspect(|n| {
self.progress_bar.add(*n as u64);
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions fil-proofs-tooling/src/bin/benchy/porep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
OpenOptions::new().read(true).write(true).open(&staged_file_path)
} else {
info!("*** Creating staged file");
OpenOptions::new().read(true).write(true).create(true).open(&staged_file_path)
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&staged_file_path)
}?;

let sealed_file_path = cache_dir.join(SEALED_FILE);
Expand All @@ -103,7 +103,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
OpenOptions::new().read(true).write(true).open(&sealed_file_path)
} else {
info!("*** Creating sealed file");
OpenOptions::new().read(true).write(true).create(true).open(&sealed_file_path)
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&sealed_file_path)
}?;

let sector_size_unpadded_bytes_amount =
Expand All @@ -120,7 +120,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
.collect();

info!("*** Created piece file");
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).open(&piece_file_path)?;
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&piece_file_path)?;
piece_file.write_all(&piece_bytes)?;
piece_file.sync_all()?;
piece_file.rewind()?;
Expand Down
6 changes: 3 additions & 3 deletions fil-proofs-tooling/src/bin/benchy/window_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
OpenOptions::new().read(true).write(true).open(&staged_file_path)
} else {
info!("*** Creating staged file");
OpenOptions::new().read(true).write(true).create(true).open(&staged_file_path)
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&staged_file_path)
}?;

let sealed_file_path = cache_dir.join(SEALED_FILE);
Expand All @@ -110,7 +110,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
OpenOptions::new().read(true).write(true).open(&sealed_file_path)
} else {
info!("*** Creating sealed file");
OpenOptions::new().read(true).write(true).create(true).open(&sealed_file_path)
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&sealed_file_path)
}?;

let sector_size_unpadded_bytes_amount =
Expand All @@ -128,7 +128,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
.collect();

info!("*** Created piece file");
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).open(&piece_file_path)?;
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&piece_file_path)?;
piece_file.write_all(&piece_bytes)?;
piece_file.sync_all()?;
piece_file.rewind()?;
Expand Down
4 changes: 2 additions & 2 deletions fil-proofs-tooling/src/bin/benchy/winning_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
create_replica::<Tree>(sector_size, fake_replica, api_version, api_features);

// Store the replica's private and publicly facing info for proving and verifying respectively.
let pub_replica_info = vec![(sector_id, replica_output.public_replica_info.clone())];
let priv_replica_info = vec![(sector_id, replica_output.private_replica_info.clone())];
let pub_replica_info = [(sector_id, replica_output.public_replica_info.clone())];
let priv_replica_info = [(sector_id, replica_output.private_replica_info.clone())];

let post_config = PoStConfig {
sector_size: sector_size.into(),
Expand Down
2 changes: 1 addition & 1 deletion fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn thread_fun(
) -> RunInfo {
let timing = Instant::now();
let mut iteration = 0;
while iteration < std::u8::MAX {
while iteration < u8::MAX {
info!("iter {}", iteration);

// This is the higher priority proof, get it on the GPU even if there is one running
Expand Down
2 changes: 1 addition & 1 deletion filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ where
/// # Arguments
///
/// * `source` - a readable source of unprocessed piece bytes. The piece's commitment will be
/// generated for the bytes read from the source plus any added padding.
/// generated for the bytes read from the source plus any added padding.
/// * `piece_size` - the number of unpadded user-bytes which can be read from source before EOF.
pub fn generate_piece_commitment<T: Read>(
source: T,
Expand Down
8 changes: 6 additions & 2 deletions filecoin-proofs/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,15 +1454,15 @@ fn winning_post<Tree: 'static + MerkleTreeTrait>(
assert_eq!(challenged_sectors.len(), sector_count);
assert_eq!(challenged_sectors[0], 0); // with a sector_count of 1, the only valid index is 0

let pub_replicas = vec![(sector_id, PublicReplicaInfo::new(comm_r)?)];
let pub_replicas = [(sector_id, PublicReplicaInfo::new(comm_r)?)];
let private_replica_info =
PrivateReplicaInfo::new(replica.path().into(), comm_r, cache_dir.path().into())?;

/////////////////////////////////////////////
// The following methods of proof generation are functionally equivalent:
// 1)
//
let priv_replicas = vec![(sector_id, private_replica_info.clone())];
let priv_replicas = [(sector_id, private_replica_info.clone())];
let proof = generate_winning_post::<Tree>(&config, &randomness, &priv_replicas[..], prover_id)?;

let valid =
Expand Down Expand Up @@ -2629,6 +2629,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(new_sealed_sector_file.path())
.with_context(|| format!("could not open path={:?}", new_sealed_sector_file.path()))?;
f_sealed_sector.set_len(new_replica_target_len)?;
Expand Down Expand Up @@ -2734,6 +2735,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(decoded_sector_file.path())
.with_context(|| format!("could not open path={:?}", decoded_sector_file.path()))?;
f_decoded_sector.set_len(decoded_sector_target_len)?;
Expand Down Expand Up @@ -2780,6 +2782,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(remove_encoded_file.path())
.with_context(|| format!("could not open path={:?}", remove_encoded_file.path()))?;
f_remove_encoded.set_len(remove_encoded_target_len)?;
Expand Down Expand Up @@ -2895,6 +2898,7 @@ fn create_seal_for_upgrade_aggregation<
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(new_sealed_sector_file.path())
.with_context(|| format!("could not open path={:?}", new_sealed_sector_file.path()))?;
f_sealed_sector.set_len(new_replica_target_len)?;
Expand Down
2 changes: 1 addition & 1 deletion fr32/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Error {
/// Invariants:
/// - Value of each 32-byte chunks MUST represent valid Frs.
/// - Total length must be a multiple of 32.
/// That is to say: each 32-byte chunk taken alone must be a valid Fr32.
/// That is to say: each 32-byte chunk taken alone must be a valid Fr32.
pub type Fr32Vec = Vec<u8>;

/// Array whose little-endian value represents an Fr.
Expand Down
2 changes: 2 additions & 0 deletions fr32/src/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ need to handle the potential bit-level misalignments:
// offset and num_bytes are based on the unpadded data, so
// if [0, 1, ..., 255] was the original unpadded data, offset 3 and len 4 would return
// [3, 4, 5, 6].
#[allow(clippy::multiple_bound_locations)]
pub fn write_unpadded<W: ?Sized>(
source: &[u8],
target: &mut W,
Expand Down Expand Up @@ -630,6 +631,7 @@ The reader will generally operate with bit precision, even if the padded
layout is byte-aligned (no extra bits) the data inside it isn't (since
we pad at the bit-level).
**/
#[allow(clippy::multiple_bound_locations)]
fn write_unpadded_aux<W: ?Sized>(
padding_map: &PaddingMap,
source: &[u8],
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.75.0
1.81.0
1 change: 1 addition & 0 deletions storage-proofs-core/src/gadgets/insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub fn select<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(
}

/// Takes two allocated numbers (`a`, `b`) and returns `a` if the condition is true, and `b` otherwise.
#[allow(clippy::multiple_bound_locations)]
pub fn pick<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(
mut cs: CS,
condition: &Boolean,
Expand Down
2 changes: 1 addition & 1 deletion storage-proofs-core/src/parameter_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ where
let param_identifier = pub_params.identifier();
info!("parameter set identifier for cache: {}", param_identifier);
let mut hasher = Sha256::default();
hasher.update(&param_identifier.into_bytes());
hasher.update(param_identifier.into_bytes());
let circuit_hash = hasher.finalize();
format!(
"{}-{:02x}",
Expand Down
1 change: 1 addition & 0 deletions storage-proofs-core/src/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn setup_replica(data: &[u8], replica_path: &Path) -> MmapMut {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(replica_path)
.expect("Failed to create replica");
f.write_all(data).expect("Failed to write data to replica");
Expand Down
1 change: 1 addition & 0 deletions storage-proofs-porep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ multicore-sdr = ["hwloc"]
# This feature enables a fixed number of discarded rows for TreeR. The `FIL_PROOFS_ROWS_TO_DISCARD`
# setting is ignored, no `TemporaryAux` file will be written.
fixed-rows-to-discard = ["storage-proofs-core/fixed-rows-to-discard"]
cpu-profile = []

[[bench]]
name = "encode"
Expand Down
4 changes: 3 additions & 1 deletion storage-proofs-porep/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ fn cfg_if_nightly() {
}

#[rustversion::not(nightly)]
fn cfg_if_nightly() {}
fn cfg_if_nightly() {
println!("cargo::rustc-check-cfg=cfg(nightly)");
}
8 changes: 5 additions & 3 deletions storage-proofs-porep/src/stacked/vanilla/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
t_aux.synth_proofs_path(),
partition_count,
)
.map_err(|error| {
.inspect_err(|error| {
info!(
"failed to read porep proofs from synthetic proofs file: {:?}",
"failed to read porep proofs from synthetic proofs file: {:?} [{}]",
t_aux.synth_proofs_path(),
error,
);
error
})
}
}
Expand Down Expand Up @@ -1503,6 +1503,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
);
let mut f = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&tree_r_last_path)
.expect("failed to open file for tree_r_last");
Expand Down Expand Up @@ -1915,6 +1916,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
);
let mut f = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&tree_r_last_path)
.expect("failed to open file for tree_r_last");
Expand Down

0 comments on commit 6e53c05

Please sign in to comment.