Skip to content

Commit 2df110d

Browse files
authored
fix(rust): Fixing Rust clippy issues (#570)
* fix clippy * fix fmt
1 parent b1136bb commit 2df110d

File tree

8 files changed

+21
-24
lines changed

8 files changed

+21
-24
lines changed

rust/c509-certificate/examples/cli/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn time_to_string(time: u64) -> anyhow::Result<String> {
364364
// Attempt to convert the timestamp and handle errors if they occur
365365
let timestamp: i64 = time
366366
.try_into()
367-
.map_err(|e| anyhow::anyhow!("Failed to convert time: {:?}", e))?;
367+
.map_err(|e| anyhow::anyhow!("Failed to convert time: {e:?}"))?;
368368

369369
// Convert the timestamp to a DateTime and handle any potential errors
370370
let datetime = DateTime::from_timestamp(timestamp, 0)

rust/cardano-blockchain-types/src/auxdata/scripts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl TryFrom<u64> for ScriptType {
100100

101101
fn try_from(value: u64) -> Result<Self, Self::Error> {
102102
match value {
103-
0 => Err(anyhow!("Invalid script type: {}", value)),
103+
0 => Err(anyhow!("Invalid script type: {value}")),
104104
1 => Ok(Self::Native),
105105
_ => Ok(Self::Plutus(value.saturating_sub(1))),
106106
}

rust/cardano-chain-follower/src/mithril_snapshot_config.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,18 @@ impl MithrilSnapshotConfig {
239239

240240
let Ok(relative_file) = tmp_file.strip_prefix(&tmp_path) else {
241241
error!("Failed to get relative path of file.");
242-
bail!("Failed to strip prefix: {tmp_path:?}");
242+
bail!("Failed to strip prefix: {}", tmp_path.to_string_lossy());
243243
};
244244

245245
// IF we make it here, the files are identical, so we can de-dup them safely.
246246
// Remove the tmp file momentarily.
247247
if tmp_file.exists() {
248248
if let Err(error) = std::fs::remove_file(tmp_file) {
249249
error!(
250-
"Error removing tmp file {} : {}",
250+
"Error removing tmp file {} : {error}",
251251
tmp_file.to_string_lossy(),
252-
error
253252
);
254-
bail!("Failed to remove tmp file: {tmp_file:?}");
253+
bail!("Failed to remove tmp file: {}", tmp_file.to_string_lossy());
255254
}
256255
}
257256

@@ -260,21 +259,23 @@ impl MithrilSnapshotConfig {
260259
// Hardlink the src file to the tmp file.
261260
if let Some(parent) = tmp_file.parent() {
262261
if let Err(error) = std::fs::create_dir_all(parent) {
263-
error!("Error creating parent dir {parent:?} for tmp file {tmp_file:?}: {error}");
262+
error!(
263+
"Error creating parent dir {parent:?} for tmp file {}: {error}",
264+
tmp_file.to_string_lossy()
265+
);
264266
}
265267
}
266268
if let Err(error) = std::fs::hard_link(src_file, tmp_file) {
267269
error!(
268-
"Error linking src file {} to tmp file {} : {}",
270+
"Error linking src file {} to tmp file {} : {error}",
269271
src_file.to_string_lossy(),
270272
tmp_file.to_string_lossy(),
271-
error
272273
);
273-
bail!("Failed to link src file: {src_file:?}");
274+
bail!("Failed to link src file: {}", src_file.to_string_lossy());
274275
}
275276

276277
// And if we made it here, file was successfully de-duped. YAY.
277-
debug!("DeDup OK: {tmp_file:?}");
278+
debug!("DeDup OK: {tmp_file:?}",);
278279
Ok(())
279280
}
280281

rust/cardano-chain-follower/src/mithril_turbo_downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl FileDownloader for MithrilTurboDownloader {
397397

398398
// We only support full downloads for now.
399399
if !matches!(download_event_type, DownloadEvent::Full { .. }) {
400-
bail!("Unsupported Download Event Type: {:?}", download_event_type);
400+
bail!("Unsupported Download Event Type: {download_event_type:?}");
401401
}
402402

403403
let location = location.as_str();

rust/cardano-chain-follower/src/turbo_downloader/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,7 @@ impl ParallelDownloadProcessor {
417417
chain: Network,
418418
) -> Result<Self> {
419419
if cfg.chunk_size < MIN_CHUNK_SIZE {
420-
bail!(
421-
"Download chunk size must be at least {} bytes",
422-
MIN_CHUNK_SIZE
423-
);
420+
bail!("Download chunk size must be at least {MIN_CHUNK_SIZE} bytes");
424421
}
425422
let file_size = get_content_length_async(url).await?;
426423

@@ -595,7 +592,7 @@ impl ParallelDownloadProcessor {
595592
let queue = worker_queue.value();
596593
queue.send(order)?;
597594
} else {
598-
bail!("Expected a work queue for worker: {:?}", this_worker);
595+
bail!("Expected a work queue for worker: {this_worker:?}");
599596
}
600597
} else {
601598
// No more work, so remove the work queue from the map.
@@ -779,7 +776,7 @@ async fn get_content_length_async(url: &str) -> Result<usize> {
779776
Ok(result) => result,
780777
Err(error) => {
781778
error!("get_content_length failed");
782-
Err(anyhow::anyhow!("get_content_length failed: {}", error))
779+
Err(anyhow::anyhow!("get_content_length failed: {error}"))
783780
},
784781
}
785782
}
@@ -799,8 +796,7 @@ fn get_content_length(url: &str) -> Result<usize> {
799796
if let Some(accept_ranges) = response.header(ACCEPT_RANGES.as_str()) {
800797
if accept_ranges != "bytes" {
801798
bail!(
802-
"Server doesn't support HTTP range byte requests (Accept-Ranges = {})",
803-
accept_ranges
799+
"Server doesn't support HTTP range byte requests (Accept-Ranges = {accept_ranges})",
804800
);
805801
}
806802
} else {

rust/immutable-ledger/src/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl BlockHeader {
437437
let prev_block_hash_type = match hash_function.as_u64() {
438438
BLAKE3_CBOR_TAG => HashFunction::Blake3,
439439
BLAKE_2B_CBOR_TAG => HashFunction::Blake2b,
440-
_ => bail!(format!("Invalid hash function type {:?}", hash_function)),
440+
_ => bail!(format!("Invalid hash function type {hash_function:?}")),
441441
};
442442

443443
let prev_block_hash = cbor_decoder

rust/signed_doc/src/metadata/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Metadata {
190190
let fields = serde::Deserializer::deserialize_map(fields, MetadataDeserializeVisitor)?;
191191
let report = ProblemReport::new("Deserializing metadata from json");
192192
let metadata = Self::from_fields(fields.into_iter().map(anyhow::Result::<_>::Ok), &report)?;
193-
anyhow::ensure!(!report.is_problematic(), "{:?}", report);
193+
anyhow::ensure!(!report.is_problematic(), "{report:?}");
194194
Ok(metadata)
195195
}
196196

rust/signed_doc/src/validator/rules/content_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl ContentTypeRule {
106106
ContentType::Json => {
107107
if let Err(e) = serde_json::from_slice::<&serde_json::value::RawValue>(content)
108108
{
109-
anyhow::bail!("Invalid {} content: {e}", exp)
109+
anyhow::bail!("Invalid {exp} content: {e}")
110110
}
111111
},
112112
ContentType::Cbor => {
@@ -129,7 +129,7 @@ impl ContentTypeRule {
129129
| ContentType::Plain
130130
| ContentType::PlainHandlebars => {
131131
// TODO: not implemented yet
132-
anyhow::bail!("`{}` is valid but unavailable yet", exp)
132+
anyhow::bail!("`{exp}` is valid but unavailable yet")
133133
},
134134
}
135135
}

0 commit comments

Comments
 (0)