Skip to content

Commit 215161c

Browse files
committed
Fixed 'mithril-common' clippy warnings from Rust 1.67.0
1 parent ce3488f commit 215161c

File tree

20 files changed

+66
-93
lines changed

20 files changed

+66
-93
lines changed

mithril-common/benches/digester.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ fn db_dir() -> PathBuf {
2727

2828
fn create_db(dir: &Path, number_of_immutables: ImmutableFileNumber, file_size: u64) {
2929
if dir.exists() {
30-
fs::remove_dir_all(dir).unwrap_or_else(|e| panic!("Could not remove dir {:?}: {}", dir, e));
30+
fs::remove_dir_all(dir).unwrap_or_else(|e| panic!("Could not remove dir {dir:?}: {e}"));
3131
}
32-
fs::create_dir_all(dir).unwrap_or_else(|e| panic!("Could not create dir {:?}: {}", dir, e));
32+
fs::create_dir_all(dir).unwrap_or_else(|e| panic!("Could not create dir {dir:?}: {e}"));
3333

3434
// + 1 to simulate "in-progress" immutable trio.
3535
for filename in (1..=(number_of_immutables + 1)).flat_map(|i| {
3636
[
37-
format!("{:05}.chunk", i),
38-
format!("{:05}.primary", i),
39-
format!("{:05}.secondary", i),
37+
format!("{i:05}.chunk"),
38+
format!("{i:05}.primary"),
39+
format!("{i:05}.secondary"),
4040
]
4141
}) {
4242
let file = dir.join(Path::new(&filename));
4343
let mut source_file = File::create(file).unwrap();
4444

45-
write!(source_file, "This is a test file named '{}'", filename).unwrap();
45+
write!(source_file, "This is a test file named '{filename}'").unwrap();
4646
writeln!(source_file).unwrap();
4747
source_file.set_len(file_size).unwrap();
4848
}

mithril-common/src/certificate_chain/certificate_verifier.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ mod tests {
422422
verify,
423423
Err(CertificateVerifierError::CertificateChainPreviousHashUnmatch)
424424
),
425-
"unexpected error type: {:?}",
426-
verify
425+
"unexpected error type: {verify:?}"
427426
);
428427
}
429428

@@ -460,8 +459,7 @@ mod tests {
460459
verify,
461460
Err(CertificateVerifierError::CertificateChainAVKUnmatch)
462461
),
463-
"unexpected error type: {:?}",
464-
verify
462+
"unexpected error type: {verify:?}"
465463
);
466464
}
467465

@@ -487,8 +485,7 @@ mod tests {
487485
verify,
488486
Err(CertificateVerifierError::CertificateHashUnmatch)
489487
),
490-
"unexpected error type: {:?}",
491-
verify
488+
"unexpected error type: {verify:?}"
492489
);
493490
}
494491

@@ -550,8 +547,7 @@ mod tests {
550547
verify,
551548
Err(CertificateVerifierError::CertificateChainPreviousHashUnmatch)
552549
),
553-
"unexpected error type: {:?}",
554-
verify
550+
"unexpected error type: {verify:?}"
555551
);
556552
}
557553
}

mithril-common/src/chain_observer/cli_observer.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,30 +217,19 @@ impl CardanoCliChainObserver {
217217
let stake_pool_snapshot: Value = serde_json::from_str(&stake_pool_snapshot_output)
218218
.map_err(|e| {
219219
ChainObserverError::InvalidContent(
220-
format!(
221-
"Error: {:?}, output was = '{}'",
222-
e, stake_pool_snapshot_output
223-
)
224-
.into(),
220+
format!("Error: {e:?}, output was = '{stake_pool_snapshot_output}'").into(),
225221
)
226222
})?;
227223
if let Value::Number(stake_pool_stake) = &stake_pool_snapshot["poolStakeMark"] {
228224
return stake_pool_stake.as_u64().ok_or_else(|| {
229225
ChainObserverError::InvalidContent(
230-
format!(
231-
"Error: could not parse stake pool value as u64 {:?}",
232-
stake_pool_stake
233-
)
234-
.into(),
226+
format!("Error: could not parse stake pool value as u64 {stake_pool_stake:?}")
227+
.into(),
235228
)
236229
});
237230
}
238231
Err(ChainObserverError::InvalidContent(
239-
format!(
240-
"Error: could not parse stake pool snapshot {:?}",
241-
stake_pool_snapshot
242-
)
243-
.into(),
232+
format!("Error: could not parse stake pool snapshot {stake_pool_snapshot:?}").into(),
244233
))
245234
}
246235
}
@@ -255,7 +244,7 @@ impl ChainObserver for CardanoCliChainObserver {
255244
.map_err(ChainObserverError::General)?;
256245
let v: Value = serde_json::from_str(&output).map_err(|e| {
257246
ChainObserverError::InvalidContent(
258-
format!("Error: {:?}, output was = '{}'", e, output).into(),
247+
format!("Error: {e:?}, output was = '{output}'").into(),
259248
)
260249
})?;
261250

@@ -325,7 +314,7 @@ impl ChainObserver for CardanoCliChainObserver {
325314
let output_cleaned = output.split_at(first_left_curly_bracket_index).1;
326315
let v: Value = serde_json::from_str(output_cleaned).map_err(|e| {
327316
ChainObserverError::InvalidContent(
328-
format!("Error: {:?}, output was = '{}'", e, output).into(),
317+
format!("Error: {e:?}, output was = '{output}'").into(),
329318
)
330319
})?;
331320

mithril-common/src/crypto_helper/cardano/codec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub trait SerDeShelleyFileFormat: Serialize + DeserializeOwned {
8080
let mut file = fs::File::create(path)?;
8181
let json_str = serde_json::to_string(&file_format)?;
8282

83-
write!(file, "{}", json_str)?;
83+
write!(file, "{json_str}")?;
8484
Ok(())
8585
}
8686
}
@@ -132,7 +132,7 @@ mod test {
132132
let json_str =
133133
serde_json::to_string(&file_format).expect("Unexpected error with serialisation.");
134134

135-
write!(file, "{}", json_str).expect("Unexpected error writing to file.");
135+
write!(file, "{json_str}").expect("Unexpected error writing to file.");
136136

137137
let kes_sk = Sum6Kes::from_file(&sk_dir);
138138

mithril-common/src/crypto_helper/cardano/key_certification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ mod test {
303303
let keypair = ColdKeyGenerator::create_deterministic_keypair([party_idx as u8; 32]);
304304
let (kes_secret_key, kes_verification_key) = Sum6Kes::keygen(&mut [party_idx as u8; 32]);
305305
let operational_certificate = OpCert::new(kes_verification_key, 0, 0, keypair);
306-
let kes_secret_key_file = temp_dir.join(format!("kes{}.skey", party_idx));
306+
let kes_secret_key_file = temp_dir.join(format!("kes{party_idx}.skey"));
307307
kes_secret_key
308308
.to_file(&kes_secret_key_file)
309309
.expect("KES secret key file export should not fail");
310-
let operational_certificate_file = temp_dir.join(format!("pool{}.cert", party_idx));
310+
let operational_certificate_file = temp_dir.join(format!("pool{party_idx}.cert"));
311311
operational_certificate
312312
.to_file(&operational_certificate_file)
313313
.expect("operational certificate file export should not fail");

mithril-common/src/crypto_helper/codec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ where
1010
T: Serialize,
1111
{
1212
Ok(serde_json::to_string(&from)
13-
.map_err(|e| format!("can't convert to hex: {}", e))?
13+
.map_err(|e| format!("can't convert to hex: {e}"))?
1414
.encode_hex::<String>())
1515
}
1616

@@ -19,8 +19,8 @@ pub fn key_decode_hex<T>(from: &HexEncodedKey) -> Result<T, String>
1919
where
2020
T: DeserializeOwned,
2121
{
22-
let from_vec = Vec::from_hex(from).map_err(|e| format!("can't parse from hex: {}", e))?;
23-
serde_json::from_slice(from_vec.as_slice()).map_err(|e| format!("can't deserialize: {}", e))
22+
let from_vec = Vec::from_hex(from).map_err(|e| format!("can't parse from hex: {e}"))?;
23+
serde_json::from_slice(from_vec.as_slice()).map_err(|e| format!("can't deserialize: {e}"))
2424
}
2525

2626
#[cfg(test)]

mithril-common/src/crypto_helper/tests_setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ pub fn setup_certificate_chain(
199199
.enumerate()
200200
.map(|(i, epoch)| {
201201
let immutable_file_number = i as u64 * 10;
202-
let digest = format!("digest{}", i);
203-
let certificate_hash = format!("certificate_hash-{}", i);
202+
let digest = format!("digest{i}");
203+
let certificate_hash = format!("certificate_hash-{i}");
204204
let fixture = fixture_per_epoch.get(&epoch).unwrap();
205205
let next_fixture = fixture_per_epoch.get(&(epoch + 1)).unwrap();
206206
let avk = avk_for_signers(&fixture.signers_fixture());

mithril-common/src/database/db_version.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl ApplicationNodeType {
2828
match node_type {
2929
"aggregator" => Ok(Self::Aggregator),
3030
"signer" => Ok(Self::Signer),
31-
_ => Err(format!("unknown node type '{}'", node_type).into()),
31+
_ => Err(format!("unknown node type '{node_type}'").into()),
3232
}
3333
}
3434
}
@@ -61,12 +61,12 @@ impl SqLiteEntity for DatabaseVersion {
6161
Ok(Self {
6262
version: row.get::<i64, _>(0),
6363
application_type: ApplicationNodeType::new(&row.get::<String, _>(1))
64-
.map_err(|e| HydrationError::InvalidData(format!("{}", e)))?,
64+
.map_err(|e| HydrationError::InvalidData(format!("{e}")))?,
6565
updated_at: NaiveDateTime::parse_from_str(
6666
&row.get::<String, _>(2),
6767
"%Y-%m-%d %H:%M:%S",
6868
)
69-
.map_err(|e| HydrationError::InvalidData(format!("{}", e)))?,
69+
.map_err(|e| HydrationError::InvalidData(format!("{e}")))?,
7070
})
7171
}
7272

@@ -143,7 +143,7 @@ insert into db_version (application_type, version) values ('{application_type}',
143143
application_type: &ApplicationNodeType,
144144
) -> Result<Option<DatabaseVersion>, Box<dyn Error>> {
145145
let condition = "application_type = ?";
146-
let params = [Value::String(format!("{}", application_type))];
146+
let params = [Value::String(format!("{application_type}"))];
147147
let result = self.find(Some(condition), &params)?.next();
148148

149149
Ok(result)

mithril-common/src/digesters/cache/json_provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ mod tests {
122122

123123
if parent_dir.exists() {
124124
fs::remove_dir_all(&parent_dir)
125-
.unwrap_or_else(|e| panic!("Could not remove dir {:?}: {}", parent_dir, e));
125+
.unwrap_or_else(|e| panic!("Could not remove dir {parent_dir:?}: {e}"));
126126
}
127127
fs::create_dir_all(&parent_dir)
128-
.unwrap_or_else(|e| panic!("Could not create dir {:?}: {}", parent_dir, e));
128+
.unwrap_or_else(|e| panic!("Could not create dir {parent_dir:?}: {e}"));
129129

130130
parent_dir
131131
}

mithril-common/src/digesters/cardano_immutable_digester.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ mod tests {
191191
}
192192

193193
fn db_builder(dir_name: &str) -> DummyImmutablesDbBuilder {
194-
DummyImmutablesDbBuilder::new(&format!("cardano_immutable_digester/{}", dir_name))
194+
DummyImmutablesDbBuilder::new(&format!("cardano_immutable_digester/{dir_name}"))
195195
}
196196

197197
#[test]
@@ -239,7 +239,7 @@ mod tests {
239239
found_number: None,
240240
}
241241
),
242-
format!("{:?}", result)
242+
format!("{result:?}")
243243
);
244244
}
245245

@@ -275,7 +275,7 @@ mod tests {
275275
found_number: None,
276276
}
277277
),
278-
format!("{:?}", result)
278+
format!("{result:?}")
279279
);
280280
}
281281

@@ -301,7 +301,7 @@ mod tests {
301301
found_number: Some(5),
302302
}
303303
),
304-
format!("{:?}", result)
304+
format!("{result:?}")
305305
);
306306
}
307307

@@ -441,9 +441,7 @@ mod tests {
441441
assert!(
442442
elapsed_with_cache < (elapsed_without_cache * 9 / 10),
443443
"digest computation with full cache should be faster than without cache,\
444-
time elapsed: with cache {:?}, without cache {:?}",
445-
elapsed_with_cache,
446-
elapsed_without_cache
444+
time elapsed: with cache {elapsed_with_cache:?}, without cache {elapsed_without_cache:?}"
447445
);
448446
}
449447

0 commit comments

Comments
 (0)