Skip to content

Commit 6e53c05

Browse files
committed
fix: additional clippy updates
1 parent e266b9c commit 6e53c05

File tree

17 files changed

+36
-22
lines changed

17 files changed

+36
-22
lines changed

build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
println!("cargo::rustc-check-cfg=cfg(nightly)");
2+
13
fn is_compiled_for_64_bit_arch() -> bool {
24
cfg!(target_pointer_width = "64")
35
}

fil-proofs-param/src/bin/paramfetch.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ struct FetchProgress<R> {
5151

5252
impl<R: Read> Read for FetchProgress<R> {
5353
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
54-
self.reader.read(buf).map(|n| {
55-
self.progress_bar.add(n as u64);
56-
n
54+
self.reader.read(buf).inspect(|n| {
55+
self.progress_bar.add(*n as u64);
5756
})
5857
}
5958
}

fil-proofs-tooling/src/bin/benchy/porep.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
9494
OpenOptions::new().read(true).write(true).open(&staged_file_path)
9595
} else {
9696
info!("*** Creating staged file");
97-
OpenOptions::new().read(true).write(true).create(true).open(&staged_file_path)
97+
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&staged_file_path)
9898
}?;
9999

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

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

122122
info!("*** Created piece file");
123-
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).open(&piece_file_path)?;
123+
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&piece_file_path)?;
124124
piece_file.write_all(&piece_bytes)?;
125125
piece_file.sync_all()?;
126126
piece_file.rewind()?;

fil-proofs-tooling/src/bin/benchy/window_post.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
101101
OpenOptions::new().read(true).write(true).open(&staged_file_path)
102102
} else {
103103
info!("*** Creating staged file");
104-
OpenOptions::new().read(true).write(true).create(true).open(&staged_file_path)
104+
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&staged_file_path)
105105
}?;
106106

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

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

130130
info!("*** Created piece file");
131-
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).open(&piece_file_path)?;
131+
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&piece_file_path)?;
132132
piece_file.write_all(&piece_bytes)?;
133133
piece_file.sync_all()?;
134134
piece_file.rewind()?;

fil-proofs-tooling/src/bin/benchy/winning_post.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
6363
create_replica::<Tree>(sector_size, fake_replica, api_version, api_features);
6464

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

6969
let post_config = PoStConfig {
7070
sector_size: sector_size.into(),

fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn thread_fun(
104104
) -> RunInfo {
105105
let timing = Instant::now();
106106
let mut iteration = 0;
107-
while iteration < std::u8::MAX {
107+
while iteration < u8::MAX {
108108
info!("iter {}", iteration);
109109

110110
// This is the higher priority proof, get it on the GPU even if there is one running

filecoin-proofs/src/api/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ where
367367
/// # Arguments
368368
///
369369
/// * `source` - a readable source of unprocessed piece bytes. The piece's commitment will be
370-
/// generated for the bytes read from the source plus any added padding.
370+
/// generated for the bytes read from the source plus any added padding.
371371
/// * `piece_size` - the number of unpadded user-bytes which can be read from source before EOF.
372372
pub fn generate_piece_commitment<T: Read>(
373373
source: T,

filecoin-proofs/tests/api.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1454,15 +1454,15 @@ fn winning_post<Tree: 'static + MerkleTreeTrait>(
14541454
assert_eq!(challenged_sectors.len(), sector_count);
14551455
assert_eq!(challenged_sectors[0], 0); // with a sector_count of 1, the only valid index is 0
14561456

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

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

14681468
let valid =
@@ -2629,6 +2629,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
26292629
.read(true)
26302630
.write(true)
26312631
.create(true)
2632+
.truncate(true)
26322633
.open(new_sealed_sector_file.path())
26332634
.with_context(|| format!("could not open path={:?}", new_sealed_sector_file.path()))?;
26342635
f_sealed_sector.set_len(new_replica_target_len)?;
@@ -2734,6 +2735,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
27342735
.read(true)
27352736
.write(true)
27362737
.create(true)
2738+
.truncate(true)
27372739
.open(decoded_sector_file.path())
27382740
.with_context(|| format!("could not open path={:?}", decoded_sector_file.path()))?;
27392741
f_decoded_sector.set_len(decoded_sector_target_len)?;
@@ -2780,6 +2782,7 @@ fn create_seal_for_upgrade<R: Rng, Tree: 'static + MerkleTreeTrait<Hasher = Tree
27802782
.read(true)
27812783
.write(true)
27822784
.create(true)
2785+
.truncate(true)
27832786
.open(remove_encoded_file.path())
27842787
.with_context(|| format!("could not open path={:?}", remove_encoded_file.path()))?;
27852788
f_remove_encoded.set_len(remove_encoded_target_len)?;
@@ -2895,6 +2898,7 @@ fn create_seal_for_upgrade_aggregation<
28952898
.read(true)
28962899
.write(true)
28972900
.create(true)
2901+
.truncate(true)
28982902
.open(new_sealed_sector_file.path())
28992903
.with_context(|| format!("could not open path={:?}", new_sealed_sector_file.path()))?;
29002904
f_sealed_sector.set_len(new_replica_target_len)?;

fr32/src/convert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum Error {
1212
/// Invariants:
1313
/// - Value of each 32-byte chunks MUST represent valid Frs.
1414
/// - Total length must be a multiple of 32.
15-
/// That is to say: each 32-byte chunk taken alone must be a valid Fr32.
15+
/// That is to say: each 32-byte chunk taken alone must be a valid Fr32.
1616
pub type Fr32Vec = Vec<u8>;
1717

1818
/// Array whose little-endian value represents an Fr.

fr32/src/padding.rs

+2
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ need to handle the potential bit-level misalignments:
563563
// offset and num_bytes are based on the unpadded data, so
564564
// if [0, 1, ..., 255] was the original unpadded data, offset 3 and len 4 would return
565565
// [3, 4, 5, 6].
566+
#[allow(clippy::multiple_bound_locations)]
566567
pub fn write_unpadded<W: ?Sized>(
567568
source: &[u8],
568569
target: &mut W,
@@ -630,6 +631,7 @@ The reader will generally operate with bit precision, even if the padded
630631
layout is byte-aligned (no extra bits) the data inside it isn't (since
631632
we pad at the bit-level).
632633
**/
634+
#[allow(clippy::multiple_bound_locations)]
633635
fn write_unpadded_aux<W: ?Sized>(
634636
padding_map: &PaddingMap,
635637
source: &[u8],

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.75.0
1+
1.81.0

storage-proofs-core/src/gadgets/insertion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ pub fn select<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(
316316
}
317317

318318
/// Takes two allocated numbers (`a`, `b`) and returns `a` if the condition is true, and `b` otherwise.
319+
#[allow(clippy::multiple_bound_locations)]
319320
pub fn pick<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(
320321
mut cs: CS,
321322
condition: &Boolean,

storage-proofs-core/src/parameter_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ where
249249
let param_identifier = pub_params.identifier();
250250
info!("parameter set identifier for cache: {}", param_identifier);
251251
let mut hasher = Sha256::default();
252-
hasher.update(&param_identifier.into_bytes());
252+
hasher.update(param_identifier.into_bytes());
253253
let circuit_hash = hasher.finalize();
254254
format!(
255255
"{}-{:02x}",

storage-proofs-core/src/test_helper.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub fn setup_replica(data: &[u8], replica_path: &Path) -> MmapMut {
99
.read(true)
1010
.write(true)
1111
.create(true)
12+
.truncate(true)
1213
.open(replica_path)
1314
.expect("Failed to create replica");
1415
f.write_all(data).expect("Failed to write data to replica");

storage-proofs-porep/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ multicore-sdr = ["hwloc"]
8484
# This feature enables a fixed number of discarded rows for TreeR. The `FIL_PROOFS_ROWS_TO_DISCARD`
8585
# setting is ignored, no `TemporaryAux` file will be written.
8686
fixed-rows-to-discard = ["storage-proofs-core/fixed-rows-to-discard"]
87+
cpu-profile = []
8788

8889
[[bench]]
8990
name = "encode"

storage-proofs-porep/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ fn cfg_if_nightly() {
88
}
99

1010
#[rustversion::not(nightly)]
11-
fn cfg_if_nightly() {}
11+
fn cfg_if_nightly() {
12+
println!("cargo::rustc-check-cfg=cfg(nightly)");
13+
}

storage-proofs-porep/src/stacked/vanilla/proof.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
192192
t_aux.synth_proofs_path(),
193193
partition_count,
194194
)
195-
.map_err(|error| {
195+
.inspect_err(|error| {
196196
info!(
197-
"failed to read porep proofs from synthetic proofs file: {:?}",
197+
"failed to read porep proofs from synthetic proofs file: {:?} [{}]",
198198
t_aux.synth_proofs_path(),
199+
error,
199200
);
200-
error
201201
})
202202
}
203203
}
@@ -1503,6 +1503,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
15031503
);
15041504
let mut f = OpenOptions::new()
15051505
.create(true)
1506+
.truncate(true)
15061507
.write(true)
15071508
.open(&tree_r_last_path)
15081509
.expect("failed to open file for tree_r_last");
@@ -1915,6 +1916,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
19151916
);
19161917
let mut f = OpenOptions::new()
19171918
.create(true)
1919+
.truncate(true)
19181920
.write(true)
19191921
.open(&tree_r_last_path)
19201922
.expect("failed to open file for tree_r_last");

0 commit comments

Comments
 (0)