Skip to content

Commit

Permalink
Fix several clippy warnings
Browse files Browse the repository at this point in the history
Fix several clippy warnings in crates such as:
- `beserial`
- `blockchain`
- `bls`
- `collections`
- `consensus`
- `database`
- `genesis-builder`
- `genesis`
- `handel`
- `lib`
- `light-blockchain`
- `log`
- `metrics-server`
- `nano-zkp`
- `network-mock`
- `block primitives`
- `mmr` primitives
- `primitives`
- `trie` primitives
- `rpc-client`
- `rpc-interface`
- `test-utils`
- `tools`

Most of the warnings fixed are related to the usage of variables in
the `format!` macro.
  • Loading branch information
jsdanielh committed Jan 27, 2023
1 parent 410a33e commit 9b79486
Show file tree
Hide file tree
Showing 42 changed files with 174 additions and 226 deletions.
22 changes: 10 additions & 12 deletions beserial/beserial_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ fn parse_field_attribs(attrs: &[syn::Attribute]) -> Option<FieldAttribute> {
&& !cmp_ident(value, "u16")
&& !cmp_ident(value, "u32")
{
panic!("beserial(len_type) must be one of [u8, u16, u32], but was {:?}", value);
panic!("beserial(len_type) must be one of [u8, u16, u32], but was {value:?}");
}
len_type =
Some(value.get_ident().cloned().unwrap());
}
Meta::NameValue(name_value) => {
if !cmp_ident(&name_value.path, "limit") {
panic!("beserial(len_type) can only have an additional limit attribute, but was {:?}", name_value);
panic!("beserial(len_type) can only have an additional limit attribute, but was {name_value:?}");
}
// We do have something like beserial(discriminant = 123).
// Parse discriminant.
Expand Down Expand Up @@ -177,7 +177,7 @@ fn parse_field_attribs(attrs: &[syn::Attribute]) -> Option<FieldAttribute> {
} else if cmp_ident(path, "uvar") {
return Some(FieldAttribute::Uvar);
} else {
panic!("unknown flag for beserial: {:?}", path)
panic!("unknown flag for beserial: {path:?}")
}
}
Meta::NameValue(ref name_value) => {
Expand All @@ -196,7 +196,7 @@ fn parse_field_attribs(attrs: &[syn::Attribute]) -> Option<FieldAttribute> {
panic!("non-integer discriminant");
}
} else {
panic!("unknown flag for beserial: {:?}", name_value)
panic!("unknown flag for beserial: {name_value:?}")
}
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ fn parse_enum_attribs(ast: &syn::DeriveInput) -> (Option<syn::Ident>, bool) {
if cmp_ident(attr_ident, "uvar") {
uvar = true;
} else {
panic!("unknown flag for beserial: {:?}", attr_ident)
panic!("unknown flag for beserial: {attr_ident:?}")
}
}
}
Expand Down Expand Up @@ -345,8 +345,7 @@ fn impl_serialize(ast: &syn::DeriveInput) -> TokenStream {
} else {
enum_type.unwrap_or_else(|| {
panic!(
"Serialize can not be derived for enum {} without repr(u*) or repr(i*)",
name
"Serialize can not be derived for enum {name} without repr(u*) or repr(i*)"
)
})
};
Expand Down Expand Up @@ -423,7 +422,7 @@ fn impl_serialize(ast: &syn::DeriveInput) -> TokenStream {
let mut serialized_size_body_fields = Vec::<TokenStream>::new();

for (i, field) in fields.unnamed.iter().enumerate() {
let ident = syn::Ident::new(&format!("f{}", i), Span::call_site());
let ident = syn::Ident::new(&format!("f{i}"), Span::call_site());
if let Some((serialize, serialized_size)) =
impl_serialize_field(field, 0, Some(&ident))
{
Expand Down Expand Up @@ -473,7 +472,7 @@ fn impl_serialize(ast: &syn::DeriveInput) -> TokenStream {
}
}
}
Data::Union(_) => panic!("Serialize can not be derived for Union {}", name),
Data::Union(_) => panic!("Serialize can not be derived for Union {name}"),
};

let gen = quote! {
Expand Down Expand Up @@ -571,8 +570,7 @@ fn impl_deserialize(ast: &syn::DeriveInput) -> TokenStream {
} else {
enum_type.unwrap_or_else(|| {
panic!(
"Deserialize can not be derived for enum {} without repr(u*) or repr(i*)",
name
"Deserialize can not be derived for enum {name} without repr(u*) or repr(i*)"
)
})
};
Expand Down Expand Up @@ -703,7 +701,7 @@ fn impl_deserialize(ast: &syn::DeriveInput) -> TokenStream {
});
}
}
Data::Union(_) => panic!("Deserialize can not be derived for Union {}", name),
Data::Union(_) => panic!("Deserialize can not be derived for Union {name}"),
};

let gen = quote! {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/src/blockchain/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Blockchain {
let batch_info = match batch_info {
Ok(batch_info) => batch_info,
Err(e) => {
panic!("Failed to revert - {:?}", e);
panic!("Failed to revert - {e:?}");
}
};

Expand Down
2 changes: 1 addition & 1 deletion bls/examples/gen_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fn main() {

let sig = keypair.sign(&message);

println!("Signature:\n {}", sig);
println!("Signature:\n {sig}");
}
17 changes: 1 addition & 16 deletions bls/src/rand_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,7 @@ pub fn generate_random_seed() -> Vec<u8> {
let block_14 = "000000000000000000132006558a816203cb442aeb9162ba1d8f6dac5f0a00ec";

let concatenated = format!(
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
block_00,
block_01,
block_02,
block_03,
block_04,
block_05,
block_06,
block_07,
block_08,
block_09,
block_10,
block_11,
block_12,
block_13,
block_14
"{block_00}{block_01}{block_02}{block_03}{block_04}{block_05}{block_06}{block_07}{block_08}{block_09}{block_10}{block_11}{block_12}{block_13}{block_14}"
);

let random_bytes = hex::decode(concatenated).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions collections/src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ impl fmt::Display for BitSet {
let consecutive_last = last_value.map(|lv| lv + 1 == value).unwrap_or(false);
let consecutive_next = value + 1 == *next_value;
if !(consecutive_last && consecutive_next) {
write!(f, "{}", value)?;
write!(f, "{value}")?;
if consecutive_next {
write!(f, "-")?;
} else {
write!(f, ", ")?;
}
}
} else {
write!(f, "{}", value)?;
write!(f, "{value}")?;
}
last_value = Some(value);
}
Expand Down
20 changes: 10 additions & 10 deletions consensus/src/sync/history/sync_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain.read().block_number(), 0);
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand Down Expand Up @@ -389,7 +389,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand Down Expand Up @@ -429,7 +429,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand Down Expand Up @@ -459,7 +459,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand Down Expand Up @@ -515,7 +515,7 @@ mod tests {
);

let num_blocks = Policy::blocks_per_batch() + Policy::blocks_per_batch() / 2;
copy_chain_with_limit(&*chain2, &*chain1, num_blocks as usize);
copy_chain_with_limit(&chain2, &chain1, num_blocks as usize);
assert_eq!(chain1.read().block_number(), num_blocks);

let mut sync = HistoryMacroSync::<MockNetwork>::new(
Expand Down Expand Up @@ -552,11 +552,11 @@ mod tests {
produce_macro_blocks_with_txns(&producer, &chain2, 1, 1, 0);
assert_eq!(chain2.read().block_number(), Policy::blocks_per_batch());

copy_chain(&*chain2, &*chain3);
copy_chain(&chain2, &chain3);
produce_macro_blocks_with_txns(&producer, &chain3, 1, 1, 0);
assert_eq!(chain3.read().block_number(), 2 * Policy::blocks_per_batch());

copy_chain(&*chain3, &*chain4);
copy_chain(&chain3, &chain4);
produce_macro_blocks_with_txns(&producer, &chain4, 1, 1, 0);
assert_eq!(chain4.read().block_number(), 3 * Policy::blocks_per_batch());

Expand All @@ -576,15 +576,15 @@ mod tests {

match sync.next().await {
Some(MacroSyncReturn::Good(peer_id)) if peer_id == net4.peer_id() => {}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
match sync.next().await {
Some(MacroSyncReturn::Outdated(peer_id)) if peer_id == net3.peer_id() => {}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
match sync.next().await {
Some(MacroSyncReturn::Outdated(peer_id)) if peer_id == net2.peer_id() => {}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}

assert_eq!(chain1.read().head(), chain4.read().head());
Expand Down
24 changes: 12 additions & 12 deletions consensus/src/sync/light/sync_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ mod tests {
// Verify the peer was removed
assert_eq!(sync.peer_requests.len(), 0);
}
res => panic!("Unexpected MacroSyncReturn: {:?}", res),
res => panic!("Unexpected MacroSyncReturn: {res:?}"),
}
}

Expand Down Expand Up @@ -495,7 +495,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand All @@ -519,7 +519,7 @@ mod tests {
if let BlockchainProxy::Full(ref chain2) = chain2 {
produce_macro_blocks_with_txns(
&producer,
&chain2,
chain2,
Policy::batches_per_epoch() as usize,
1,
0,
Expand Down Expand Up @@ -567,7 +567,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand All @@ -588,7 +588,7 @@ mod tests {
if let BlockchainProxy::Full(ref chain2) = chain2 {
produce_macro_blocks_with_txns(
&producer,
&chain2,
chain2,
(Policy::batches_per_epoch() + 1) as usize,
1,
0,
Expand Down Expand Up @@ -639,7 +639,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand All @@ -659,7 +659,7 @@ mod tests {
let num_batches = (Policy::batches_per_epoch() - 1) as usize;
let producer = BlockProducer::new(signing_key(), voting_key());
if let BlockchainProxy::Full(ref chain2) = chain2 {
produce_macro_blocks_with_txns(&producer, &chain2, num_batches, 1, 0);
produce_macro_blocks_with_txns(&producer, chain2, num_batches, 1, 0);
}
assert_eq!(
chain2.read().block_number(),
Expand Down Expand Up @@ -706,7 +706,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}
}

Expand All @@ -728,7 +728,7 @@ mod tests {
if let BlockchainProxy::Full(ref chain2) = chain2 {
produce_macro_blocks_with_txns(
&producer,
&chain2,
chain2,
Policy::batches_per_epoch() as usize * (num_extra_epochs + 2) as usize,
1,
0,
Expand All @@ -741,7 +741,7 @@ mod tests {
if let BlockchainProxy::Full(ref chain1) = chain1 {
let block_to_delete = chain2
.read()
.get_block_at(Policy::blocks_per_epoch() as u32, true)
.get_block_at(Policy::blocks_per_epoch(), true)
.unwrap();

assert_eq!(
Expand All @@ -753,7 +753,7 @@ mod tests {
chain1.upgradable_read(),
chain2
.read()
.get_block_at(Policy::blocks_per_epoch() as u32 * 2, true)
.get_block_at(Policy::blocks_per_epoch() * 2, true)
.unwrap(),
),
Ok(PushResult::Extended),
Expand Down Expand Up @@ -810,7 +810,7 @@ mod tests {
Some(MacroSyncReturn::Good(_)) => {
assert_eq!(chain1.read().head(), chain2.read().head());
}
res => panic!("Unexpected HistorySyncReturn: {:?}", res),
res => panic!("Unexpected HistorySyncReturn: {res:?}"),
}

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/sync/live/state_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub enum ResponseChunk {
impl Display for ResponseChunk {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ResponseChunk::Chunk(chunk) => write!(f, "ResponseChunk::Chunk({})", chunk),
ResponseChunk::Chunk(chunk) => write!(f, "ResponseChunk::Chunk({chunk})"),
ResponseChunk::IncompleteState => {
write!(f, "ResponseChunk::IncompleteState")
}
Expand Down
2 changes: 1 addition & 1 deletion database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Error::*;
match self {
CreateDirectory(e) => write!(f, "couldn't create directory for DB: {}", e),
CreateDirectory(e) => write!(f, "couldn't create directory for DB: {e}"),
Mdbx(e) => e.fmt(f),
}
}
Expand Down
7 changes: 3 additions & 4 deletions genesis-builder/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
D: Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
Address::from_user_friendly_address(&s).map_err(|e| Error::custom(format!("{:?}", e)))
Address::from_user_friendly_address(&s).map_err(|e| Error::custom(format!("{e:?}")))
}

#[allow(dead_code)]
Expand All @@ -83,8 +83,7 @@ where
let opt: Option<String> = Deserialize::deserialize(deserializer)?;
if let Some(s) = opt {
Ok(Some(
Address::from_user_friendly_address(&s)
.map_err(|e| Error::custom(format!("{:?}", e)))?,
Address::from_user_friendly_address(&s).map_err(|e| Error::custom(format!("{e:?}")))?,
))
} else {
Ok(None)
Expand Down Expand Up @@ -127,7 +126,7 @@ where
if let Some(s) = opt {
Ok(Some(
OffsetDateTime::parse(&s, &time::format_description::well_known::Rfc3339)
.map_err(|e| Error::custom(format!("{:?}", e)))?,
.map_err(|e| Error::custom(format!("{e:?}")))?,
))
} else {
Ok(None)
Expand Down
6 changes: 3 additions & 3 deletions genesis-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ fn main() {
.generate(env)
.unwrap();

println!("Genesis Block: {}", hash);
println!("{:#?}", block);
println!("Genesis Block: {hash}");
println!("{block:#?}");
println!();
println!("Genesis Accounts:");
println!("{:#?}", accounts);
println!("{accounts:#?}");
} else {
usage(args);
}
Expand Down
Loading

0 comments on commit 9b79486

Please sign in to comment.